From 306d4057a84f51c691aed6d98c57e7f605617609 Mon Sep 17 00:00:00 2001 From: clarmso Date: Fri, 5 Apr 2019 00:00:46 -0400 Subject: [PATCH 1/4] Attempt to add insert, page up and page down keys. --- packages/driver/src/cypress/keyboard.coffee | 47 +++++++- .../commands/actions/type_spec.coffee | 101 ++++++++++++++++++ 2 files changed, 145 insertions(+), 3 deletions(-) diff --git a/packages/driver/src/cypress/keyboard.coffee b/packages/driver/src/cypress/keyboard.coffee index 0f1e55e486ec..8f1a1be4b404 100644 --- a/packages/driver/src/cypress/keyboard.coffee +++ b/packages/driver/src/cypress/keyboard.coffee @@ -13,6 +13,7 @@ charsBetweenCurlyBracesRe = /({.+?})/ keyStandardMap = { # Cypress keyboard key : Standard value "{backspace}": "Backspace", + "{insert}": "Insert", "{del}": "Delete", "{downarrow}": "ArrowDown", "{enter}": "Enter", @@ -25,7 +26,9 @@ keyStandardMap = { "{alt}": "Alt", "{ctrl}": "Control", "{meta}": "Meta", - "{shift}": "Shift" + "{shift}": "Shift", + "{pageup}": "PageUp", + "{pagedown}": "PageDown" } $Keyboard = { @@ -103,6 +106,18 @@ $Keyboard = { return + ## charCode = 45 + ## no keyPress + ## no textInput + ## yes input (if value is actually changed) + "{insert}": (el, options) -> + options.charCode = 45 + options.keypress = false + options.textInput = false + options.setKey = "{insert}" + @ensureKey el, null, options + + ## charCode = 8 ## no keyPress ## no textInput @@ -128,7 +143,7 @@ $Keyboard = { return - + ## charCode = 27 ## no keyPress ## no textInput @@ -239,6 +254,32 @@ $Keyboard = { options.setKey = "{end}" @ensureKey el, null, options, -> $selection.moveCursorToLineEnd(el) + + + ## charCode = 33 + ## no keyPress + ## no textInput + ## no input + "{pageup}": (el, options) -> + options.charCode = 33 + options.keypress = false + options.textInput = false + options.input = false + options.setKey = "{pageup}" + @ensureKey el, null, options + + + ## charCode = 33 + ## no keyPress + ## no textInput + ## no input + "{pagedown}": (el, options) -> + options.charCode = 34 + options.keypress = false + options.textInput = false + options.input = false + options.setKey = "{pagedown}" + @ensureKey el, null, options } modifierChars: { @@ -483,7 +524,7 @@ $Keyboard = { if $elements.isInput(el) or $elements.isTextarea(el) ml = el.maxLength - + ## maxlength is -1 by default when omitted ## but could also be null or undefined :-/ ## only cafe if we are trying to type a key diff --git a/packages/driver/test/cypress/integration/commands/actions/type_spec.coffee b/packages/driver/test/cypress/integration/commands/actions/type_spec.coffee index ca101ce878a8..5085ade88e6f 100644 --- a/packages/driver/test/cypress/integration/commands/actions/type_spec.coffee +++ b/packages/driver/test/cypress/integration/commands/actions/type_spec.coffee @@ -1699,6 +1699,107 @@ describe "src/cy/commands/actions/type", -> expect($div.get(0).textContent).to.eql("foobabaquuxzr") expect($div.get(0).innerHTML).to.eql("fooba
ba
quuxzr
") + context "{insert}", -> + it "sets which and keyCode to 45 and does not fire keypress events", (done) -> + cy.$$(":text:first").on "keypress", -> + done("should not have received keypress") + + cy.$$(":text:first").on "keydown", (e) -> + expect(e.which).to.eq 45 + expect(e.keyCode).to.eq 45 + expect(e.key).to.eq "Insert" + done() + + cy.get(":text:first").invoke("val", "ab").type("{insert}") + + it "does not fire textInput event", (done) -> + cy.$$(":text:first").on "textInput", (e) -> + done("textInput should not have fired") + + cy.get(":text:first").invoke("val", "ab").type("{insert}").then -> done() + + it "does not fire input event", (done) -> + cy.$$(":text:first").on "input", (e) -> + done("input should not have fired") + + cy.get(":text:first").invoke("val", "ab").type("{insert}").then -> done() + + it "can prevent default insert movement", (done) -> + cy.$$(":text:first").on "keydown", (e) -> + if e.keyCode is 45 + e.preventDefault() + + cy.get(":text:first").invoke("val", "foo").type("d{insert}").then ($input) -> + expect($input).to.have.value("food") + done() + + context "{pageup}", -> + it "sets which and keyCode to 33 and does not fire keypress events", (done) -> + cy.$$(":text:first").on "keypress", -> + done("should not have received keypress") + + cy.$$(":text:first").on "keydown", (e) -> + expect(e.which).to.eq 33 + expect(e.keyCode).to.eq 33 + expect(e.key).to.eq "PageUp" + done() + + cy.get(":text:first").invoke("val", "ab").type("{pageup}") + + it "does not fire textInput event", (done) -> + cy.$$(":text:first").on "textInput", (e) -> + done("textInput should not have fired") + + cy.get(":text:first").invoke("val", "ab").type("{pageup}").then -> done() + + it "does not fire input event", (done) -> + cy.$$(":text:first").on "input", (e) -> + done("input should not have fired") + + cy.get(":text:first").invoke("val", "ab").type("{pageup}").then -> done() + + it "can prevent default insert movement", (done) -> + cy.$$(":text:first").on "keydown", (e) -> + if e.keyCode is 33 + e.preventDefault() + + cy.get(":text:first").invoke("val", "foo").type("d{pageup}").then ($input) -> + expect($input).to.have.value("food") + done() + + context "{pagedown}", -> + it "sets which and keyCode to 34 and does not fire keypress events", (done) -> + cy.$$(":text:first").on "keypress", -> + done("should not have received keypress") + + cy.$$(":text:first").on "keydown", (e) -> + expect(e.which).to.eq 34 + expect(e.keyCode).to.eq 34 + expect(e.key).to.eq "PageDown" + done() + + cy.get(":text:first").invoke("val", "ab").type("{pageup}") + + it "does not fire textInput event", (done) -> + cy.$$(":text:first").on "textInput", (e) -> + done("textInput should not have fired") + + cy.get(":text:first").invoke("val", "ab").type("{pageup}").then -> done() + + it "does not fire input event", (done) -> + cy.$$(":text:first").on "input", (e) -> + done("input should not have fired") + + cy.get(":text:first").invoke("val", "ab").type("{pageup}").then -> done() + + it "can prevent default insert movement", (done) -> + cy.$$(":text:first").on "keydown", (e) -> + if e.keyCode is 34 + e.preventDefault() + + cy.get(":text:first").invoke("val", "foo").type("d{pageup}").then ($input) -> + expect($input).to.have.value("food") + done() describe "modifiers", -> From 5ca2025f048930ceaf01d116797c8e50b67158e8 Mon Sep 17 00:00:00 2001 From: clarmso Date: Fri, 5 Apr 2019 21:25:04 -0400 Subject: [PATCH 2/4] Fix keyboard event for page down. Fix tests' titles. --- packages/driver/src/cypress/keyboard.coffee | 3 ++- .../cypress/integration/commands/actions/type_spec.coffee | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/driver/src/cypress/keyboard.coffee b/packages/driver/src/cypress/keyboard.coffee index 8f1a1be4b404..e0ec75de5b04 100644 --- a/packages/driver/src/cypress/keyboard.coffee +++ b/packages/driver/src/cypress/keyboard.coffee @@ -114,6 +114,7 @@ $Keyboard = { options.charCode = 45 options.keypress = false options.textInput = false + options.input = false options.setKey = "{insert}" @ensureKey el, null, options @@ -269,7 +270,7 @@ $Keyboard = { @ensureKey el, null, options - ## charCode = 33 + ## charCode = 34 ## no keyPress ## no textInput ## no input diff --git a/packages/driver/test/cypress/integration/commands/actions/type_spec.coffee b/packages/driver/test/cypress/integration/commands/actions/type_spec.coffee index 5085ade88e6f..077c0f86e594 100644 --- a/packages/driver/test/cypress/integration/commands/actions/type_spec.coffee +++ b/packages/driver/test/cypress/integration/commands/actions/type_spec.coffee @@ -1758,7 +1758,7 @@ describe "src/cy/commands/actions/type", -> cy.get(":text:first").invoke("val", "ab").type("{pageup}").then -> done() - it "can prevent default insert movement", (done) -> + it "can prevent default pageup movement", (done) -> cy.$$(":text:first").on "keydown", (e) -> if e.keyCode is 33 e.preventDefault() @@ -1792,7 +1792,7 @@ describe "src/cy/commands/actions/type", -> cy.get(":text:first").invoke("val", "ab").type("{pageup}").then -> done() - it "can prevent default insert movement", (done) -> + it "can prevent default pagedown movement", (done) -> cy.$$(":text:first").on "keydown", (e) -> if e.keyCode is 34 e.preventDefault() From dfc453973df6bd413b0e6b1e8ef1baa97727e442 Mon Sep 17 00:00:00 2001 From: clarmso Date: Fri, 5 Apr 2019 22:00:37 -0400 Subject: [PATCH 3/4] Fix the pagedown test. --- .../cypress/integration/commands/actions/type_spec.coffee | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/driver/test/cypress/integration/commands/actions/type_spec.coffee b/packages/driver/test/cypress/integration/commands/actions/type_spec.coffee index 077c0f86e594..cf2e46571d9f 100644 --- a/packages/driver/test/cypress/integration/commands/actions/type_spec.coffee +++ b/packages/driver/test/cypress/integration/commands/actions/type_spec.coffee @@ -1778,26 +1778,26 @@ describe "src/cy/commands/actions/type", -> expect(e.key).to.eq "PageDown" done() - cy.get(":text:first").invoke("val", "ab").type("{pageup}") + cy.get(":text:first").invoke("val", "ab").type("{pagedown}") it "does not fire textInput event", (done) -> cy.$$(":text:first").on "textInput", (e) -> done("textInput should not have fired") - cy.get(":text:first").invoke("val", "ab").type("{pageup}").then -> done() + cy.get(":text:first").invoke("val", "ab").type("{pagedown}").then -> done() it "does not fire input event", (done) -> cy.$$(":text:first").on "input", (e) -> done("input should not have fired") - cy.get(":text:first").invoke("val", "ab").type("{pageup}").then -> done() + cy.get(":text:first").invoke("val", "ab").type("{pagedown}").then -> done() it "can prevent default pagedown movement", (done) -> cy.$$(":text:first").on "keydown", (e) -> if e.keyCode is 34 e.preventDefault() - cy.get(":text:first").invoke("val", "foo").type("d{pageup}").then ($input) -> + cy.get(":text:first").invoke("val", "foo").type("d{pagedown}").then ($input) -> expect($input).to.have.value("food") done() From 6c19a64ef2e2866297c425365c1688ec89ffdf8b Mon Sep 17 00:00:00 2001 From: clarmso Date: Mon, 8 Apr 2019 22:45:50 -0400 Subject: [PATCH 4/4] Fix comment for the insert key. --- packages/driver/src/cypress/keyboard.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/driver/src/cypress/keyboard.coffee b/packages/driver/src/cypress/keyboard.coffee index e0ec75de5b04..13bed68c251c 100644 --- a/packages/driver/src/cypress/keyboard.coffee +++ b/packages/driver/src/cypress/keyboard.coffee @@ -109,7 +109,7 @@ $Keyboard = { ## charCode = 45 ## no keyPress ## no textInput - ## yes input (if value is actually changed) + ## no input "{insert}": (el, options) -> options.charCode = 45 options.keypress = false