Skip to content

Commit

Permalink
test(a11y): fix flaky accessibility integration tests (#1137)
Browse files Browse the repository at this point in the history
  • Loading branch information
rshen91 authored Apr 27, 2021
1 parent eb11480 commit b4943e9
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 49 deletions.
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');
});
});

0 comments on commit b4943e9

Please sign in to comment.