|
1 | 1 | describe('src/cy/commands/actions/press', () => {
|
2 |
| - it('dispatches the tab keypress to the AUT', () => { |
3 |
| - // Non-BiDi firefox is not supported |
4 |
| - if (Cypress.browser.family === 'firefox' && Cypress.browserMajorVersion() < 135) { |
5 |
| - return |
6 |
| - } |
7 |
| - |
8 |
| - // TODO: Webkit is not supported. https://github.com/cypress-io/cypress/issues/31054 |
9 |
| - if (Cypress.isBrowser('webkit')) { |
10 |
| - return |
11 |
| - } |
| 2 | + // TODO: Webkit is not supported. https://github.com/cypress-io/cypress/issues/31054 |
| 3 | + if (Cypress.isBrowser('webkit')) { |
| 4 | + return |
| 5 | + } |
12 | 6 |
|
| 7 | + beforeEach(() => { |
13 | 8 | cy.visit('/fixtures/input_events.html')
|
| 9 | + }) |
14 | 10 |
|
15 |
| - cy.press(Cypress.Keyboard.Keys.TAB) |
16 |
| - |
17 |
| - cy.get('#keydown').should('have.value', 'Tab') |
| 11 | + it('fires the click event on the button when the named key is sent', () => { |
| 12 | + cy.get('#button').focus() |
| 13 | + cy.get('#button').should('be.focused') |
| 14 | + cy.press(Cypress.Keyboard.Keys.SPACE) |
| 15 | + cy.get('#checkbox').should('be.checked') |
| 16 | + }) |
18 | 17 |
|
19 |
| - cy.get('#keyup').should('have.value', 'Tab') |
| 18 | + it('fires the click event on the button when a space is sent', () => { |
| 19 | + cy.get('#button').focus() |
| 20 | + cy.get('#button').should('be.focused') |
| 21 | + cy.press(' ') |
| 22 | + cy.get('#checkbox').should('be.checked') |
20 | 23 | })
|
| 24 | + |
| 25 | + const testKeyDownUp = (key) => { |
| 26 | + it(`dispatches ${key} keypress to the AUT`, () => { |
| 27 | + cy.press(key) |
| 28 | + // spacebar is a special case - it's both a named key and a single character, |
| 29 | + // but when we dispatch the named key (via codepoint in bidi, via `Space` in CDP) |
| 30 | + // we get the space character, not the name of the key. |
| 31 | + cy.get('#keydown').should('have.value', key === 'Space' ? ' ' : key) |
| 32 | + }) |
| 33 | + } |
| 34 | + |
| 35 | + Object.values(Cypress.Keyboard.Keys).forEach(testKeyDownUp) |
| 36 | + |
| 37 | + // sets truncated for speed |
| 38 | + |
| 39 | + // // Numbers |
| 40 | + ;['0', '1'].forEach(testKeyDownUp) |
| 41 | + |
| 42 | + ;[0, 1].forEach(testKeyDownUp) |
| 43 | + |
| 44 | + // // Letters |
| 45 | + ;['a', 'z'].forEach(testKeyDownUp) |
| 46 | + |
| 47 | + // // Special characters |
| 48 | + ;['!', ' ', '€', 'é'].forEach(testKeyDownUp) |
21 | 49 | })
|
0 commit comments