driver: fix typing decimal into number input

This commit is contained in:
Chris Breiding
2017-05-24 11:48:15 -04:00
parent 4aae695a28
commit 1df3c32b76
2 changed files with 16 additions and 5 deletions
@@ -212,6 +212,13 @@ module.exports = (Cypress, Commands) ->
return dispatched
needSingleValueChange = ->
isDate or
isMonth or
isWeek or
isTime or
(options.$el.is("[type=number]") and _.includes(options.chars, "."))
## see comment in updateValue below
typed = ""
@@ -223,11 +230,11 @@ module.exports = (Cypress, Commands) ->
window: @privateState("window")
updateValue: (rng, key) ->
## date/month/week/time inputs need to only have their value updated
## once after all the characters are input because attemping
## to set a partial/invalid value results in the value being
## set to an empty string
if isDate or isMonth or isWeek or isTime
if needSingleValueChange()
## in these cases, the value must only be set after all
## the characters are input because attemping to set
## a partial/invalid value results in the value being
## set to an empty string
typed += key
if typed is options.chars
options.$el.val(options.chars)
@@ -513,6 +513,10 @@ describe "$Cypress.Cy Text Commands", ->
@cy.get("#number-without-value").type("42").then ($text) ->
expect($text).to.have.value("42")
it "can input decimal", ->
@cy.get("#number-without-value").type("2.0").then ($input) ->
expect($input).to.have.value("2.0")
it "can utilize {selectall}", ->
@cy.get("#number-with-value").type("{selectall}99").then ($input) ->
expect($input).to.have.value("99")