forked from elastic/eui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Splitting Cypress tests for component function and axe (a11y) checks (e…
…lastic#6331) * First commit for splitting Cypress tests. * Renaming config variables and a11y test type. * Refactoring to simpler commands, one config file. * Factoring out a11y tests for two more components. * Adding a comment to specPattern for future selves. * Updating Cypress wiki doc for new functionality.
- Loading branch information
Showing
12 changed files
with
238 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
/// <reference types="../../../cypress/support"/> | ||
|
||
import React from 'react'; | ||
import { EuiAccordion, EuiAccordionProps } from './index'; | ||
import { EuiPanel } from '../../components/panel'; | ||
import { htmlIdGenerator } from '../../services'; | ||
|
||
const baseProps: EuiAccordionProps = { | ||
buttonContent: 'Click me to toggle', | ||
id: htmlIdGenerator()(), | ||
initialIsOpen: false, | ||
}; | ||
|
||
const noArrow = { arrowDisplay: 'none' }; | ||
const noArrowProps: EuiAccordionProps = Object.assign(baseProps, noArrow); | ||
|
||
describe('EuiAccordion', () => { | ||
describe('Automated accessibility check', () => { | ||
it('has zero violations when expanded', () => { | ||
cy.mount( | ||
<EuiAccordion {...noArrowProps}> | ||
<EuiPanel color="subdued"> | ||
Any content inside of <strong>EuiAccordion</strong> will appear | ||
here. We will include <a href="#">a link</a> to confirm focus. | ||
</EuiPanel> | ||
</EuiAccordion> | ||
); | ||
cy.get('button.euiAccordion__button').click(); | ||
cy.checkAxe(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
/// <reference types="../../../cypress/support"/> | ||
|
||
import React from 'react'; | ||
|
||
import { EuiContextMenuItem } from './context_menu_item'; | ||
import { EuiContextMenuPanel } from './context_menu_panel'; | ||
|
||
const items = [ | ||
<EuiContextMenuItem key="A" data-test-subj="itemA"> | ||
Option A | ||
</EuiContextMenuItem>, | ||
<EuiContextMenuItem key="B" data-test-subj="itemB"> | ||
Option B | ||
</EuiContextMenuItem>, | ||
<EuiContextMenuItem key="C" data-test-subj="itemC"> | ||
Option C | ||
</EuiContextMenuItem>, | ||
]; | ||
|
||
describe('EuiContextMenuPanel', () => { | ||
describe('Automated accessibility check', () => { | ||
it('has zero violations', () => { | ||
const showNextPanelHandler = cy.stub(); | ||
cy.mount( | ||
<EuiContextMenuPanel | ||
items={items} | ||
showNextPanel={showNextPanelHandler} | ||
/> | ||
); | ||
cy.checkAxe(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
/// <reference types="../../../cypress/support"/> | ||
|
||
import React, { useState } from 'react'; | ||
|
||
import { EuiButton } from '../button'; | ||
import { EuiPopover } from '../popover'; | ||
import { EuiSelectable, EuiSelectableProps } from './selectable'; | ||
|
||
const options: EuiSelectableProps['options'] = [ | ||
{ | ||
label: 'Titan', | ||
'data-test-subj': 'titanOption', | ||
}, | ||
{ | ||
label: 'Enceladus', | ||
}, | ||
{ | ||
label: | ||
"Pandora is one of Saturn's moons, named for a Titaness of Greek mythology", | ||
}, | ||
]; | ||
|
||
const EuiSelectableListboxOnly = (args) => { | ||
return ( | ||
<EuiSelectable options={options} {...args}> | ||
{(list) => <>{list}</>} | ||
</EuiSelectable> | ||
); | ||
}; | ||
|
||
const EuiSelectableWithSearchInput = (args) => { | ||
return ( | ||
<EuiSelectable searchable options={options} {...args}> | ||
{(list, search) => ( | ||
<> | ||
{search} | ||
{list} | ||
</> | ||
)} | ||
</EuiSelectable> | ||
); | ||
}; | ||
|
||
describe('EuiSelectable', () => { | ||
describe('with a `searchable` configuration', () => { | ||
it('has no accessibility errors', () => { | ||
const onChange = cy.stub(); | ||
cy.realMount(<EuiSelectableWithSearchInput onChange={onChange} />); | ||
cy.checkAxe(); | ||
}); | ||
}); | ||
|
||
describe('without a `searchable` configuration', () => { | ||
it('has no accessibility errors', () => { | ||
const onChange = cy.stub(); | ||
cy.realMount( | ||
<EuiSelectableListboxOnly | ||
aria-label="No search box" | ||
onChange={onChange} | ||
/> | ||
); | ||
cy.checkAxe(); | ||
}); | ||
}); | ||
|
||
describe('nested in `EuiPopover` component', () => { | ||
const EuiSelectableNested = () => { | ||
const [isPopoverOpen, setIsPopoverOpen] = useState(false); | ||
|
||
const onChange = () => {}; | ||
const onClosePopover = () => {}; | ||
const onButtonClick = () => { | ||
setIsPopoverOpen(!isPopoverOpen); | ||
}; | ||
|
||
const button = ( | ||
<EuiButton | ||
iconType="arrowDown" | ||
iconSide="right" | ||
onClick={onButtonClick} | ||
> | ||
Show popover | ||
</EuiButton> | ||
); | ||
|
||
return ( | ||
<EuiPopover | ||
id="data-cy-popover-1" | ||
panelPaddingSize="s" | ||
button={button} | ||
isOpen={isPopoverOpen} | ||
closePopover={onClosePopover} | ||
> | ||
<EuiSelectableWithSearchInput | ||
aria-label="With popover" | ||
options={options} | ||
onChange={onChange} | ||
> | ||
{(list) => <>{list}</>} | ||
</EuiSelectableWithSearchInput> | ||
</EuiPopover> | ||
); | ||
}; | ||
|
||
it('has no accessibility errors', () => { | ||
cy.realMount(<EuiSelectableNested />); | ||
cy.get('button').realClick(); | ||
cy.get('li[role=option]').first(); // Make sure the EuiSelectable is rendered before a11y check | ||
cy.checkAxe(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.