Skip to content

Commit

Permalink
#3845 Attempt to add insert, page up and page down keys (#3892)
Browse files Browse the repository at this point in the history
* Attempt to add insert, page up and page down keys.

* Fix keyboard event for page down. Fix tests' titles.

* Fix the pagedown test.

* Fix comment for the insert key.
  • Loading branch information
clarmso authored and jennifer-shehane committed Apr 10, 2019
1 parent 2d6e13b commit 6e5ff7d
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 1 deletion.
44 changes: 43 additions & 1 deletion packages/driver/src/cypress/keyboard.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ charsBetweenCurlyBracesRe = /({.+?})/
keyStandardMap = {
# Cypress keyboard key : Standard value
"{backspace}": "Backspace",
"{insert}": "Insert",
"{del}": "Delete",
"{downarrow}": "ArrowDown",
"{enter}": "Enter",
Expand All @@ -25,7 +26,9 @@ keyStandardMap = {
"{alt}": "Alt",
"{ctrl}": "Control",
"{meta}": "Meta",
"{shift}": "Shift"
"{shift}": "Shift",
"{pageup}": "PageUp",
"{pagedown}": "PageDown"
}

$Keyboard = {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<div>ba</div><div>quuxzr</div>")

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", ->

Expand Down

0 comments on commit 6e5ff7d

Please sign in to comment.