diff --git a/packages/driver/src/cypress/keyboard.coffee b/packages/driver/src/cypress/keyboard.coffee index 088befdd043a..8de28b8bc8c9 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,19 @@ $Keyboard = { return + ## charCode = 45 + ## no keyPress + ## no textInput + ## no input + "{insert}": (el, options) -> + options.charCode = 45 + options.keypress = false + options.textInput = false + options.input = false + options.setKey = "{insert}" + @ensureKey el, null, options + + ## charCode = 8 ## no keyPress ## no textInput @@ -239,6 +255,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 = 34 + ## 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: { 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 9b5437cc4805..c1ae3d1f556d 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 pageup 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("{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("{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("{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{pagedown}").then ($input) -> + expect($input).to.have.value("food") + done() describe "modifiers", ->