|
| 1 | +import React from 'react' |
| 2 | +import { render } from '@testing-library/react' |
| 3 | +import { toHaveClass } from '@testing-library/jest-dom/matchers' |
| 4 | + |
| 5 | +import Tabs from '.' |
| 6 | +import Tab from './Tab.js' |
| 7 | + |
| 8 | +describe('Tabs', () => { |
| 9 | + expect.extend({ toHaveClass }) |
| 10 | + const tabsId = 'tabs' |
| 11 | + |
| 12 | + describe('CSS API', () => { |
| 13 | + it('props: default', () => { |
| 14 | + const { getByTestId, getByText } = render( |
| 15 | + <Tabs testId={tabsId}> |
| 16 | + <Tab label="label 1" active> |
| 17 | + Tab 1 |
| 18 | + </Tab> |
| 19 | + <Tab label="label 2" /> |
| 20 | + </Tabs> |
| 21 | + ) |
| 22 | + |
| 23 | + const tabs = getByTestId(tabsId) |
| 24 | + expect(tabs).not.toHaveClass('overflow-y-hidden') |
| 25 | + |
| 26 | + const tabsContent = getByText('Tab 1') |
| 27 | + expect(tabsContent).toBeTruthy() |
| 28 | + expect(tabsContent).not.toHaveClass('overflow-y-auto') |
| 29 | + |
| 30 | + expect(getByText('label 1')).not.toHaveClass('w-100') |
| 31 | + }) |
| 32 | + |
| 33 | + it('prop: sticky', () => { |
| 34 | + const { getByTestId, getByText } = render( |
| 35 | + <Tabs testId={tabsId} sticky> |
| 36 | + <Tab label="label 1" active> |
| 37 | + Tab 1 |
| 38 | + </Tab> |
| 39 | + <Tab label="label 2" /> |
| 40 | + </Tabs> |
| 41 | + ) |
| 42 | + |
| 43 | + expect(getByTestId(tabsId)).toHaveClass('overflow-y-hidden') |
| 44 | + expect(getByText('Tab 1')).toHaveClass('overflow-y-auto') |
| 45 | + }) |
| 46 | + |
| 47 | + it('prop: fullWidth', () => { |
| 48 | + const { getByText } = render( |
| 49 | + <Tabs testId={tabsId} fullWidth> |
| 50 | + <Tab label="label 1" active> |
| 51 | + Tab 1 |
| 52 | + </Tab> |
| 53 | + <Tab label="label 2">Tab 2</Tab> |
| 54 | + <Tab label="label 3">Tab 3</Tab> |
| 55 | + </Tabs> |
| 56 | + ) |
| 57 | + |
| 58 | + expect(getByText('label 1')).toHaveClass('w-100') |
| 59 | + expect(getByText('label 2')).toHaveClass('w-100') |
| 60 | + expect(getByText('label 3')).toHaveClass('w-100') |
| 61 | + }) |
| 62 | + }) |
| 63 | + |
| 64 | + describe('Behavior', () => { |
| 65 | + it('active tab content', () => { |
| 66 | + const { getByText } = render( |
| 67 | + <Tabs testId={tabsId}> |
| 68 | + <Tab label="label 1" active> |
| 69 | + Tab 1 |
| 70 | + </Tab> |
| 71 | + <Tab label="label 2">Tab 2</Tab> |
| 72 | + </Tabs> |
| 73 | + ) |
| 74 | + |
| 75 | + expect(getByText('Tab 1')).toBeTruthy() |
| 76 | + }) |
| 77 | + }) |
| 78 | +}) |
0 commit comments