Skip to content

Commit

Permalink
fix: "type" action with {upArrow} and {downArrow} arguments to simula… (
Browse files Browse the repository at this point in the history
#29636)

* fix: "type" action with {upArrow} and {downArrow} arguments to simulate native behavior of input[type=number]

* Add changelog entry for the fix

---------

Co-authored-by: Jennifer Shehane <[email protected]>
  • Loading branch information
thevladisss and jennifer-shehane authored Jun 18, 2024
1 parent 7827656 commit 9c9bf5b
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ _Released 6/18/2024 (PENDING)_

**Bugfixes:**

- We now trigger `input` and `change` events when typing `{upArrow}` and `{downArrow}` via `.type()` on `input[type=number]` elements. Fixes [#29611](https://github.com/cypress-io/cypress/issues/29611)
- Fixed an issue where auto scrolling the reporter would sometimes be disabled without the user's intent. Fixes [#25084](https://github.com/cypress-io/cypress/issues/25084).
- Fixed an issue where `inlineSourceMaps` was still being used when `sourceMaps` was provided in a users typescript config for typescript version 5. Fixes [#26203](https://github.com/cypress-io/cypress/issues/26203).
- When capture protocol script fails verification, an appropriate error is now displayed. Previously, an error regarding Test Replay archive location was shown. Addressed in [#29603](https://github.com/cypress-io/cypress/pull/29603).
Expand Down
48 changes: 48 additions & 0 deletions packages/driver/cypress/e2e/commands/actions/type.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -1305,6 +1305,54 @@ describe('src/cy/commands/actions/type - #type', () => {
.type('100{enter}')
.should('have.value', '100')
})

context('can utilize up and down arrow keys', () => {
beforeEach(() => {
cy.get('#number-with-value').then(($input) => $input.val(1))
})

it('can utilize {upArrow}', () => {
cy.get('#number-with-value')
.type('{upArrow}')
.should('have.value', 2)
})

it('{upArrow} triggers events on input', () => {
cy.get('#number-with-value')
.then(($input) => {
$input.on('change', cy.spy().as('spyChange'))
$input.on('input', cy.spy().as('spyInput'))

return $input
})
.type('{upArrow}')

cy.get('@spyInput').should('have.been.calledOnce')
cy.get('@spyChange').should('have.been.calledOnce')
})

it('can utilize {downArrow}', () => {
cy.get('#number-with-value').then(($input) => $input.val(1))

cy.get('#number-with-value')
.type('{downArrow}')
.should('have.value', 0)
})

it('{downArrow} triggers events on input', () => {
cy.get('#number-with-value')
.then(($input) => {
$input.on('change', cy.spy().as('spyChange'))
$input.on('input', cy.spy().as('spyInput'))

return $input
})
.type('{downArrow}')

cy.get('@spyChange').should('have.been.calledOnce')
cy.get('@spyInput').should('have.been.calledOnce')
})
})
})

describe('input[type=email]', () => {
Expand Down
11 changes: 11 additions & 0 deletions packages/driver/src/dom/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,22 @@ const _moveCursorUpOrDown = function (up: boolean, el: HTMLElement) {
if ($elements.isInputType(el, 'number')) {
if (up) {
if (typeof el.stepUp === 'function') {
const changeEvent = new Event('change')

const inputEvent = new Event('input')

el.stepUp()
el.dispatchEvent(inputEvent)
el.dispatchEvent(changeEvent)
}
} else {
if (typeof el.stepDown === 'function') {
const changeEvent = new Event('change')
const inputEvent = new Event('input')

el.stepDown()
el.dispatchEvent(inputEvent)
el.dispatchEvent(changeEvent)
}
}
}
Expand Down

4 comments on commit 9c9bf5b

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 9c9bf5b Jun 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.12.0/linux-x64/develop-9c9bf5b690fccbea55361192ec75706359a4da26/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 9c9bf5b Jun 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.12.0/darwin-arm64/develop-9c9bf5b690fccbea55361192ec75706359a4da26/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 9c9bf5b Jun 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.12.0/win32-x64/develop-9c9bf5b690fccbea55361192ec75706359a4da26/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 9c9bf5b Jun 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.12.0/darwin-x64/develop-9c9bf5b690fccbea55361192ec75706359a4da26/cypress.tgz

Please sign in to comment.