From 1df3c32b7603c5b60c655d6598e4cc192bf490c3 Mon Sep 17 00:00:00 2001 From: Chris Breiding Date: Wed, 24 May 2017 11:48:15 -0400 Subject: [PATCH] driver: fix typing decimal into number input --- .../driver/src/cy/commands/actions/text.coffee | 17 ++++++++++++----- .../unit/cy/commands/actions/text_spec.coffee | 4 ++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/driver/src/cy/commands/actions/text.coffee b/packages/driver/src/cy/commands/actions/text.coffee index 2adca84387..498839dede 100644 --- a/packages/driver/src/cy/commands/actions/text.coffee +++ b/packages/driver/src/cy/commands/actions/text.coffee @@ -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) diff --git a/packages/driver/test/unit/cy/commands/actions/text_spec.coffee b/packages/driver/test/unit/cy/commands/actions/text_spec.coffee index c55e7de740..123b1443e0 100644 --- a/packages/driver/test/unit/cy/commands/actions/text_spec.coffee +++ b/packages/driver/test/unit/cy/commands/actions/text_spec.coffee @@ -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")