-
Notifications
You must be signed in to change notification settings - Fork 844
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/datagrid/5310
- Loading branch information
Showing
23 changed files
with
722 additions
and
93 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,33 @@ | ||
import { mount as cypressMount } from '@cypress/react'; | ||
import { React, Fragment } from 'react'; | ||
import { EuiProvider } from '../../src'; | ||
|
||
// Provide global cy.mount() shortcut that includes required providers | ||
// @see https://github.com/cypress-io/cypress/blob/develop/npm/react/docs/providers-and-composition.md | ||
Cypress.Commands.add('mount', (children) => { | ||
return cypressMount(<EuiProvider>{children}</EuiProvider>); | ||
}); | ||
|
||
// This ensures the correct testing window has focus when using Cypress Real Events. | ||
// @see https://github.com/dmtrKovalenko/cypress-real-events/issues/196 | ||
Cypress.Commands.add('realMount', (children) => { | ||
cy.mount( | ||
<Fragment> | ||
<div | ||
data-test-subj="cypress-real-event-target" | ||
style={{ height: '1px', width: '1px' }} | ||
/> | ||
{children} | ||
</Fragment> | ||
).then(() => { | ||
cy.get('[data-test-subj="cypress-real-event-target"]').realClick({ | ||
position: 'topLeft', | ||
}); | ||
}); | ||
}); | ||
|
||
Cypress.Commands.add('repeatRealPress', (keyToPress, count = 2) => { | ||
for (let i = 0; i < count; i++) { | ||
cy.realPress(keyToPress); | ||
} | ||
}); |
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
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. | ||
*/ | ||
|
||
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('Keyboard and screen reader accessibility', () => { | ||
it('renders with required props', () => { | ||
cy.realMount( | ||
<EuiAccordion {...baseProps}> | ||
<EuiPanel color="subdued"> | ||
Any content inside of <strong>EuiAccordion</strong> will appear | ||
here. | ||
</EuiPanel> | ||
</EuiAccordion> | ||
); | ||
cy.realPress('Tab'); | ||
cy.focused().contains('Click me to toggle'); | ||
}); | ||
|
||
it('opens and closes on ENTER keypress', () => { | ||
cy.realMount( | ||
<EuiAccordion {...baseProps}> | ||
<EuiPanel color="subdued"> | ||
Any content inside of <strong>EuiAccordion</strong> will appear | ||
here. | ||
</EuiPanel> | ||
</EuiAccordion> | ||
); | ||
cy.realPress('Tab'); | ||
cy.focused().contains('Click me to toggle').realPress('Enter'); | ||
cy.realPress(['Shift', 'Tab']); | ||
cy.focused().invoke('attr', 'aria-expanded').should('equal', 'true'); | ||
cy.realPress('Enter'); | ||
cy.focused().invoke('attr', 'aria-expanded').should('equal', 'false'); | ||
}); | ||
|
||
it('opens and closes on SPACE keypress', () => { | ||
cy.realMount( | ||
<EuiAccordion {...baseProps}> | ||
<EuiPanel color="subdued"> | ||
Any content inside of <strong>EuiAccordion</strong> will appear | ||
here. | ||
</EuiPanel> | ||
</EuiAccordion> | ||
); | ||
cy.realPress('Tab'); | ||
cy.focused().contains('Click me to toggle').realPress('Space'); | ||
cy.realPress(['Shift', 'Tab']); | ||
cy.focused().invoke('attr', 'aria-expanded').should('equal', 'true'); | ||
cy.realPress('Space'); | ||
cy.focused().invoke('attr', 'aria-expanded').should('equal', 'false'); | ||
}); | ||
}); | ||
|
||
describe('Props and keyboard navigation', () => { | ||
it('should not have an arrow', () => { | ||
cy.realMount( | ||
<EuiAccordion {...noArrowProps}> | ||
<EuiPanel color="subdued"> | ||
Any content inside of <strong>EuiAccordion</strong> will appear | ||
here. | ||
</EuiPanel> | ||
</EuiAccordion> | ||
); | ||
cy.get('.euiAccordion__iconButton').should('not.exist'); | ||
}); | ||
|
||
it('manages focus when panel is opened', () => { | ||
cy.realMount( | ||
<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.realPress('Tab'); | ||
cy.focused().contains('Click me to toggle').realPress('Enter'); | ||
cy.focused().invoke('attr', 'tabindex').should('equal', '-1'); | ||
cy.focused().contains('Any content inside of EuiAccordion'); | ||
cy.realPress('Tab'); | ||
cy.focused().contains('a link'); | ||
}); | ||
|
||
it('manages focus when forceState is open', () => { | ||
cy.realMount( | ||
<EuiAccordion {...noArrowProps} forceState="open"> | ||
<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.realPress('Tab'); | ||
cy.focused().contains('Click me to toggle'); | ||
cy.focused().invoke('attr', 'aria-expanded').should('equal', 'true'); | ||
cy.focused().invoke('attr', 'tabindex').should('not.exist'); | ||
cy.realPress('Tab'); | ||
cy.focused().contains('a link'); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.