mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Add new tests for dropdown component
This commit is contained in:
parent
ccf3e0e251
commit
2adfce772c
@ -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;
|
const DropdownMenuItem = require(path.join(__dirname, '..', '..', '..', '..', 'ui', 'responsive', 'app', 'components', 'dropdown.js')).DropdownMenuItem;
|
||||||
|
|
||||||
describe('Dropdown components', function () {
|
describe('Dropdown components', function () {
|
||||||
it('can render two items', function () {
|
let onClickOutside;
|
||||||
const renderer = ReactTestUtils.createRenderer()
|
let closeMenu;
|
||||||
|
let onClick;
|
||||||
|
|
||||||
const onClickOutside = sinon.spy();
|
let dropdownComponentProps;
|
||||||
const closeMenu = sinon.spy();
|
const renderer = ReactTestUtils.createRenderer()
|
||||||
const onClick = sinon.spy();
|
beforeEach(function () {
|
||||||
|
onClickOutside = sinon.spy();
|
||||||
|
closeMenu = sinon.spy();
|
||||||
|
onClick = sinon.spy();
|
||||||
|
|
||||||
const dropdownComponent = h(Dropdown, {
|
dropdownComponentProps = {
|
||||||
isOpen: true,
|
isOpen: true,
|
||||||
zIndex: 11,
|
zIndex: 11,
|
||||||
onClickOutside,
|
onClickOutside,
|
||||||
@ -26,26 +30,86 @@ describe('Dropdown components', function () {
|
|||||||
top: '36px',
|
top: '36px',
|
||||||
},
|
},
|
||||||
innerStyle: {},
|
innerStyle: {},
|
||||||
}, [ // DROP MENU ITEMS
|
}
|
||||||
h('style', `
|
});
|
||||||
.drop-menu-item:hover { background:rgb(235, 235, 235); }
|
|
||||||
.drop-menu-item i { margin: 11px; }
|
|
||||||
`),
|
|
||||||
|
|
||||||
h(DropdownMenuItem, {
|
it('can render two items', function () {
|
||||||
closeMenu,
|
const dropdownComponent = h(
|
||||||
onClick,
|
Dropdown,
|
||||||
}, 'Item 1'),
|
dropdownComponentProps,
|
||||||
|
[
|
||||||
h(DropdownMenuItem, {
|
h('style', `
|
||||||
closeMenu,
|
.drop-menu-item:hover { background:rgb(235, 235, 235); }
|
||||||
onClick,
|
.drop-menu-item i { margin: 11px; }
|
||||||
}, 'Item 2'),
|
`),
|
||||||
])
|
h(DropdownMenuItem, {
|
||||||
|
closeMenu,
|
||||||
|
onClick,
|
||||||
|
}, 'Item 1'),
|
||||||
|
h(DropdownMenuItem, {
|
||||||
|
closeMenu,
|
||||||
|
onClick,
|
||||||
|
}, 'Item 2'),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
const component = additions.renderIntoDocument(dropdownComponent);
|
const component = additions.renderIntoDocument(dropdownComponent);
|
||||||
renderer.render(dropdownComponent);
|
renderer.render(dropdownComponent);
|
||||||
const items = additions.find(component, 'li');
|
const items = additions.find(component, 'li');
|
||||||
assert.equal(items.length, 2);
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
Loading…
Reference in New Issue
Block a user