From e1682a81257f09e8b2cabe20b7a4f94ce94793c1 Mon Sep 17 00:00:00 2001 From: Daniel Tschinder <231804+danez@users.noreply.github.com> Date: Sun, 17 Apr 2022 13:42:20 +0000 Subject: [PATCH] chore: Add test for tabindex --- src/components/__tests__/Tabs-test.js | 63 +++++++++++++++++++++------ 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/src/components/__tests__/Tabs-test.js b/src/components/__tests__/Tabs-test.js index 9d9e4767a8..eed73ee008 100644 --- a/src/components/__tests__/Tabs-test.js +++ b/src/components/__tests__/Tabs-test.js @@ -133,11 +133,46 @@ describe('', () => { }); describe('keyboard', () => { + test('should change focus on tab and tabindex set', async () => { + render( + + + + Tab1 + + + Tab2 + + + Tab3 + + + Hello Tab1 + Hello Tab2 + Hello Tab3 + , + ); + const element = screen.getByTestId('tab1'); + await userEvent.click(element); + + assertTabSelected(1); + + await userEvent.keyboard('[Tab]'); + await userEvent.keyboard('[Enter]'); + + assertTabSelected(2); + + await userEvent.keyboard('[Tab]'); + await userEvent.keyboard('[Space]'); + + assertTabSelected(3); + }); + test('should update selectedIndex when arrow right key pressed', async () => { render(createTabs()); const element = screen.getByTestId('tab1'); await userEvent.click(element); - await userEvent.type(element, '{ArrowRight}'); + await userEvent.type(element, '[ArrowRight]'); assertTabSelected(2); }); @@ -146,7 +181,7 @@ describe('', () => { render(createTabs()); const element = screen.getByTestId('tab3'); await userEvent.click(element); - await userEvent.type(element, '{ArrowRight}'); + await userEvent.type(element, '[ArrowRight]'); assertTabSelected(1); }); @@ -166,7 +201,7 @@ describe('', () => { ); const element = screen.getByTestId('tab1'); await userEvent.click(element); - await userEvent.keyboard('{ArrowRight}'); + await userEvent.keyboard('[ArrowRight]'); assertTabSelected(1); }); @@ -175,7 +210,7 @@ describe('', () => { render(createTabs()); const element = screen.getByTestId('tab1'); await userEvent.click(element); - await userEvent.keyboard('{ArrowLeft}'); + await userEvent.keyboard('[ArrowLeft]'); assertTabSelected(3); }); @@ -195,7 +230,7 @@ describe('', () => { ); const element = screen.getByTestId('tab2'); await userEvent.click(element); - await userEvent.keyboard('{ArrowLeft}'); + await userEvent.keyboard('[ArrowLeft]'); assertTabSelected(2); }); @@ -204,7 +239,7 @@ describe('', () => { render(createTabs()); const element = screen.getByTestId('tab3'); await userEvent.click(element); - await userEvent.type(element, '{Home}'); + await userEvent.type(element, '[Home]'); assertTabSelected(1); }); @@ -213,7 +248,7 @@ describe('', () => { render(createTabs()); const element = screen.getByTestId('tab1'); await userEvent.click(element); - await userEvent.type(element, '{End}'); + await userEvent.type(element, '[End]'); assertTabSelected(3); }); @@ -222,7 +257,7 @@ describe('', () => { render(createTabs({ direction: 'rtl' })); const element = screen.getByTestId('tab1'); await userEvent.click(element); - await userEvent.type(element, '{ArrowLeft}'); + await userEvent.type(element, '[ArrowLeft]'); assertTabSelected(2); }); @@ -231,7 +266,7 @@ describe('', () => { render(createTabs({ direction: 'rtl' })); const element = screen.getByTestId('tab2'); await userEvent.click(element); - await userEvent.type(element, '{ArrowRight}'); + await userEvent.type(element, '[ArrowRight]'); assertTabSelected(1); }); @@ -240,7 +275,7 @@ describe('', () => { render(createTabs()); const element = screen.getByTestId('tab4'); await userEvent.click(element); - await userEvent.type(element, '{ArrowLeft}'); + await userEvent.type(element, '[ArrowLeft]'); assertTabSelected(1); }); @@ -498,11 +533,11 @@ describe('', () => { expect(firstTab).toHaveFocus(); assertTabSelected(1); - await userEvent.type(firstTab, '{ArrowDown}'); + await userEvent.type(firstTab, '[ArrowDown]'); expect(secondTab).toHaveFocus(); assertTabSelected(2); - await userEvent.type(secondTab, '{ArrowUp}'); + await userEvent.type(secondTab, '[ArrowUp]'); expect(firstTab).toHaveFocus(); assertTabSelected(1); }); @@ -568,11 +603,11 @@ describe('', () => { expect(firstTab).toHaveFocus(); assertTabSelected(1); - await userEvent.type(firstTab, '{ArrowDown}'); + await userEvent.type(firstTab, '[ArrowDown]'); expect(firstTab).toHaveFocus(); assertTabSelected(1); - await userEvent.type(firstTab, '{ArrowUp}'); + await userEvent.type(firstTab, '[ArrowUp]'); expect(firstTab).toHaveFocus(); assertTabSelected(1); });