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

Test/resize observer loop handler #679

Merged
merged 17 commits into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
10 changes: 5 additions & 5 deletions packages/elements/src/clock/__test__/clock.interactive.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ describe('clock/Interactive', () => {
expect(offsetChangedCount, 'offset-changed count should be 1').to.be.equal(1);
expect(offsetEvent.detail.value, '  should be 60').to.be.equal(60);
});

describe('Accessibility', () => {
it('Should have role="spinbutton", be focusable, and aria attributes', async () => {
expect(el.getAttribute('role')).to.be.equal('spinbutton');
Expand All @@ -165,7 +165,7 @@ describe('clock/Interactive', () => {
createKeyboardEvent(el, InputKey.ArrowUp);
await elementUpdated(el);
await nextFrame();

expect(el.getAttribute('aria-valuetext')).to.be.equal('Time: 01:00');
expect(el.getAttribute('aria-valuenow')).to.be.equal(el.displayTime.toString());
});
Expand All @@ -174,7 +174,7 @@ describe('clock/Interactive', () => {
createKeyboardEvent(el, InputKey.ArrowDown);
await elementUpdated(el);
await nextFrame();

expect(el.getAttribute('aria-valuetext')).to.be.equal('Time: 23:00');
expect(el.getAttribute('aria-valuenow')).to.be.equal(el.displayTime.toString());
});
Expand All @@ -183,7 +183,7 @@ describe('clock/Interactive', () => {
createKeyboardEvent(el, InputKey.ArrowUp);
await elementUpdated(el);
await nextFrame();

expect(el.getAttribute('aria-valuetext')).to.be.equal('Time: 00:01');
expect(el.getAttribute('aria-valuenow')).to.be.equal(el.displayTime.toString());
});
Expand All @@ -192,7 +192,7 @@ describe('clock/Interactive', () => {
createKeyboardEvent(el, InputKey.ArrowUp);
await elementUpdated(el);
await nextFrame();

expect(el.getAttribute('aria-valuetext')).to.be.equal('Time: 00:01');
expect(el.getAttribute('aria-valuenow')).to.be.equal(el.displayTime.toString());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { fixture, fixtureSync, expect, elementUpdated, oneEvent, nextFrame, aTim
// import element and theme
import { InteractiveChart } from '@refinitiv-ui/elements/interactive-chart';
import '@refinitiv-ui/elemental-theme/light/ef-interactive-chart.js';

let line = {
series: [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, fixture, nextFrame, oneEvent } from '@refinitiv-ui/test-helpers';
import { expect, fixture, nextFrame } from '@refinitiv-ui/test-helpers';
import { createSandbox, restore, spy } from 'sinon';

import { BackdropManager, clear, deregister, register, size } from '../../../../lib/overlay/managers/backdrop-manager.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, fixture, nextFrame } from '@refinitiv-ui/test-helpers';
import { expect, fixture } from '@refinitiv-ui/test-helpers';
import { createSandbox, restore, spy } from 'sinon';

import { openedUpdated } from './../mocks/helper';
Expand Down
14 changes: 14 additions & 0 deletions packages/test-helpers/__test__/test-helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,18 @@ describe('TestHelpersTest', () => {
});
});

describe('test ResizeObserver loop handler', function () {

it('Convert resize-observer errors to warnings', function () {
const message = 'ResizeObserver loop completed with undelivered notifications';
window.dispatchEvent(new ErrorEvent('error', {
message,
error: new Error(message)
}));

// the test should run until the end with a passed result
expect(message).to.equal(message);
});
});

});
2 changes: 1 addition & 1 deletion packages/test-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
"@types/mocha": "^5.2.7",
"mocha": "^6.2.3"
}
}
}
32 changes: 27 additions & 5 deletions packages/test-helpers/src/test-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ export const keyboardEvent = (type: string, init: KeyboardEventInit = {}): Keybo
cancelable: true,
composed: true
}) as CustomKeyboardEvent;
event.key = init.key || '';
event.shiftKey = init.shiftKey || false;
event.altKey = init.altKey || false;
event.ctrlKey = init.ctrlKey || false;
event.metaKey = init.metaKey || false;
event.key = init.key ?? '';
event.shiftKey = init.shiftKey ?? false;
event.altKey = init.altKey ?? false;
event.ctrlKey = init.ctrlKey ?? false;
event.metaKey = init.metaKey ?? false;

return event;
}
Expand Down Expand Up @@ -94,3 +94,25 @@ export const isNear = (a: number, b: number, distance: number, inclusive = true)
* @returns string
*/
export const replaceWhitespace = (text: string): string => text.replace(/\s/g, ' ');

// ResizeObserver loop error is considered benign as discussed in https://github.com/w3c/csswg-drafts/issues/5023
// This module converts the error into a warning instead
// Note that, mocha must be available in an imported context
before(function () {
const originalOnError = window.onerror;
window.onerror = function (event, ...args) {
// Firefox: `ResizeObserver loop completed with undelivered notifications.`
// Chrome: `ResizeObserver loop limit exceeded`
// Safari: `ResizeObserver loop completed with undelivered notifications`
// Each browser logs a slightly different messages yet they all start with `ResizeObserver loop`
/* istanbul ignore else */
if (typeof event === 'string' && event.startsWith('ResizeObserver loop')) {
// eslint-disable-next-line no-console
console.warn(`warning: ${event}`);
return true;
}
else {
return originalOnError ? originalOnError(event, ...args) as boolean : false;
}
};
});