Skip to content

Commit

Permalink
colocate tab tests and files
Browse files Browse the repository at this point in the history
  • Loading branch information
Barsnes committed Jun 11, 2024
1 parent bc2232d commit 75bc37f
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { HTMLAttributes } from 'react';
import { forwardRef } from 'react';
import cl from 'clsx/lite';

import { RovingTabindexItem } from '../../../utilities/RovingTabIndex';
import { RovingTabindexItem } from '../../utilities/RovingTabIndex';

import { useTabItem } from './useTab';

Expand Down
27 changes: 0 additions & 27 deletions packages/react/src/components/Tabs/Tab/Tab.test.tsx

This file was deleted.

1 change: 0 additions & 1 deletion packages/react/src/components/Tabs/Tab/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import type { HTMLAttributes } from 'react';
import { forwardRef, useContext } from 'react';
import cl from 'clsx/lite';

import { TabsContext } from '../Tabs';
import { Paragraph } from '../../Typography';
import { Paragraph } from '../Typography';

import { TabsContext } from './Tabs';

export type TabContentProps = {
/** When this value is selected as the current state, render this `TabContent` component*/
Expand Down
20 changes: 0 additions & 20 deletions packages/react/src/components/Tabs/TabContent/TabContent.test.tsx

This file was deleted.

1 change: 0 additions & 1 deletion packages/react/src/components/Tabs/TabContent/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { HTMLAttributes } from 'react';
import { forwardRef } from 'react';
import cl from 'clsx/lite';

import { RovingTabindexRoot } from '../../../utilities/RovingTabIndex';
import { RovingTabindexRoot } from '../../utilities/RovingTabIndex';

export const TabList = forwardRef<
HTMLDivElement,
Expand Down
28 changes: 0 additions & 28 deletions packages/react/src/components/Tabs/TabList/TabList.test.tsx

This file was deleted.

1 change: 0 additions & 1 deletion packages/react/src/components/Tabs/TabList/index.ts

This file was deleted.

47 changes: 47 additions & 0 deletions packages/react/src/components/Tabs/Tabs.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,51 @@ describe('Tabs', () => {
expect(screen.queryByText('content 2')).toBeVisible();
expect(screen.queryByText('content 1')).not.toBeInTheDocument();
});

test('item renders with correct aria attributes', async () => {
render(
<Tabs defaultValue='value1'>
<Tabs.List>
<Tabs.Tab value='value1'>Tab 1</Tabs.Tab>
<Tabs.Tab value='value2'>Tab 2</Tabs.Tab>
</Tabs.List>
</Tabs>,
);

const tab = screen.getByRole('tab', { name: 'Tab 2' });
expect(tab).toHaveAttribute('aria-selected', 'false');
await user.click(tab);
expect(tab).toHaveAttribute('aria-selected', 'true');
});

test('renders ReactNodes as children when TabContents value is selected', () => {
render(
<Tabs defaultValue='value1'>
<Tabs.Content value='value1'>
<div>content 1</div>
</Tabs.Content>
</Tabs>,
);

const content = screen.queryByText('content 1');
expect(content).toBeInTheDocument();
});

test('can navigate tabs with keyboard', async () => {
render(
<Tabs.List>
<Tabs.Tab value='value1'>Tab 1</Tabs.Tab>
<Tabs.Tab value='value2'>Tab 2</Tabs.Tab>
</Tabs.List>,
);

const tab1 = screen.getByRole('tab', { name: 'Tab 1' });
const tab2 = screen.getByRole('tab', { name: 'Tab 2' });
await user.tab();
expect(tab1).toHaveFocus();
await user.type(tab1, '{arrowright}');
expect(tab2).toHaveFocus();
await user.type(tab2, '{arrowleft}');
expect(tab1).toHaveFocus();
});
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { HTMLAttributes } from 'react';
import { useContext, useId } from 'react';

import { TabsContext } from '../Tabs';
import { TabsContext } from './Tabs';

import type { TabProps } from './Tab';
import type { TabProps } from '.';

type UseTab = (
props: TabProps,
Expand Down

0 comments on commit 75bc37f

Please sign in to comment.