aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorsdtsui <szehungdanieltsui@gmail.com>2017-07-18 20:23:25 +0800
committersdtsui <szehungdanieltsui@gmail.com>2017-07-18 20:31:52 +0800
commit2adfce772c91e28cb25145ad0beda40bd5aed7d4 (patch)
tree639ce582843ceca819e3fb29e2b74bebc521e633 /test
parentccf3e0e2512c05c024ec5f2e70e2d682a4968041 (diff)
downloadtangerine-wallet-browser-2adfce772c91e28cb25145ad0beda40bd5aed7d4.tar
tangerine-wallet-browser-2adfce772c91e28cb25145ad0beda40bd5aed7d4.tar.gz
tangerine-wallet-browser-2adfce772c91e28cb25145ad0beda40bd5aed7d4.tar.bz2
tangerine-wallet-browser-2adfce772c91e28cb25145ad0beda40bd5aed7d4.tar.lz
tangerine-wallet-browser-2adfce772c91e28cb25145ad0beda40bd5aed7d4.tar.xz
tangerine-wallet-browser-2adfce772c91e28cb25145ad0beda40bd5aed7d4.tar.zst
tangerine-wallet-browser-2adfce772c91e28cb25145ad0beda40bd5aed7d4.zip
Add new tests for dropdown component
Diffstat (limited to 'test')
-rw-r--r--test/unit/responsive/components/dropdown-test.js108
1 files changed, 86 insertions, 22 deletions
diff --git a/test/unit/responsive/components/dropdown-test.js b/test/unit/responsive/components/dropdown-test.js
index feadc792e..4d417d394 100644
--- a/test/unit/responsive/components/dropdown-test.js
+++ b/test/unit/responsive/components/dropdown-test.js
@@ -9,14 +9,18 @@ const Dropdown = require(path.join(__dirname, '..', '..', '..', '..', 'ui', 'res
const DropdownMenuItem = require(path.join(__dirname, '..', '..', '..', '..', 'ui', 'responsive', 'app', 'components', 'dropdown.js')).DropdownMenuItem;
describe('Dropdown components', function () {
- it('can render two items', function () {
- const renderer = ReactTestUtils.createRenderer()
+ let onClickOutside;
+ let closeMenu;
+ let onClick;
- const onClickOutside = sinon.spy();
- const closeMenu = sinon.spy();
- const onClick = sinon.spy();
+ let dropdownComponentProps;
+ const renderer = ReactTestUtils.createRenderer()
+ beforeEach(function () {
+ onClickOutside = sinon.spy();
+ closeMenu = sinon.spy();
+ onClick = sinon.spy();
- const dropdownComponent = h(Dropdown, {
+ dropdownComponentProps = {
isOpen: true,
zIndex: 11,
onClickOutside,
@@ -26,26 +30,86 @@ describe('Dropdown components', function () {
top: '36px',
},
innerStyle: {},
- }, [ // DROP MENU ITEMS
- h('style', `
- .drop-menu-item:hover { background:rgb(235, 235, 235); }
- .drop-menu-item i { margin: 11px; }
- `),
-
- h(DropdownMenuItem, {
- closeMenu,
- onClick,
- }, 'Item 1'),
-
- h(DropdownMenuItem, {
- closeMenu,
- onClick,
- }, 'Item 2'),
- ])
+ }
+ });
+
+ it('can render two items', function () {
+ const dropdownComponent = h(
+ Dropdown,
+ dropdownComponentProps,
+ [
+ h('style', `
+ .drop-menu-item:hover { background:rgb(235, 235, 235); }
+ .drop-menu-item i { margin: 11px; }
+ `),
+ h(DropdownMenuItem, {
+ closeMenu,
+ onClick,
+ }, 'Item 1'),
+ h(DropdownMenuItem, {
+ closeMenu,
+ onClick,
+ }, 'Item 2'),
+ ]
+ )
const component = additions.renderIntoDocument(dropdownComponent);
renderer.render(dropdownComponent);
const items = additions.find(component, 'li');
assert.equal(items.length, 2);
});
+
+ it('closes when item clicked', function() {
+ const dropdownComponent = h(
+ Dropdown,
+ dropdownComponentProps,
+ [
+ h('style', `
+ .drop-menu-item:hover { background:rgb(235, 235, 235); }
+ .drop-menu-item i { margin: 11px; }
+ `),
+ h(DropdownMenuItem, {
+ closeMenu,
+ onClick,
+ }, 'Item 1'),
+ h(DropdownMenuItem, {
+ closeMenu,
+ onClick,
+ }, 'Item 2'),
+ ]
+ )
+ const component = additions.renderIntoDocument(dropdownComponent);
+ renderer.render(dropdownComponent);
+ const items = additions.find(component, 'li');
+ const node = items[0];
+ ReactTestUtils.Simulate.click(node);
+ assert.equal(closeMenu.calledOnce, true);
+ });
+
+ it('invokes click handler when item clicked', function() {
+ const dropdownComponent = h(
+ Dropdown,
+ dropdownComponentProps,
+ [
+ h('style', `
+ .drop-menu-item:hover { background:rgb(235, 235, 235); }
+ .drop-menu-item i { margin: 11px; }
+ `),
+ h(DropdownMenuItem, {
+ closeMenu,
+ onClick,
+ }, 'Item 1'),
+ h(DropdownMenuItem, {
+ closeMenu,
+ onClick,
+ }, 'Item 2'),
+ ]
+ )
+ const component = additions.renderIntoDocument(dropdownComponent);
+ renderer.render(dropdownComponent);
+ const items = additions.find(component, 'li');
+ const node = items[0];
+ ReactTestUtils.Simulate.click(node);
+ assert.equal(onClick.calledOnce, true);
+ });
}); \ No newline at end of file