|
1 | 1 | const React = require('react/addons'); |
2 | 2 | const TestUtils = React.addons.TestUtils; |
3 | 3 | import {SLDSLookup} from '../../components'; |
4 | | -import ActionItem from '../../components/SLDSLookup/Menu/ActionItem'; |
5 | 4 |
|
6 | 5 | describe('SLDSLookup: ', function(){ |
7 | 6 |
|
@@ -89,17 +88,44 @@ describe('SLDSLookup: ', function(){ |
89 | 88 | }); |
90 | 89 |
|
91 | 90 | 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'); |
92 | 100 | }); |
93 | 101 |
|
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'); |
95 | 110 | }); |
96 | 111 |
|
97 | 112 | 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'); |
98 | 119 | }); |
99 | 120 |
|
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'); |
101 | 128 | }); |
102 | | - |
103 | 129 | }); |
104 | 130 |
|
105 | 131 | }); |
0 commit comments