Skip to content

Commit

Permalink
fix: edge cases during cy.type in number input (#6033)
Browse files Browse the repository at this point in the history
- regressions introduced in `3.8.0`
  • Loading branch information
kuceb authored Dec 23, 2019
1 parent 37dd275 commit 16b76f4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/driver/src/cy/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const monthRe = /^\d{4}-(0\d|1[0-2])/
const weekRe = /^\d{4}-W(0[1-9]|[1-4]\d|5[0-3])/
const timeRe = /^([0-1]\d|2[0-3]):[0-5]\d(:[0-5]\d)?(\.[0-9]{1,3})?/
const dateTimeRe = /^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}/
const numberRe = /^-?(0|[1-9]\d*)(\.\d+)?(e-?(0|[1-9]\d*))?$/i
const numberRe = /^-?(\d+|\d+\.\d+|\.\d+)([eE][-+]?\d+)?$/i
const charsBetweenCurlyBracesRe = /({.+?})/

const INITIAL_MODIFIERS = {
Expand Down Expand Up @@ -260,7 +260,11 @@ const shouldUpdateValue = (el: HTMLElement, key: KeyDetails, options) => {

if (!(numberRe.test(potentialValue))) {
debug('skipping inserting value since number input would be invalid', key.text, potentialValue)
options.prevVal = needsValue + key.text
if (key.text.match(/[-+eE\d\.]/)) {
options.prevVal = needsValue + key.text
} else {
options.prevVal = ''
}

return
}
Expand Down Expand Up @@ -477,7 +481,9 @@ function _getEndIndex (str, substr) {
// Simulated default actions for select few keys.
const simulatedDefaultKeyMap: { [key: string]: SimulatedDefault } = {
Enter: (el, key, options) => {
$selection.replaceSelectionContents(el, '\n')
if (!$elements.isInput(el)) {
$selection.replaceSelectionContents(el, '\n')
}

options.onEnterPressed()
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1302,6 +1302,20 @@ describe('src/cy/commands/actions/type', () => {
expect(blurred).to.be.calledOnce
})
})

// https://github.com/cypress-io/cypress/issues/5997
it('type=number can accept values with commas (,)', () => {
cy.get('#number-without-value')
.type('1,000')
.should('have.value', '1000')
})

// https://github.com/cypress-io/cypress/issues/5968
it('type=number can include {enter}', () => {
cy.get('#number-without-value')
.type('100{enter}')
.should('have.value', '100')
})
})

describe('input[type=email]', () => {
Expand Down

4 comments on commit 16b76f4

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 16b76f4 Dec 23, 2019

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.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.8.1/linux-x64/circle-develop-16b76f4d99807f2466abe9c9ab25da8f26c0a293-222196/cypress.zip
npm install https://cdn.cypress.io/beta/npm/3.8.1/circle-develop-16b76f4d99807f2466abe9c9ab25da8f26c0a293-222185/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 16b76f4 Dec 23, 2019

Choose a reason for hiding this comment

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

AppVeyor has built the win32 ia32 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.8.1/win32-ia32/appveyor-develop-16b76f4d99807f2466abe9c9ab25da8f26c0a293-29725871/cypress.zip
npm install https://cdn.cypress.io/beta/binary/3.8.1/win32-ia32/appveyor-develop-16b76f4d99807f2466abe9c9ab25da8f26c0a293-29725871/cypress.zip

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 16b76f4 Dec 23, 2019

Choose a reason for hiding this comment

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

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

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.8.1/win32-x64/appveyor-develop-16b76f4d99807f2466abe9c9ab25da8f26c0a293-29725871/cypress.zip
npm install https://cdn.cypress.io/beta/binary/3.8.1/win32-x64/appveyor-develop-16b76f4d99807f2466abe9c9ab25da8f26c0a293-29725871/cypress.zip

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 16b76f4 Dec 23, 2019

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.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.8.1/darwin-x64/circle-develop-16b76f4d99807f2466abe9c9ab25da8f26c0a293-222233/cypress.zip
npm install https://cdn.cypress.io/beta/npm/3.8.1/circle-develop-16b76f4d99807f2466abe9c9ab25da8f26c0a293-222198/cypress.tgz

Please sign in to comment.