Skip to content

Commit

Permalink
Merge pull request #1195 from buschtoens/tests-firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue authored Mar 31, 2022
2 parents 7d0aab9 + 0a1245e commit c74acb8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
3 changes: 3 additions & 0 deletions tests/helpers/browser-detect.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ export const isIE11 = !window.ActiveXObject && 'ActiveXObject' in window;
export const isIE = 'ActiveXObject' in window;

export const isEdge = navigator.userAgent.indexOf('Edge') >= 0;

// Unlike Chrome, Firefox emits `selectionchange` events.
export const isFirefox = navigator.userAgent.indexOf('Firefox') >= 0;
10 changes: 7 additions & 3 deletions tests/unit/dom/fill-in-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import {
_registerHook,
} from '@ember/test-helpers';
import { buildInstrumentedElement, insertElement } from '../../helpers/events';
import { isIE11 } from '../../helpers/browser-detect';
import { isIE11, isFirefox } from '../../helpers/browser-detect';
import hasEmberVersion from '@ember/test-helpers/has-ember-version';

let clickSteps = ['focus', 'focusin', 'input', 'change'];

if (isIE11) {
clickSteps = ['focusin', 'input', 'change', 'focus'];
} else if (isFirefox) {
clickSteps.push('selectionchange');
}

module('DOM Helper: fillIn', function (hooks) {
Expand Down Expand Up @@ -226,7 +228,8 @@ module('DOM Helper: fillIn', function (hooks) {
await setupContext(context);
await fillIn(element, 'foo');

assert.verifySteps(clickSteps);
// For this specific case, Firefox does not emit `selectionchange`.
assert.verifySteps(clickSteps.filter((s) => s !== 'selectionchange'));
assert.strictEqual(
document.activeElement,
element,
Expand Down Expand Up @@ -255,7 +258,8 @@ module('DOM Helper: fillIn', function (hooks) {
await setupContext(context);
await fillIn(`#${element.id}`, '');

assert.verifySteps(clickSteps);
// For this specific case, Firefox does not emit `selectionchange`.
assert.verifySteps(clickSteps.filter((s) => s !== 'selectionchange'));
assert.strictEqual(
document.activeElement,
element,
Expand Down
31 changes: 27 additions & 4 deletions tests/unit/dom/type-in-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
_registerHook,
} from '@ember/test-helpers';
import { buildInstrumentedElement, insertElement } from '../../helpers/events';
import { isIE11 } from '../../helpers/browser-detect';
import { isIE11, isFirefox } from '../../helpers/browser-detect';
import { debounce } from '@ember/runloop';
import { Promise } from 'rsvp';
import hasEmberVersion from '@ember/test-helpers/has-ember-version';
Expand Down Expand Up @@ -49,6 +49,27 @@ if (isIE11) {
'change',
'focus',
];
} else if (isFirefox) {
expectedEvents = [
'focus',
'focusin',
'keydown',
'keypress',
'input',
'keyup',
'selectionchange',
'keydown',
'keypress',
'input',
'keyup',
'selectionchange',
'keydown',
'keypress',
'input',
'keyup',
'change',
'selectionchange',
];
}

module('DOM Helper: typeIn', function (hooks) {
Expand Down Expand Up @@ -164,7 +185,9 @@ module('DOM Helper: typeIn', function (hooks) {
element.setAttribute('contenteditable', 'true');
await typeIn(element, 'foo');

assert.verifySteps(expectedEvents);
// For this specific case, Firefox does not emit `selectionchange`.
assert.verifySteps(expectedEvents.filter((s) => s !== 'selectionchange'));

assert.strictEqual(
document.activeElement,
element,
Expand Down Expand Up @@ -302,7 +325,7 @@ module('DOM Helper: typeIn', function (hooks) {
await assert.rejects(
typeIn(element, tooLongString).finally(() => {
// should throw before the second input event (or second keyup for IE)
const expectedNumberOfSteps = isIE11 ? 6 : 8;
const expectedNumberOfSteps = isIE11 ? 6 : isFirefox ? 9 : 8;
assert.verifySteps(expectedEvents.slice(0, expectedNumberOfSteps));
}),
new Error("Can not `typeIn` with text: 'fo' that exceeds maxlength: '1'.")
Expand Down Expand Up @@ -355,7 +378,7 @@ module('DOM Helper: typeIn', function (hooks) {
await assert.rejects(
typeIn(element, tooLongString).finally(() => {
// should throw before the second input event (or second keyup for IE)
const expectedNumberOfSteps = isIE11 ? 6 : 8;
const expectedNumberOfSteps = isIE11 ? 6 : isFirefox ? 9 : 8;
assert.verifySteps(expectedEvents.slice(0, expectedNumberOfSteps));
}),
new Error("Can not `typeIn` with text: 'fo' that exceeds maxlength: '1'.")
Expand Down

0 comments on commit c74acb8

Please sign in to comment.