Skip to content

Commit 5ff2e60

Browse files
committed
simplify tests and add comment block with explanation
1 parent fba7170 commit 5ff2e60

1 file changed

Lines changed: 8 additions & 55 deletions

File tree

src/components/accordion/accordion.spec.tsx

Lines changed: 8 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/// <reference types="cypress-real-events" />
1111
/// <reference types="../../../cypress/support" />
1212

13-
import React, { useState } from 'react';
13+
import React from 'react';
1414
import { EuiAccordion, EuiAccordionProps } from './index';
1515

1616
const sharedProps: EuiAccordionProps = {
@@ -53,59 +53,12 @@ describe('EuiAccordion', () => {
5353
});
5454
});
5555

56-
describe('focus management', () => {
57-
it('maintains focus when the button is clicked', () => {
58-
cy.realMount(<EuiAccordion {...sharedProps} />);
59-
cy.get('.euiAccordion__button').realClick();
60-
cy.focused().should('have.class', 'euiAccordion__button');
61-
});
62-
63-
it('maintains focus when the button is pressed', () => {
64-
cy.realMount(<EuiAccordion {...sharedProps} />);
65-
cy.realPress('Tab');
66-
cy.focused().should('have.class', 'euiAccordion__button');
67-
cy.focused().contains('Click me to toggle').realPress('Enter');
68-
cy.focused().should('have.class', 'euiAccordion__button');
69-
});
70-
71-
describe('forceState', () => {
72-
it('does not focus the accordion when `forceState` prevents the accordion from opening', () => {
73-
cy.realMount(<EuiAccordion {...sharedProps} forceState="closed" />);
74-
75-
cy.contains('Click me to toggle').realClick();
76-
// cy.focused() is flaky here and doesn't always return an element, so use document.activeElement instead
77-
cy.then(() => {
78-
expect(document.activeElement).not.to.have.class(
79-
'euiAccordion__childWrapper'
80-
);
81-
});
82-
});
83-
84-
it('does not focus the accordion when programmatically toggled from outside the accordion', () => {
85-
const ControlledComponent = () => {
86-
const [accordionOpen, setAccordionOpen] = useState(false);
87-
return (
88-
<>
89-
<button
90-
data-test-subj="toggleForceState"
91-
onClick={() => setAccordionOpen(!accordionOpen)}
92-
>
93-
Control accordion
94-
</button>
95-
<EuiAccordion
96-
{...sharedProps}
97-
forceState={accordionOpen ? 'open' : 'closed'}
98-
/>
99-
</>
100-
);
101-
};
102-
cy.realMount(<ControlledComponent />);
103-
104-
cy.get('[data-test-subj="toggleForceState"]').realClick();
105-
cy.focused()
106-
.should('not.have.class', 'euiAccordion__childWrapper')
107-
.should('have.attr', 'data-test-subj', 'toggleForceState');
108-
});
109-
});
56+
// Note: we used to move focus automatically to the accordion contents on open/
57+
// toggle button click, but we no longer do so after receiving a11y audit feedback
58+
// that the change of context was confusing/not helpful
59+
it('maintains focus on the toggle button when opened', () => {
60+
cy.realMount(<EuiAccordion {...sharedProps} />);
61+
cy.get('.euiAccordion__button').realClick();
62+
cy.focused().should('have.class', 'euiAccordion__button');
11063
});
11164
});

0 commit comments

Comments
 (0)