mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-13 02:40:22 -05:00
fix type_spec for chrome
This commit is contained in:
@@ -4,6 +4,12 @@ Keyboard = Cypress.Keyboard
|
||||
Promise = Cypress.Promise
|
||||
$selection = require("../../../../../src/dom/selection")
|
||||
|
||||
## trim new lines at the end of innerText
|
||||
## due to changing browser versions implementing
|
||||
## this differently
|
||||
trimInnerText = ($el) ->
|
||||
_.trimEnd($el.get(0).innerText, "\n")
|
||||
|
||||
describe "src/cy/commands/actions/type", ->
|
||||
before ->
|
||||
cy
|
||||
@@ -11,6 +17,31 @@ describe "src/cy/commands/actions/type", ->
|
||||
.then (win) ->
|
||||
@body = win.document.body.outerHTML
|
||||
|
||||
el = cy.$$('[contenteditable]:first').get(0)
|
||||
|
||||
innerHtml = el.innerHTML
|
||||
|
||||
## by default... the last new line by itself
|
||||
## will only ever count as a single new line...
|
||||
## but new lines above it will count as 2 new lines...
|
||||
## so by adding "3" new lines, the last counts as 1
|
||||
## and the first 2 count as 2...
|
||||
el.innerHTML = '<div><br></div>'.repeat(3)
|
||||
|
||||
## browsers changed their implementation
|
||||
## of the number of newlines that <div><br></div>
|
||||
## create. newer versions of chrome set 2 new lines
|
||||
## per set - whereas older ones create only 1 new line.
|
||||
## so we grab the current sets for the assertion later
|
||||
## so this test is browser version agnostic
|
||||
newLines = el.innerText
|
||||
|
||||
## disregard the last new line, and divide by 2...
|
||||
## this tells us how many multiples of new lines
|
||||
## the browser inserts for new lines other than
|
||||
## the last new line
|
||||
@multiplierNumNewLines = (newLines.length - 1) / 2
|
||||
|
||||
beforeEach ->
|
||||
doc = cy.state("document")
|
||||
|
||||
@@ -1038,7 +1069,7 @@ describe "src/cy/commands/actions/type", ->
|
||||
cy.$$('[contenteditable]:first').get(0).innerHTML = '<div>foo</div>'
|
||||
cy.get("[contenteditable]:first")
|
||||
.type("bar").then ($div) ->
|
||||
expect($div.get(0).innerText).to.eql("foobar\n")
|
||||
expect(trimInnerText($div)).to.eql("foobar")
|
||||
expect($div.get(0).textContent).to.eql("foobar")
|
||||
expect($div.get(0).innerHTML).to.eql("<div>foobar</div>")
|
||||
|
||||
@@ -1046,7 +1077,7 @@ describe "src/cy/commands/actions/type", ->
|
||||
cy.$$('[contenteditable]:first').get(0).innerHTML = '<p>foo</p>'
|
||||
cy.get("[contenteditable]:first")
|
||||
.type("bar").then ($div) ->
|
||||
expect($div.get(0).innerText).to.eql("foobar\n\n")
|
||||
expect(trimInnerText($div)).to.eql("foobar")
|
||||
expect($div.get(0).textContent).to.eql("foobar")
|
||||
expect($div.get(0).innerHTML).to.eql("<p>foobar</p>")
|
||||
|
||||
@@ -1054,13 +1085,13 @@ describe "src/cy/commands/actions/type", ->
|
||||
cy.$$('[contenteditable]:first').get(0).innerHTML = '<div>bar</div>'
|
||||
cy.get("[contenteditable]:first")
|
||||
.type("{selectall}{leftarrow}foo").then ($div) ->
|
||||
expect($div.get(0).innerText).to.eql("foobar\n")
|
||||
expect(trimInnerText($div)).to.eql("foobar")
|
||||
|
||||
it "collapses selection to end on {rightarrow}", ->
|
||||
cy.$$('[contenteditable]:first').get(0).innerHTML = '<div>bar</div>'
|
||||
cy.get("[contenteditable]:first")
|
||||
.type("{selectall}{leftarrow}foo{selectall}{rightarrow}baz").then ($div) ->
|
||||
expect($div.get(0).innerText).to.eql("foobarbaz\n")
|
||||
expect(trimInnerText($div)).to.eql("foobarbaz")
|
||||
|
||||
it "can remove a placeholder <br>", ->
|
||||
cy.$$('[contenteditable]:first').get(0).innerHTML = '<div><br></div>'
|
||||
@@ -1451,7 +1482,7 @@ describe "src/cy/commands/actions/type", ->
|
||||
|
||||
cy.get("[contenteditable]:first")
|
||||
.type("{home}11{uparrow}{home}22{uparrow}{home}33").then ($div) ->
|
||||
expect($div.get(0).innerText).to.eql("33foo\n22bar\n11baz\n")
|
||||
expect(trimInnerText($div)).to.eql("33foo\n22bar\n11baz")
|
||||
|
||||
context "{end}", ->
|
||||
it "sets which and keyCode to 35 and does not fire keypress events", (done) ->
|
||||
@@ -1501,7 +1532,7 @@ describe "src/cy/commands/actions/type", ->
|
||||
|
||||
cy.get("[contenteditable]:first")
|
||||
.type("{end}11{uparrow}{end}22{uparrow}{end}33").then ($div) ->
|
||||
expect($div.get(0).innerText).to.eql("foo33\nbar22\nbaz11\n")
|
||||
expect(trimInnerText($div)).to.eql("foo33\nbar22\nbaz11")
|
||||
|
||||
context "{uparrow}", ->
|
||||
beforeEach ->
|
||||
@@ -1540,7 +1571,7 @@ describe "src/cy/commands/actions/type", ->
|
||||
|
||||
cy.get("[contenteditable]:first")
|
||||
.type("{leftarrow}{leftarrow}{uparrow}11{uparrow}22{downarrow}{downarrow}33").then ($div) ->
|
||||
expect($div.get(0).innerText).to.eql("foo22\nb11ar\nbaz33\n")
|
||||
expect(trimInnerText($div)).to.eql("foo22\nb11ar\nbaz33")
|
||||
|
||||
it "uparrow ignores current selection", ->
|
||||
ce = cy.$$('[contenteditable]:first').get(0)
|
||||
@@ -1556,7 +1587,7 @@ describe "src/cy/commands/actions/type", ->
|
||||
|
||||
cy.get("[contenteditable]:first")
|
||||
.type("{uparrow}11").then ($div) ->
|
||||
expect($div.get(0).innerText).to.eql("11foo\nbar\nbaz\n")
|
||||
expect(trimInnerText($div)).to.eql("11foo\nbar\nbaz")
|
||||
|
||||
it "up and down arrow on textarea", ->
|
||||
cy.$$('textarea:first').get(0).value = 'foo\nbar\nbaz'
|
||||
@@ -1570,7 +1601,6 @@ describe "src/cy/commands/actions/type", ->
|
||||
.type('{uparrow}{uparrow}')
|
||||
.should('have.value', '14')
|
||||
|
||||
|
||||
context "{downarrow}", ->
|
||||
beforeEach ->
|
||||
cy.$$("#comments").val("foo\nbar\nbaz")
|
||||
@@ -1626,7 +1656,7 @@ describe "src/cy/commands/actions/type", ->
|
||||
|
||||
cy.get("[contenteditable]:first")
|
||||
.type("{downarrow}22").then ($div) ->
|
||||
expect($div.get(0).innerText).to.eql("foo\n22bar\nbaz\n")
|
||||
expect(trimInnerText($div)).to.eql("foo\n22bar\nbaz")
|
||||
|
||||
context "{selectall}{del}", ->
|
||||
it "can select all the text and delete", ->
|
||||
@@ -1688,14 +1718,16 @@ describe "src/cy/commands/actions/type", ->
|
||||
it "inserts new line into [contenteditable] ", ->
|
||||
cy.get("#input-types [contenteditable]:first").invoke("text", "foo")
|
||||
.type("bar{enter}baz{enter}{enter}{enter}quux").then ($div) ->
|
||||
expect($div.get(0).innerText).to.eql("foobar\nbaz\n\n\nquux\n")
|
||||
conditionalNewLines = "\n\n".repeat(@multiplierNumNewLines)
|
||||
|
||||
expect(trimInnerText($div)).to.eql("foobar\nbaz#{conditionalNewLines}\nquux")
|
||||
expect($div.get(0).textContent).to.eql("foobarbazquux")
|
||||
expect($div.get(0).innerHTML).to.eql("foobar<div>baz</div><div><br></div><div><br></div><div>quux</div>")
|
||||
|
||||
it "inserts new line into [contenteditable] from midline", ->
|
||||
cy.get("#input-types [contenteditable]:first").invoke("text", "foo")
|
||||
.type("bar{leftarrow}{enter}baz{leftarrow}{enter}quux").then ($div) ->
|
||||
expect($div.get(0).innerText).to.eql("fooba\nba\nquuxzr\n")
|
||||
expect(trimInnerText($div)).to.eql("fooba\nba\nquuxzr")
|
||||
expect($div.get(0).textContent).to.eql("foobabaquuxzr")
|
||||
expect($div.get(0).innerHTML).to.eql("fooba<div>ba</div><div>quuxzr</div>")
|
||||
|
||||
@@ -2312,7 +2344,6 @@ describe "src/cy/commands/actions/type", ->
|
||||
.then ->
|
||||
expect(changed).to.eql 0
|
||||
|
||||
|
||||
describe "caret position", ->
|
||||
|
||||
it "respects being formatted by input event handlers"
|
||||
@@ -2380,32 +2411,35 @@ describe "src/cy/commands/actions/type", ->
|
||||
el.innerHTML = 'start'+
|
||||
'<div>middle</div>'+
|
||||
'<div>end</div>'
|
||||
|
||||
cy.get('[contenteditable]:first')
|
||||
## move cursor to beginning of div
|
||||
.type('{selectall}{leftarrow}')
|
||||
.type('{rightarrow}'.repeat(14)+'[_I_]').then ->
|
||||
expect(cy.$$('[contenteditable]:first').get(0).innerText).to.eql('start\nmiddle\ne[_I_]nd\n')
|
||||
.type('{rightarrow}'.repeat(14)+'[_I_]').then ($el) ->
|
||||
expect(trimInnerText($el)).to.eql('start\nmiddle\ne[_I_]nd')
|
||||
|
||||
it "can wrap cursor to prev line in [contenteditable] with {leftarrow}", ->
|
||||
$el = cy.$$('[contenteditable]:first')
|
||||
el = $el.get(0)
|
||||
|
||||
el.innerHTML = 'start'+
|
||||
'<div>middle</div>'+
|
||||
'<div>end</div>'
|
||||
cy.get('[contenteditable]:first').type('{leftarrow}'.repeat(12)+'[_I_]').then ->
|
||||
expect(cy.$$('[contenteditable]:first').get(0).innerText).to.eql('star[_I_]t\nmiddle\nend\n')
|
||||
|
||||
cy.get('[contenteditable]:first').type('{leftarrow}'.repeat(12)+'[_I_]').then ($el) ->
|
||||
expect(trimInnerText($el)).to.eql('star[_I_]t\nmiddle\nend')
|
||||
|
||||
it "can wrap cursor to next line in [contenteditable] with {rightarrow} and empty lines", ->
|
||||
$el = cy.$$('[contenteditable]:first')
|
||||
el = $el.get(0)
|
||||
el.innerHTML = '<div><br></div>'.repeat(4)+
|
||||
'<div>end</div>'
|
||||
el.innerHTML = '<div><br></div>'.repeat(4) + '<div>end</div>'
|
||||
|
||||
newLines = "\n\n\n".repeat(@multiplierNumNewLines)
|
||||
|
||||
cy.get('[contenteditable]:first')
|
||||
.type('{selectall}{leftarrow}')
|
||||
# .type('foobar'+'{rightarrow}'.repeat(6)+'[_I_]').then ->
|
||||
# expect(cy.$$('[contenteditable]:first').get(0).innerText).to.eql('foobar\n\n\n\nen[_I_]d\n')
|
||||
.type('foobar'+'{rightarrow}'.repeat(6)+'[_I_]').then ->
|
||||
expect(trimInnerText($el)).to.eql("foobar#{newLines}\nen[_I_]d")
|
||||
|
||||
it "can use {rightarrow} and nested elements", ->
|
||||
$el = cy.$$('[contenteditable]:first')
|
||||
@@ -2415,19 +2449,19 @@ describe "src/cy/commands/actions/type", ->
|
||||
cy.get('[contenteditable]:first')
|
||||
.type('{selectall}{leftarrow}')
|
||||
.type('{rightarrow}'.repeat(3)+'[_I_]').then ->
|
||||
expect(cy.$$('[contenteditable]:first').get(0).innerText).to.eql('sta[_I_]rt\n')
|
||||
expect(trimInnerText($el)).to.eql('sta[_I_]rt')
|
||||
|
||||
it "enter and \\n should act the same for [contenteditable]", ->
|
||||
|
||||
cleanseText = (text) ->
|
||||
text.replace(/ /g, ' ')
|
||||
## non breaking white space
|
||||
text.split('\u00a0').join(' ')
|
||||
|
||||
expectMatchInnerText = ($el , innerText) ->
|
||||
expect(cleanseText($el.get(0).innerText)).to.eql(innerText)
|
||||
expect(cleanseText(trimInnerText($el))).to.eql(innerText)
|
||||
|
||||
## NOTE: this may only pass in Chrome since the whitespace may be different in other browsers
|
||||
## even if actual and expected appear the same.
|
||||
expected = "{\n foo: 1\n bar: 2\n baz: 3\n}\n"
|
||||
expected = "{\n foo: 1\n bar: 2\n baz: 3\n}"
|
||||
cy.get('[contenteditable]:first')
|
||||
.invoke('html', '<div><br></div>')
|
||||
.type('{{}{enter} foo: 1{enter} bar: 2{enter} baz: 3{enter}}')
|
||||
@@ -2438,7 +2472,6 @@ describe "src/cy/commands/actions/type", ->
|
||||
.should ($el) ->
|
||||
expectMatchInnerText($el, expected)
|
||||
|
||||
|
||||
it "enter and \\n should act the same for textarea", ->
|
||||
expected = "{\n foo: 1\n bar: 2\n baz: 3\n}"
|
||||
cy.get('textarea:first')
|
||||
@@ -2449,8 +2482,6 @@ describe "src/cy/commands/actions/type", ->
|
||||
.type('{{}\n foo: 1\n bar: 2\n baz: 3\n}')
|
||||
.should('have.prop', 'value', expected)
|
||||
|
||||
|
||||
|
||||
describe "{enter}", ->
|
||||
beforeEach ->
|
||||
@$forms = cy.$$("#form-submits")
|
||||
|
||||
@@ -91,6 +91,7 @@ describe "src/cy/commands/navigation", ->
|
||||
expect(stub2).to.be.calledOnce
|
||||
expect(stub3).to.be.calledOnce
|
||||
|
||||
# Array(100).fill().map ->
|
||||
it "removes listeners", ->
|
||||
win = cy.state("window")
|
||||
|
||||
@@ -100,6 +101,14 @@ describe "src/cy/commands/navigation", ->
|
||||
expect(rel).to.be.calledWith("beforeunload")
|
||||
expect(rel).to.be.calledWith("unload")
|
||||
|
||||
|
||||
# cy.reload().then ->
|
||||
# cy.wrap(null).should ->
|
||||
# expect(rel).to.be.calledWith("beforeunload")
|
||||
# expect(rel).to.be.calledWith("unload")
|
||||
|
||||
|
||||
|
||||
describe "errors", ->
|
||||
beforeEach ->
|
||||
Cypress.config("defaultCommandTimeout", 50)
|
||||
@@ -149,6 +158,7 @@ describe "src/cy/commands/navigation", ->
|
||||
expect(win.foo).to.be.undefined
|
||||
|
||||
it "throws when reload times out", (done) ->
|
||||
console.time('foo')
|
||||
locReload = cy.spy(Cypress.utils, "locReload")
|
||||
|
||||
cy
|
||||
@@ -167,6 +177,8 @@ describe "src/cy/commands/navigation", ->
|
||||
cy.on "fail", (err) ->
|
||||
expected = true
|
||||
|
||||
console.timeEnd('foo')
|
||||
|
||||
expect(err.message).to.include "Your page did not fire its 'load' event within '1ms'."
|
||||
|
||||
.reload({timeout: 1})
|
||||
@@ -232,17 +244,18 @@ describe "src/cy/commands/navigation", ->
|
||||
$(doc.body).empty().html(@body)
|
||||
|
||||
## TODO: fix this
|
||||
it.skip "(FLAKY) sets timeout to Cypress.config(pageLoadTimeout)", ->
|
||||
timeout = cy.spy Promise.prototype, "timeout"
|
||||
Cypress.config("pageLoadTimeout", 4567)
|
||||
# it.skip "(FLAKY) sets timeout to Cypress.config(pageLoadTimeout)", ->
|
||||
# timeout = cy.spy Promise.prototype, "timeout"
|
||||
# Cypress.config("pageLoadTimeout", 4567)
|
||||
|
||||
cy
|
||||
.visit("/fixtures/jquery.html")
|
||||
.go("back").then ->
|
||||
expect(timeout).to.be.calledWith(4567, "go")
|
||||
# cy
|
||||
# .visit("/fixtures/jquery.html")
|
||||
# .go("back").then ->
|
||||
# expect(timeout).to.be.calledWith(4567, "go")
|
||||
|
||||
it "removes listeners", ->
|
||||
cy
|
||||
.visit("/fixtures/generic.html")
|
||||
.visit("/fixtures/jquery.html")
|
||||
.then ->
|
||||
winLoadListeners = cy.listeners("window:load")
|
||||
@@ -266,6 +279,7 @@ describe "src/cy/commands/navigation", ->
|
||||
stub3 = cy.stub()
|
||||
|
||||
cy
|
||||
.visit("/fixtures/generic.html")
|
||||
.visit("/fixtures/jquery.html")
|
||||
.then ->
|
||||
cy.on("stability:changed", stub1)
|
||||
@@ -279,6 +293,7 @@ describe "src/cy/commands/navigation", ->
|
||||
|
||||
it "removes listeners from window", ->
|
||||
cy
|
||||
.visit("/fixtures/generic.html")
|
||||
.visit("/fixtures/jquery.html")
|
||||
.then (win) ->
|
||||
rel = cy.stub(win, "removeEventListener")
|
||||
@@ -369,6 +384,7 @@ describe "src/cy/commands/navigation", ->
|
||||
|
||||
it "logs go", ->
|
||||
cy
|
||||
.visit("/fixtures/generic.html")
|
||||
.visit("/fixtures/jquery.html")
|
||||
.go("back").then ->
|
||||
lastLog = @lastLog
|
||||
@@ -378,12 +394,14 @@ describe "src/cy/commands/navigation", ->
|
||||
|
||||
it "can turn off logging", ->
|
||||
cy
|
||||
.visit("/fixtures/generic.html")
|
||||
.visit("/fixtures/jquery.html")
|
||||
.go("back", {log: false}).then ->
|
||||
expect(@lastLog).to.be.undefined
|
||||
|
||||
it "does not log 'Page Load' events", ->
|
||||
cy
|
||||
.visit("/fixtures/generic.html")
|
||||
.visit("/fixtures/jquery.html")
|
||||
.go("back").then ->
|
||||
@logs.slice(0).forEach (log) ->
|
||||
@@ -393,6 +411,7 @@ describe "src/cy/commands/navigation", ->
|
||||
beforeunload = false
|
||||
|
||||
cy
|
||||
.visit("/fixtures/generic.html")
|
||||
.visit("/fixtures/jquery.html")
|
||||
.window().then (win) ->
|
||||
cy.on "window:before:unload", =>
|
||||
|
||||
@@ -29,7 +29,7 @@ describe "return values", ->
|
||||
|
||||
it "stringifies function bodies", (done) ->
|
||||
cy.on "fail", (err) ->
|
||||
expect(err.message).to.include("> function () {")
|
||||
expect(err.message).to.include("> function")
|
||||
expect(err.message).to.include("return \"foo\";")
|
||||
expect(err.message).to.include("Cypress detected that you invoked one or more cy commands but returned a different value.")
|
||||
|
||||
@@ -78,7 +78,7 @@ describe "return values", ->
|
||||
expect(lastLog.get("name")).to.eq("foo")
|
||||
expect(lastLog.get("error")).to.eq(err)
|
||||
expect(err.message).to.include("> cy.foo()")
|
||||
expect(err.message).to.include("> function () {")
|
||||
expect(err.message).to.include("> function")
|
||||
expect(err.message).to.include("return \"bar\";")
|
||||
expect(err.message).to.include("Cypress detected that you invoked one or more cy commands in a custom command but returned a different value.")
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
"lib"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@babel/plugin-proposal-decorators": "7.4.0",
|
||||
"@babel/plugin-proposal-object-rest-spread": "7.4.0",
|
||||
"@cypress/react-tooltip": "0.4.0",
|
||||
"bin-up": "1.1.0",
|
||||
|
||||
Reference in New Issue
Block a user