Skip to content

Commit

Permalink
chore(tabs): test skipping disabled tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
weronikaolejniczak committed Nov 21, 2024
1 parent 62f2781 commit 4cc2dbd
Showing 1 changed file with 50 additions and 13 deletions.
63 changes: 50 additions & 13 deletions packages/eui/src/components/tabs/tabs.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,34 @@ const tabs = [

const tabsSecond = [
{
id: 'hello',
name: 'New tab 1',
content: <p>Hello</p>,
id: 'apple',
name: 'Apple',
content: <p>Apple</p>,
},
{
id: 'world',
name: 'New tab 2',
content: <p>World</p>,
id: 'banana',
name: 'Banana',
content: <p>Banana</p>,
},
{
id: 'pear',
name: 'Pear',
content: <p>Pear</p>,
disabled: true,
},
];

const TabbedContent = () => {
const tabProps: EuiTabbedContentProps = {
tabs: tabs,
initialSelectedTab: tabs[1],
autoFocus: 'selected',
onTabClick: () => {},
};

return <EuiTabbedContent {...tabProps} />;
};

const DynamicTabbedContent = () => {
const [items, setItems] = useState(tabs);

Expand All @@ -110,10 +127,10 @@ const DynamicTabbedContent = () => {
);
};

const TabbedContent = () => {
const TabbedContentWithDisabledTabs = () => {
const tabProps: EuiTabbedContentProps = {
tabs: tabs,
initialSelectedTab: tabs[1],
tabs: tabsSecond,
initialSelectedTab: tabsSecond[0],
autoFocus: 'selected',
onTabClick: () => {},
};
Expand Down Expand Up @@ -173,16 +190,36 @@ describe('EuiTabs', () => {
// assert that the focus was reset
cy.realPress('Tab');
cy.realPress('ArrowRight');
cy.focused().should('have.text', 'New tab 2');
cy.focused().should('have.text', 'Banana');
// press ArrowRight to navigate to the first tab and assert it is focused
cy.realPress('ArrowRight');
cy.focused().should('have.text', 'New tab 1');
cy.focused().should('have.text', 'Apple');
// press ArrowRight to navigate back to the second tab and assert it is focused
cy.realPress('ArrowRight');
cy.focused().should('have.text', 'New tab 2');
cy.focused().should('have.text', 'Banana');
// press ArrowLeft to navigate back to the first tab and verify it is focused
cy.realPress('ArrowLeft');
cy.focused().should('have.text', 'New tab 1');
cy.focused().should('have.text', 'Apple');
});

it('should skip disabled tabs', () => {
cy.mount(<TabbedContentWithDisabledTabs />);

// focus the first tab and assert it is focused
cy.realPress('Tab');
cy.focused().should('have.text', 'Apple');

// press ArrowRight to navigate to the second tab and assert it is focused
cy.realPress('ArrowRight');
cy.focused().should('have.text', 'Banana');

// press ArrowRight to navigate to the first tab because the third tab is disabled
cy.realPress('ArrowRight');
cy.focused().should('have.text', 'Apple');

// press ArrowLeft to navigate back to the second tab, skipping the third tab and assert it is focused
cy.realPress('ArrowLeft');
cy.focused().should('have.text', 'Banana');
});
});
});

0 comments on commit 4cc2dbd

Please sign in to comment.