Skip to content

Commit 02420cb

Browse files
committed
Add more lookup tests
1 parent d834a3a commit 02420cb

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

tests/SLDSLookup/lookup.test.jsx

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const React = require('react/addons');
22
const TestUtils = React.addons.TestUtils;
33
import {SLDSLookup} from '../../components';
4-
import ActionItem from '../../components/SLDSLookup/Menu/ActionItem';
54

65
describe('SLDSLookup: ', function(){
76

@@ -89,17 +88,44 @@ describe('SLDSLookup: ', function(){
8988
});
9089

9190
it('selects correct item', function() {
91+
let lookup = generateLookup(<SLDSLookup items={items} label="Leads" type="lead" />);
92+
let input = lookup.getElementsByTagName("input")[0];
93+
TestUtils.Simulate.click(input);
94+
TestUtils.Simulate.keyDown(input, {key: "Down", keyCode: 40, which: 40});
95+
TestUtils.Simulate.keyDown(input, {key: "Down", keyCode: 40, which: 40});
96+
TestUtils.Simulate.keyDown(input, {key: "Down", keyCode: 40, which: 40});
97+
TestUtils.Simulate.keyDown(input, {key: "Enter", keyCode: 13, which: 13});
98+
let selected = lookup.getElementsByTagName("span")[0].getElementsByTagName('span')[0].innerText;
99+
expect(selected).to.equal('Paper St. Soap Company');
92100
});
93101

94-
it('closes lookup menu', function() {
102+
it('closes lookup menu on esc', function() {
103+
let lookup = generateLookup(<SLDSLookup items={items} label="Leads" type="lead" />);
104+
let input = lookup.getElementsByTagName("input")[0];
105+
TestUtils.Simulate.click(input);
106+
TestUtils.Simulate.keyDown(input, {key: "Down", keyCode: 40, which: 40});
107+
TestUtils.Simulate.keyDown(input, {key: "Esc", keyCode: 27, which: 27});
108+
let ariaExpanded = input.getAttribute("aria-expanded");
109+
expect(ariaExpanded).to.equal('false');
95110
});
96111

97112
it('aria-expanded is false after selecting item', function() {
113+
let lookup = generateLookup(<SLDSLookup items={items} label="Leads" type="lead" />);
114+
let input = lookup.getElementsByTagName("input")[0];
115+
TestUtils.Simulate.click(input);
116+
TestUtils.Simulate.keyDown(input, {key: "Down", keyCode: 40, which: 40});
117+
TestUtils.Simulate.keyDown(input, {key: "Enter", keyCode: 13, which: 13});
118+
expect(input.className).to.have.string('slds-hide');
98119
});
99120

100-
it('focuses on selected item', function() {
121+
it('aria-expanded is false after selecting item', function() {
122+
let lookup = generateLookup(<SLDSLookup items={items} label="Leads" type="lead" />);
123+
let input = lookup.getElementsByTagName("input")[0];
124+
TestUtils.Simulate.click(input);
125+
TestUtils.Simulate.keyDown(input, {key: "Down", keyCode: 40, which: 40});
126+
let focusedItem = lookup.getElementsByTagName("ul")[0].getElementsByTagName('li')[0];
127+
expect(focusedItem.className).to.have.string('slds-theme--shade');
101128
});
102-
103129
});
104130

105131
});

0 commit comments

Comments
 (0)