From 53ada46c96515a0d8664cc5f1efc39de96e6738f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rui=20Sim=C3=A3o?= Date: Tue, 3 Oct 2023 14:12:23 +0100 Subject: [PATCH] feat: add more tests --- .../src/Tabs/__tests__/Tabs.test.tsx | 63 ++++++++++++++++++- .../src/Tooltip/__tests__/Tooltip.test.tsx | 8 +-- 2 files changed, 65 insertions(+), 6 deletions(-) diff --git a/packages/components/src/Tabs/__tests__/Tabs.test.tsx b/packages/components/src/Tabs/__tests__/Tabs.test.tsx index c322949ae..e8455d604 100644 --- a/packages/components/src/Tabs/__tests__/Tabs.test.tsx +++ b/packages/components/src/Tabs/__tests__/Tabs.test.tsx @@ -1,6 +1,7 @@ -import { render } from '@testing-library/react'; -import { createRef } from 'react'; +import { render, screen, waitFor } from '@testing-library/react'; +import { Key, createRef, useState } from 'react'; import { testA11y } from '@interlay/test-utils'; +import userEvent from '@testing-library/user-event'; import { Tabs, TabsItem } from '..'; @@ -40,4 +41,62 @@ describe('Tabs', () => { ); }); + + it('should display default selected key', async () => { + render( + + + item 1 + + + item 2 + + + ); + + expect(screen.getByRole('tab', { name: /title 2/i })).toHaveAttribute('aria-selected', 'true'); + expect(screen.getByRole('tabpanel')).toHaveTextContent(/item 2$/i); + }); + + it('should be able to control open tab', async () => { + const Component = () => { + const [state, setState] = useState('2'); + + return ( + + + item 1 + + + item 2 + + + ); + }; + + render(); + + expect(screen.getByRole('tab', { name: /title 2/i })).toHaveAttribute('aria-selected', 'true'); + + userEvent.click(screen.getByRole('tab', { name: /title 1/i })); + + await waitFor(() => { + expect(screen.getByRole('tab', { name: /title 1/i })).toHaveAttribute('aria-selected', 'true'); + }); + }); + + it('should disabled tab', async () => { + render( + + + item 1 + + + item 2 + + + ); + + expect(screen.getByRole('tab', { name: /title 1/i })).toHaveAttribute('aria-disabled', 'true'); + }); }); diff --git a/packages/components/src/Tooltip/__tests__/Tooltip.test.tsx b/packages/components/src/Tooltip/__tests__/Tooltip.test.tsx index a5541eeb5..a723e330a 100644 --- a/packages/components/src/Tooltip/__tests__/Tooltip.test.tsx +++ b/packages/components/src/Tooltip/__tests__/Tooltip.test.tsx @@ -1,13 +1,13 @@ +import { testA11y } from '@interlay/test-utils'; import { render } from '@testing-library/react'; import { createRef } from 'react'; -import { testA11y } from '@interlay/test-utils'; import { Tooltip } from '..'; describe('Tooltip', () => { it('should render correctly', () => { const wrapper = render( - + trigger ); @@ -19,7 +19,7 @@ describe('Tooltip', () => { const ref = createRef(); render( - + trigger ); @@ -29,7 +29,7 @@ describe('Tooltip', () => { it('should pass a11y', async () => { await testA11y( - + trigger );