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(a11y): fix flaky accessibility integration tests #1137

Merged
merged 7 commits into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
7 changes: 4 additions & 3 deletions integration/page_objects/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import Url from 'url';

import { JSDOM } from 'jsdom';
import { AXNode } from 'puppeteer';

import { DRAG_DETECTION_TIMEOUT } from '../../src/state/reducers/interactions';
Expand Down Expand Up @@ -472,10 +473,10 @@ class CommonPage {
* Get HTML for element to test aria labels etc
*/
// eslint-disable-next-line class-methods-use-this
async getElementHTML(url: string) {
async getSelectorHTML(url: string, tagName: string) {
await this.loadElementFromURL(url, '.echCanvasRenderer');
// https://github.com/puppeteer/puppeteer/issues/406#issuecomment-323555639
return await page.evaluate(() => new XMLSerializer().serializeToString(document));
const xml = await page.evaluate(() => new XMLSerializer().serializeToString(document));
return new JSDOM(xml, { contentType: 'text/xml' }).window.document.getElementsByTagName(tagName);
}
}

Expand Down
14 changes: 8 additions & 6 deletions integration/tests/accessibility.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ import { common } from '../page_objects/common';

describe('Accessibility', () => {
it('should include the series types if one type of series', async () => {
const html = await common.getElementHTML(
const html = await common.getSelectorHTML(
'http://localhost:9001/iframe.html?id=annotations-lines--x-continuous-domain',
'dd',
);
const startIndex = html.indexOf('<dd>');
expect(html.slice(startIndex, startIndex + 13)).toBe('<dd>bar chart');
expect(html[0].innerHTML).toBe('bar chart');
});
it('should include the series types if multiple types of series', async () => {
const html = await common.getElementHTML('http://localhost:9001/iframe.html?id=mixed-charts--bars-and-lines');
const startIndex = html.indexOf('<dd>');
expect(html.slice(startIndex, startIndex + 30)).toBe('<dd>Mixed chart: bar and line ');
const html = await common.getSelectorHTML(
'http://localhost:9001/iframe.html?id=mixed-charts--bars-and-lines',
'dd',
);
expect(html[0].innerHTML).toBe('Mixed chart: bar and line chart');
});
});
nickofthyme marked this conversation as resolved.
Show resolved Hide resolved