Skip to content

Commit 4bfbfd3

Browse files
committed
feat(tabs): add test code for tab actions
1 parent 6b6dc17 commit 4bfbfd3

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

packages/bezier-react/src/components/Tabs/Tabs.test.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const CONTENT1 = 'Content one'
2424
const CONTENT2 = 'Content two'
2525

2626
const ACTION1 = 'Action1'
27+
const ACTION2 = 'Action2'
2728

2829
type RenderTabsProps = {
2930
tabsProps?: TabsProps
@@ -54,6 +55,9 @@ describe('Tabs', () => {
5455
<TabAction href="https://github.com/channel-io/bezier-react">
5556
{ ACTION1 }
5657
</TabAction>
58+
<TabAction>
59+
{ ACTION2 }
60+
</TabAction>
5761
</TabActions>
5862
</TabList>
5963

@@ -196,6 +200,32 @@ describe('Tabs', () => {
196200
})
197201
})
198202

203+
describe('Tab Actions', () => {
204+
describe('ARIA', () => {
205+
it('should have \'role="toolbar"\' attribute.', () => {
206+
const { getByRole } = renderTabs()
207+
expect(getByRole('toolbar', { name: 'More actions' })).toBeInTheDocument()
208+
})
209+
})
210+
211+
describe('Keyboard Navigation', () => {
212+
it('can control by arrow right and left key', async () => {
213+
const { getByRole } = renderTabs()
214+
const tabItem1 = getByRole('link', { name: ACTION1 })
215+
const tabItem2 = getByRole('button', { name: ACTION2 })
216+
217+
await user.click(getByRole('link', { name: ACTION1 }))
218+
expect(document.activeElement).toBe(tabItem1)
219+
await user.keyboard('{arrowright}')
220+
expect(document.activeElement).toBe(tabItem2)
221+
await user.keyboard('{arrowleft}')
222+
expect(document.activeElement).toBe(tabItem1)
223+
await user.keyboard('{arrowleft}')
224+
expect(document.activeElement).toBe(tabItem2)
225+
})
226+
})
227+
})
228+
199229
describe('Tab Content', () => {
200230
describe('ARIA', () => {
201231
it('should have \'role="tabpanel"\' attribute.', () => {

0 commit comments

Comments
 (0)