Skip to content

Commit

Permalink
fixes #816 properly fire change events for react email + number inputs (
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-mann authored Oct 30, 2017
1 parent ad50516 commit bbaedcc
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 13 deletions.
13 changes: 12 additions & 1 deletion packages/driver/test/cypress/fixtures/react-15.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,18 @@
window.onChangeEvents = 0

ReactDOM.render(React.createElement('div', {},
React.createElement('input', { onChange (e) { window.onChangeEvents++ } })
React.createElement('input', {
type: 'text',
onChange (e) { window.onChangeEvents++ }
}),
React.createElement('input', {
type: 'email',
onChange (e) { window.onChangeEvents++ }
}),
React.createElement('input', {
type: 'number',
onChange (e) { window.onChangeEvents++ }
})
), document.getElementById('react-container'))
</script>
</body>
13 changes: 12 additions & 1 deletion packages/driver/test/cypress/fixtures/react-16.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,18 @@
window.onChangeEvents = 0

ReactDOM.render(React.createElement('div', {},
React.createElement('input', { onChange (e) { window.onChangeEvents++ } })
React.createElement('input', {
type: 'text',
onChange (e) { window.onChangeEvents++ }
}),
React.createElement('input', {
type: 'email',
onChange (e) { window.onChangeEvents++ }
}),
React.createElement('input', {
type: 'number',
onChange (e) { window.onChangeEvents++ }
})
), document.getElementById('react-container'))
</script>
</body>
23 changes: 18 additions & 5 deletions packages/driver/test/cypress/integration/e2e/react-15_spec.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
describe "react v15.6.0", ->
it "correctly fires onChange events", ->
cy
.visit("/fixtures/react-15.html")
.get("#react-container input").type("foo").blur()
.window().its("onChangeEvents").should("eq", 3)
context "fires onChange events", ->
beforeEach ->
cy.visit("/fixtures/react-15.html")

it "input", ->
cy
.get("#react-container input[type=text]").type("foo").blur()
.window().its("onChangeEvents").should("eq", 3)

it "email", ->
cy
.get("#react-container input[type=email]").type("foo").blur()
.window().its("onChangeEvents").should("eq", 3)

it "number", ->
cy
.get("#react-container input[type=number]").type("123").blur()
.window().its("onChangeEvents").should("eq", 3)
23 changes: 18 additions & 5 deletions packages/driver/test/cypress/integration/e2e/react-16_spec.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
describe "react v16.0.0", ->
it "correctly fires onChange events", ->
cy
.visit("/fixtures/react-16.html")
.get("#react-container input").type("foo").blur()
.window().its("onChangeEvents").should("eq", 3)
context "fires onChange events", ->
beforeEach ->
cy.visit("/fixtures/react-16.html")

it "input", ->
cy
.get("#react-container input[type=text]").type("foo").blur()
.window().its("onChangeEvents").should("eq", 3)

it "email", ->
cy
.get("#react-container input[type=email]").type("foo").blur()
.window().its("onChangeEvents").should("eq", 3)

it "number", ->
cy
.get("#react-container input[type=number]").type("123").blur()
.window().its("onChangeEvents").should("eq", 3)
10 changes: 9 additions & 1 deletion packages/driver/vendor/bililiteRange.js
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,15 @@ NothingRange.prototype._nativeGetText = function (rng){
};
NothingRange.prototype._nativeSetText = function (text, rng){
var val = this._el[this._textProp];
this._el[this._textProp] = val.substring(0, rng[0]) + text + val.substring(rng[1]);

var newVal = val.substring(0, rng[0]) + text + val.substring(rng[1])

if (this._textProp === "value") {
setValue(this._el, newVal)
} else {
this._el[this._textProp] = newVal
}

};
NothingRange.prototype._nativeEOL = function(){
this.text('\n');
Expand Down

0 comments on commit bbaedcc

Please sign in to comment.