Skip to content

Commit

Permalink
feat: add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsimao committed Oct 3, 2023
1 parent dcc2822 commit 53ada46
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 6 deletions.
63 changes: 61 additions & 2 deletions packages/components/src/Tabs/__tests__/Tabs.test.tsx
Original file line number Diff line number Diff line change
@@ -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 '..';

Expand Down Expand Up @@ -40,4 +41,62 @@ describe('Tabs', () => {
</Tabs>
);
});

it('should display default selected key', async () => {
render(
<Tabs defaultSelectedKey='2'>
<TabsItem key='1' title='Title 1'>
item 1
</TabsItem>
<TabsItem key='2' title='Title 2'>
item 2
</TabsItem>
</Tabs>
);

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<Key>('2');

return (
<Tabs selectedKey={state} onSelectionChange={setState}>
<TabsItem key='1' title='Title 1'>
item 1
</TabsItem>
<TabsItem key='2' title='Title 2'>
item 2
</TabsItem>
</Tabs>
);
};

render(<Component />);

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(
<Tabs disabledKeys={['1']}>
<TabsItem key='1' title='Title 1'>
item 1
</TabsItem>
<TabsItem key='2' title='Title 2'>
item 2
</TabsItem>
</Tabs>
);

expect(screen.getByRole('tab', { name: /title 1/i })).toHaveAttribute('aria-disabled', 'true');
});
});
8 changes: 4 additions & 4 deletions packages/components/src/Tooltip/__tests__/Tooltip.test.tsx
Original file line number Diff line number Diff line change
@@ -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(
<Tooltip isOpen label='tooltip'>
<Tooltip isOpen label='tooltip content'>
trigger
</Tooltip>
);
Expand All @@ -19,7 +19,7 @@ describe('Tooltip', () => {
const ref = createRef<HTMLDivElement>();

render(
<Tooltip ref={ref} isOpen label='tooltip'>
<Tooltip ref={ref} isOpen label='tooltip content'>
trigger
</Tooltip>
);
Expand All @@ -29,7 +29,7 @@ describe('Tooltip', () => {

it('should pass a11y', async () => {
await testA11y(
<Tooltip isOpen label='tooltip'>
<Tooltip isOpen label='tooltip content'>
trigger
</Tooltip>
);
Expand Down

0 comments on commit 53ada46

Please sign in to comment.