Skip to content

Commit

Permalink
Add test case for Chrome under 53
Browse files Browse the repository at this point in the history
  • Loading branch information
yesmeck committed Apr 2, 2017
1 parent 54d73f1 commit 3685701
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 101 deletions.
3 changes: 2 additions & 1 deletion scripts/fiber/tests-passing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,8 @@ src/renderers/dom/shared/eventPlugins/__tests__/ChangeEventPlugin-test.js
* should deduplicate input value change events
* should listen for both change and input events when supported
* should only fire events when the value changes for range inputs
* should only fire change once on Webkit
* should only fire change once on Chrome
* should only fire change once on Chrome under 53
* should only fire change once on Firefox
* should only fire change once on IE9
* should only fire change once on IE10
Expand Down
13 changes: 4 additions & 9 deletions src/renderers/dom/shared/eventPlugins/ChangeEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,20 +228,15 @@ function getTargetInstForInputOrChangeEvent(topLevelType, targetInst) {
if (inComposition(topLevelType)) {
return;
} else if (
topLevelType === 'topInput' &&
lastTopLevelType === 'topCompositionEnd'
topLevelType === 'topInput' && lastTopLevelType === 'topCompositionEnd'
) {
return getInstIfValueChanged(targetInst);
} else if (
// Webkit fires 'compositionEnd' event after 'input' event.
topLevelType === 'topKeyUp' &&
lastTopLevelType === 'topCompositionEnd'
topLevelType === 'topKeyUp' && lastTopLevelType === 'topCompositionEnd'
) {
// Chrome fires 'compositionEnd' event after 'input' event.
return getInstIfValueChanged(targetInst);
} else if (
topLevelType === 'topInput' ||
topLevelType === 'topChange'
) {
} else if (topLevelType === 'topInput' || topLevelType === 'topChange') {
return getInstIfValueChanged(targetInst);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,120 +236,143 @@ describe('ChangeEventPlugin', () => {
}

var input = ReactTestUtils.renderIntoDocument(
<input type="text" onChange={cb} />
<input type="text" onChange={cb} />,
);

Scenario.forEach(el => {
el.run.apply(null, [input].concat(el.args))
el.run.apply(null, [input].concat(el.args));
});

expect(called).toBe(1);
expect(value).toBe('你');
}

var Scenario = {
Webkit: [
{ run: setUntrackedValue, args: [ 'n' ] },
{ run: simulateEvent, args: [ 'keyDown' ] },
{ run: simulateEvent, args: [ 'compositionStart' ] },
{ run: simulateEvent, args: [ 'compositionUpdate' ] },
{ run: simulateEvent, args: [ 'input' ] },
{ run: simulateEvent, args: [ 'keyUp' ] },
{ run: setUntrackedValue, args: [ 'ni' ] },
{ run: simulateEvent, args: [ 'keyDown' ] },
{ run: simulateEvent, args: [ 'compositionUpdate' ] },
{ run: simulateEvent, args: [ 'input' ] },
{ run: simulateEvent, args: [ 'keyUp' ] },
{ run: setUntrackedValue, args: [ '你' ] },
{ run: simulateEvent, args: [ 'keyDown' ] },
{ run: simulateEvent, args: [ 'compositionUpdate' ] },
{ run: simulateEvent, args: [ 'textInput' ] },
{ run: simulateEvent, args: [ 'input' ] },
{ run: simulateEvent, args: [ 'compositionEnd' ] },
{ run: simulateEvent, args: [ 'keyUp' ] },
ChromeUnder53: [
{run: setUntrackedValue, args: ['n']},
{run: simulateEvent, args: ['keyDown']},
{run: simulateEvent, args: ['compositionStart']},
{run: simulateEvent, args: ['compositionUpdate']},
{run: simulateEvent, args: ['input']},
{run: simulateEvent, args: ['keyUp']},
{run: setUntrackedValue, args: ['ni']},
{run: simulateEvent, args: ['keyDown']},
{run: simulateEvent, args: ['compositionUpdate']},
{run: simulateEvent, args: ['input']},
{run: simulateEvent, args: ['keyUp']},
{run: setUntrackedValue, args: ['你']},
{run: simulateEvent, args: ['keyDown']},
{run: simulateEvent, args: ['compositionEnd']},
{run: simulateEvent, args: ['textInput']},
{run: simulateEvent, args: ['input']},
{run: simulateEvent, args: ['keyUp']},
],
Chrome: [
{run: setUntrackedValue, args: ['n']},
{run: simulateEvent, args: ['keyDown']},
{run: simulateEvent, args: ['compositionStart']},
{run: simulateEvent, args: ['compositionUpdate']},
{run: simulateEvent, args: ['input']},
{run: simulateEvent, args: ['keyUp']},
{run: setUntrackedValue, args: ['ni']},
{run: simulateEvent, args: ['keyDown']},
{run: simulateEvent, args: ['compositionUpdate']},
{run: simulateEvent, args: ['input']},
{run: simulateEvent, args: ['keyUp']},
{run: setUntrackedValue, args: ['你']},
{run: simulateEvent, args: ['keyDown']},
{run: simulateEvent, args: ['compositionUpdate']},
{run: simulateEvent, args: ['textInput']},
{run: simulateEvent, args: ['input']},
{run: simulateEvent, args: ['compositionEnd']},
{run: simulateEvent, args: ['keyUp']},
],
Firefox: [
{ run: setUntrackedValue, args: [ 'n' ] },
{ run: simulateEvent, args: [ 'keyDown' ] },
{ run: simulateEvent, args: [ 'compositionStart' ] },
{ run: simulateEvent, args: [ 'compositionUpdate' ] },
{ run: simulateEvent, args: [ 'input' ] },
{ run: setUntrackedValue, args: [ 'ni' ] },
{ run: simulateEvent, args: [ 'compositionUpdate' ] },
{ run: simulateEvent, args: [ 'input' ] },
{ run: setUntrackedValue, args: [ '你' ] },
{ run: simulateEvent, args: [ 'compositionUpdate' ] },
{ run: simulateEvent, args: [ 'compositionEnd' ] },
{ run: simulateEvent, args: [ 'input' ] },
{ run: simulateEvent, args: [ 'keyUp' ] },
{run: setUntrackedValue, args: ['n']},
{run: simulateEvent, args: ['keyDown']},
{run: simulateEvent, args: ['compositionStart']},
{run: simulateEvent, args: ['compositionUpdate']},
{run: simulateEvent, args: ['input']},
{run: setUntrackedValue, args: ['ni']},
{run: simulateEvent, args: ['compositionUpdate']},
{run: simulateEvent, args: ['input']},
{run: setUntrackedValue, args: ['你']},
{run: simulateEvent, args: ['compositionUpdate']},
{run: simulateEvent, args: ['compositionEnd']},
{run: simulateEvent, args: ['input']},
{run: simulateEvent, args: ['keyUp']},
],
IE9: [
{ run: setUntrackedValue, args: [ 'n' ] },
{ run: simulateEvent, args: [ 'keyDown' ] },
{ run: simulateEvent, args: [ 'compositionStart' ] },
{ run: simulateEvent, args: [ 'compositionUpdate' ] },
{ run: simulateEvent, args: [ 'keyUp' ] },
{ run: setUntrackedValue, args: [ 'ni' ] },
{ run: simulateEvent, args: [ 'keyDown' ] },
{ run: simulateEvent, args: [ 'compositionUpdate' ] },
{ run: simulateEvent, args: [ 'keyUp' ] },
{ run: setUntrackedValue, args: [ '你' ] },
{ run: simulateEvent, args: [ 'keyDown' ] },
{ run: simulateEvent, args: [ 'input' ] },
{ run: simulateEvent, args: [ 'compositionUpdate' ] },
{ run: simulateEvent, args: [ 'compositionEnd' ] },
{ run: simulateEvent, args: [ 'keyUp' ] },
{run: setUntrackedValue, args: ['n']},
{run: simulateEvent, args: ['keyDown']},
{run: simulateEvent, args: ['compositionStart']},
{run: simulateEvent, args: ['compositionUpdate']},
{run: simulateEvent, args: ['keyUp']},
{run: setUntrackedValue, args: ['ni']},
{run: simulateEvent, args: ['keyDown']},
{run: simulateEvent, args: ['compositionUpdate']},
{run: simulateEvent, args: ['keyUp']},
{run: setUntrackedValue, args: ['你']},
{run: simulateEvent, args: ['keyDown']},
{run: simulateEvent, args: ['input']},
{run: simulateEvent, args: ['compositionUpdate']},
{run: simulateEvent, args: ['compositionEnd']},
{run: simulateEvent, args: ['keyUp']},
],
IE10: [
{ run: setUntrackedValue, args: [ 'n' ] },
{ run: simulateEvent, args: [ 'keyDown' ] },
{ run: simulateEvent, args: [ 'compositionStart' ] },
{ run: simulateEvent, args: [ 'keyUp' ] },
{ run: setUntrackedValue, args: [ 'ni' ] },
{ run: simulateEvent, args: [ 'keyDown' ] },
{ run: simulateEvent, args: [ 'keyUp' ] },
{ run: setUntrackedValue, args: [ '你' ] },
{ run: simulateEvent, args: [ 'keyDown' ] },
{ run: simulateEvent, args: [ 'keyUp' ] },
{ run: simulateEvent, args: [ 'keyDown' ] },
{ run: simulateEvent, args: [ 'compositionEnd' ] },
{ run: simulateEvent, args: [ 'input' ] },
{ run: simulateEvent, args: [ 'keyUp' ] },
{run: setUntrackedValue, args: ['n']},
{run: simulateEvent, args: ['keyDown']},
{run: simulateEvent, args: ['compositionStart']},
{run: simulateEvent, args: ['keyUp']},
{run: setUntrackedValue, args: ['ni']},
{run: simulateEvent, args: ['keyDown']},
{run: simulateEvent, args: ['keyUp']},
{run: setUntrackedValue, args: ['你']},
{run: simulateEvent, args: ['keyDown']},
{run: simulateEvent, args: ['keyUp']},
{run: simulateEvent, args: ['keyDown']},
{run: simulateEvent, args: ['compositionEnd']},
{run: simulateEvent, args: ['input']},
{run: simulateEvent, args: ['keyUp']},
],
IE11: [
{ run: setUntrackedValue, args: [ 'n' ] },
{ run: simulateEvent, args: [ 'keyDown' ] },
{ run: simulateEvent, args: [ 'compositionStart' ] },
{ run: simulateEvent, args: [ 'compositionUpdate' ] },
{ run: simulateEvent, args: [ 'input' ] },
{ run: simulateEvent, args: [ 'keyUp' ] },
{ run: setUntrackedValue, args: [ 'ni' ] },
{ run: simulateEvent, args: [ 'keyDown' ] },
{ run: simulateEvent, args: [ 'input' ] },
{ run: simulateEvent, args: [ 'keyUp' ] },
{ run: setUntrackedValue, args: [ '你' ] },
{ run: simulateEvent, args: [ 'keyDown' ] },
{ run: simulateEvent, args: [ 'compositionEnd' ] },
{ run: simulateEvent, args: [ 'input' ] },
{ run: simulateEvent, args: [ 'keyUp' ] },
{run: setUntrackedValue, args: ['n']},
{run: simulateEvent, args: ['keyDown']},
{run: simulateEvent, args: ['compositionStart']},
{run: simulateEvent, args: ['compositionUpdate']},
{run: simulateEvent, args: ['input']},
{run: simulateEvent, args: ['keyUp']},
{run: setUntrackedValue, args: ['ni']},
{run: simulateEvent, args: ['keyDown']},
{run: simulateEvent, args: ['input']},
{run: simulateEvent, args: ['keyUp']},
{run: setUntrackedValue, args: ['你']},
{run: simulateEvent, args: ['keyDown']},
{run: simulateEvent, args: ['compositionEnd']},
{run: simulateEvent, args: ['input']},
{run: simulateEvent, args: ['keyUp']},
],
Edge: [
{ run: setUntrackedValue, args: [ 'n' ] },
{ run: simulateEvent, args: [ 'keyDown' ] },
{ run: simulateEvent, args: [ 'compositionStart' ] },
{ run: simulateEvent, args: [ 'keyUp' ] },
{ run: setUntrackedValue, args: [ 'ni' ] },
{ run: simulateEvent, args: [ 'keyDown' ] },
{ run: simulateEvent, args: [ 'keyUp' ] },
{ run: setUntrackedValue, args: [ '你' ] },
{ run: simulateEvent, args: [ 'keyDown' ] },
{ run: simulateEvent, args: [ 'compositionEnd' ] },
{ run: simulateEvent, args: [ 'input' ] },
{run: setUntrackedValue, args: ['n']},
{run: simulateEvent, args: ['keyDown']},
{run: simulateEvent, args: ['compositionStart']},
{run: simulateEvent, args: ['keyUp']},
{run: setUntrackedValue, args: ['ni']},
{run: simulateEvent, args: ['keyDown']},
{run: simulateEvent, args: ['keyUp']},
{run: setUntrackedValue, args: ['你']},
{run: simulateEvent, args: ['keyDown']},
{run: simulateEvent, args: ['compositionEnd']},
{run: simulateEvent, args: ['input']},
],
};

it('should only fire change once on Webkit', () => {
TestCompositionEvent(Scenario.Webkit);
it('should only fire change once on Chrome', () => {
TestCompositionEvent(Scenario.Chrome);
});

it('should only fire change once on Chrome under 53', () => {
TestCompositionEvent(Scenario.ChromeUnder53);
});

it('should only fire change once on Firefox', () => {
Expand Down

0 comments on commit 3685701

Please sign in to comment.