-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for autoclosable/autotogglable behaviors
- Loading branch information
Shuwen Qian
committed
Sep 16, 2015
1 parent
32dc46f
commit e7bc9bd
Showing
2 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<script src="../bower_components/webcomponentsjs/webcomponents.js"></script> | ||
<script src="../bower_components/web-component-tester/browser.js"></script> | ||
<script src="TestHelper.js"></script> | ||
<script> | ||
var should = chai.should(); | ||
</script> | ||
<link rel="import" href="../build/shared/behaviors/autoclosable.html"/> | ||
<link rel="import" href="../bower_components/polymer/polymer.html"/> | ||
</head> | ||
<body> | ||
|
||
<dom-module id="test-autoclosable"> | ||
<template> | ||
<content></content> | ||
</template> | ||
</dom-module> | ||
|
||
<script> | ||
HTMLImports.whenReady(function() { | ||
window.TestAutoClosable = Polymer({ | ||
is: 'test-autoclosable', | ||
behaviors: [StrandTraits.AutoClosable] | ||
}); | ||
}); | ||
</script> | ||
|
||
<test-autoclosable id="testAutoClosable"></test-autoclosable> | ||
|
||
<script> | ||
describe('AutoClosable', function() { | ||
|
||
it('should not close on mouseup inside element', function() { | ||
var testAutoClosable = document.querySelector('#testAutoClosable'); | ||
testAutoClosable.open(); | ||
testAutoClosable.fire('mouseup'); | ||
testAutoClosable.state.should.equal(testAutoClosable.STATE_OPENED); | ||
}); | ||
|
||
it('should close on mouseup outside element', function() { | ||
var testAutoClosable = document.querySelector('#testAutoClosable'); | ||
testAutoClosable.open(); | ||
testAutoClosable.fire('mouseup', null, {node: document}); | ||
testAutoClosable.state.should.equal(testAutoClosable.STATE_CLOSED); | ||
}); | ||
|
||
}); | ||
</script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<script src="../bower_components/webcomponentsjs/webcomponents.js"></script> | ||
<script src="../bower_components/web-component-tester/browser.js"></script> | ||
<script src="TestHelper.js"></script> | ||
<script> | ||
var should = chai.should(); | ||
</script> | ||
<link rel="import" href="../build/shared/behaviors/autotogglable.html"/> | ||
<link rel="import" href="../bower_components/polymer/polymer.html"/> | ||
</head> | ||
<body> | ||
|
||
<dom-module id="test-autotogglable"> | ||
<template> | ||
<content></content> | ||
</template> | ||
</dom-module> | ||
|
||
<script> | ||
HTMLImports.whenReady(function() { | ||
window.TestAutoTogglable = Polymer({ | ||
is: 'test-autotogglable', | ||
behaviors: [StrandTraits.AutoTogglable] | ||
}); | ||
}); | ||
</script> | ||
|
||
<a id="testTrigger">Foo</a> | ||
<test-autotogglable id="testAutoTogglable"></test-autotogglable> | ||
|
||
<script> | ||
describe('AutoTogglable', function() { | ||
|
||
it('should get a toggleTrigger from a selector', function() { | ||
var toggle = document.querySelector('#testAutoTogglable'), | ||
trigger = document.querySelector('#testTrigger'); | ||
|
||
toggle.toggleTrigger = '#testTrigger'; | ||
toggle.toggleTrigger.should.equal(trigger); | ||
}); | ||
|
||
it('should toggle when the trigger is clicked', function() { | ||
var toggle = document.querySelector('#testAutoTogglable'), | ||
trigger = document.querySelector('#testTrigger'); | ||
|
||
toggle.state.should.equal(toggle.STATE_CLOSED); | ||
toggle.fire('click', null, {node: trigger}); | ||
toggle.state.should.equal(toggle.STATE_OPENED); | ||
toggle.fire('click', null, {node: trigger}); | ||
toggle.state.should.equal(toggle.STATE_CLOSED); | ||
}); | ||
|
||
}); | ||
</script> | ||
|
||
</body> | ||
</html> |