Skip to content

Commit

Permalink
Added tests for autoclosable/autotogglable behaviors
Browse files Browse the repository at this point in the history
  • Loading branch information
Shuwen Qian committed Sep 16, 2015
1 parent 32dc46f commit e7bc9bd
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
54 changes: 54 additions & 0 deletions test/behavior_autoclosable.html
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>
60 changes: 60 additions & 0 deletions test/behavior_autotogglable.html
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>

0 comments on commit e7bc9bd

Please sign in to comment.