Skip to content

Commit

Permalink
Updated Cypress functional test.
Browse files Browse the repository at this point in the history
  • Loading branch information
1Copenut committed Apr 17, 2024
1 parent 03b4edb commit 2a16967
Showing 1 changed file with 6 additions and 29 deletions.
35 changes: 6 additions & 29 deletions src/components/accordion/accordion.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,31 +47,25 @@ describe('EuiAccordion', () => {
cy.realMount(<EuiAccordion {...sharedProps} />);
cy.realPress('Tab');
cy.realPress('Enter');
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('focus management', () => {
const expectChildrenIsFocused = () => {
cy.focused()
.should('have.class', 'euiAccordion__childWrapper')
.should('have.attr', 'tabindex', '-1');
};

it('focuses the accordion content when the arrow is clicked', () => {
it('maintains focus when the button is clicked', () => {
cy.realMount(<EuiAccordion {...sharedProps} />);
cy.get('.euiAccordion__arrow').realClick();
expectChildrenIsFocused();
cy.get('.euiAccordion__button').realClick();
cy.focused().should('have.class', 'euiAccordion__button');
});

it('focuses the accordion content when the button is clicked', () => {
it('maintains focus when the button is pressed', () => {
cy.realMount(<EuiAccordion {...sharedProps} />);
cy.realPress('Tab');
cy.focused().should('have.class', 'euiAccordion__button');
cy.focused().contains('Click me to toggle').realPress('Enter');
expectChildrenIsFocused();
cy.focused().should('have.class', 'euiAccordion__button');
});

describe('forceState', () => {
Expand Down Expand Up @@ -112,23 +106,6 @@ describe('EuiAccordion', () => {
.should('not.have.class', 'euiAccordion__childWrapper')
.should('have.attr', 'data-test-subj', 'toggleForceState');
});

it('attempts to focus the accordion children when `onToggle` controls `forceState`', () => {
const ControlledComponent = () => {
const [accordionOpen, setAccordionOpen] = useState(false);
return (
<EuiAccordion
{...sharedProps}
onToggle={(open) => setAccordionOpen(open)}
forceState={accordionOpen ? 'open' : 'closed'}
/>
);
};
cy.realMount(<ControlledComponent />);

cy.contains('Click me to toggle').realClick();
expectChildrenIsFocused();
});
});
});
});

0 comments on commit 2a16967

Please sign in to comment.