Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#3845 Attempt to add insert, page up and page down keys #3892

Merged
merged 7 commits into from
Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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