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 all 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
9 changes: 5 additions & 4 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) {
await this.loadElementFromURL(url);
// https://github.com/puppeteer/puppeteer/issues/406#issuecomment-323555639
return await page.evaluate(() => new XMLSerializer().serializeToString(document));
async getSelectorHTML(url: string, tagName: string) {
await this.loadElementFromURL(url, '.echCanvasRenderer');
const xml = await page.evaluate(() => new XMLSerializer().serializeToString(document));
return new JSDOM(xml, { contentType: 'text/xml' }).window.document.getElementsByTagName(tagName);
}
}

Expand Down
45 changes: 0 additions & 45 deletions integration/tests/accessibility.test.ts

This file was deleted.

46 changes: 46 additions & 0 deletions src/components/accessibility/accessibility.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { mount } from 'enzyme';
import React from 'react';

import { BarSeries, LineSeries, Settings } from '../../specs';
import { Chart } from '../chart';

describe('Accessibility', () => {
it('should include the series types if one type of series', () => {
const wrapper = mount(
<Chart size={[100, 100]} id="chart1">
<Settings debug rendering="svg" showLegend />
<BarSeries id="test" data={[{ x: 0, y: 2 }]} />
</Chart>,
);
expect(wrapper.find('dd').first().text()).toBe('bar chart');
});
it('should include the series types if multiple types of series', () => {
const wrapper = mount(
<Chart size={[100, 100]} id="chart1">
<Settings debug rendering="svg" showLegend />
<BarSeries id="test" data={[{ x: 0, y: 2 }]} />
<LineSeries id="test2" data={[{ x: 3, y: 5 }]} />
</Chart>,
);
expect(wrapper.find('dd').first().text()).toBe('Mixed chart: bar and line chart');
});
});