Skip to content

Commit 4b6ba92

Browse files
committed
Test for control bindings conditionally
1 parent e281613 commit 4b6ba92

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

test/test.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import Combobox from '../dist/index.js'
2+
3+
const ctrlBindings = !!navigator.userAgent.match(/Macintosh/)
4+
25
function press(input, key, ctrlKey) {
36
input.dispatchEvent(new KeyboardEvent('keydown', {key, ctrlKey}))
47
}
@@ -105,17 +108,17 @@ describe('combobox-nav', function() {
105108

106109
press(input, 'Enter')
107110

108-
press(input, 'ArrowDown')
111+
ctrlBindings ? press(input, 'n', true) : press(input, 'ArrowDown')
109112
assert.equal(options[2].getAttribute('aria-selected'), 'true')
110113
assert.equal(input.getAttribute('aria-activedescendant'), 'r2-d2')
111114

112-
press(input, 'ArrowDown')
115+
ctrlBindings ? press(input, 'n', true) : press(input, 'ArrowDown')
113116
assert.equal(options[4].getAttribute('aria-selected'), 'true')
114117
assert.equal(input.getAttribute('aria-activedescendant'), 'wall-e')
115118
press(input, 'Enter')
116119
click(document.getElementById('wall-e'))
117120

118-
press(input, 'ArrowDown')
121+
ctrlBindings ? press(input, 'n', true) : press(input, 'ArrowDown')
119122
assert.equal(options[5].getAttribute('aria-selected'), 'true')
120123
assert.equal(input.getAttribute('aria-activedescendant'), 'link')
121124

@@ -127,19 +130,18 @@ describe('combobox-nav', function() {
127130
assert.equal(options[0].getAttribute('aria-selected'), 'true')
128131
assert.equal(input.getAttribute('aria-activedescendant'), 'baymax')
129132

130-
press(input, 'ArrowUp')
133+
ctrlBindings ? press(input, 'p', true) : press(input, 'ArrowUp')
131134
assert(!list.querySelector('[aria-selected=true]'), 'Nothing should be selected')
132135
assert(!input.hasAttribute('aria-activedescendant'), 'Nothing should be selected')
133136

134-
press(input, 'ArrowDown')
135-
press(input, 'ArrowDown')
136-
assert.equal(options[1].getAttribute('aria-selected'), 'true')
137-
assert.equal(input.getAttribute('aria-activedescendant'), 'hubot')
137+
press(input, 'ArrowUp')
138+
assert.equal(options[5].getAttribute('aria-selected'), 'true')
139+
assert.equal(input.getAttribute('aria-activedescendant'), 'link')
138140

139141
press(input, 'Enter')
140142
assert.equal(expectedTargets.length, 2)
141143
assert.equal(expectedTargets[0], 'hubot')
142-
assert.equal(expectedTargets[1], 'hubot')
144+
assert.equal(expectedTargets[1], 'link')
143145
})
144146

145147
it('fires commit events on click', function() {
@@ -171,9 +173,11 @@ describe('combobox-nav', function() {
171173
assert.equal(options[0].getAttribute('aria-selected'), 'true')
172174
assert.equal(input.getAttribute('aria-activedescendant'), 'baymax')
173175

174-
press(input, 'Control', true)
175-
assert.equal(options[0].getAttribute('aria-selected'), 'true', 'Selection stays on modifier keydown')
176-
assert.equal(input.getAttribute('aria-activedescendant'), 'baymax', 'Selection stays on modifier keydown')
176+
if (ctrlBindings) {
177+
press(input, 'Control', true)
178+
assert.equal(options[0].getAttribute('aria-selected'), 'true', 'Selection stays on modifier keydown')
179+
assert.equal(input.getAttribute('aria-activedescendant'), 'baymax', 'Selection stays on modifier keydown')
180+
}
177181

178182
press(input, 'Backspace')
179183
assert(!list.querySelector('[aria-selected=true]'), 'Nothing should be selected')

0 commit comments

Comments
 (0)