Skip to content

Commit 12a01f5

Browse files
Add test to Tabs component
1 parent 1a47606 commit 12a01f5

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1414

1515
### Added
1616

17-
- Warning icon when input has errorMessaxge
17+
- Warning icon when input has errorMessage
1818
- Size prop to checkbox.
19+
- Tests for `Tabs` component
1920

2021
### Changed
2122

react/components/Tabs/index.test.tsx

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import React from 'react'
2+
import { render } from '@testing-library/react'
3+
import { toHaveClass, toHaveAttribute, toHaveTextContent } 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, toHaveAttribute, toHaveTextContent })
10+
const tabsId = 'tabs'
11+
const tab1Id = 'tab 1'
12+
13+
describe('CSS API', () => {
14+
15+
it('props: default', () => {
16+
const { getByTestId } = render(
17+
<Tabs testId={tabsId}>
18+
<Tab testId={tab1Id} label="label 1" active>
19+
Tab 1
20+
</Tab>
21+
<Tab label="label 2" />
22+
</Tabs>
23+
)
24+
25+
const tabs = getByTestId(tabsId)
26+
expect(tabs).not.toHaveClass('overflow-y-hidden')
27+
28+
const tabsContent = tabs.querySelector('.overflow-y-auto')
29+
expect(tabsContent).toBeNull()
30+
expect(tabsContent).toBeDefined()
31+
32+
expect(getByTestId(tab1Id)).not.toHaveClass('w-100')
33+
})
34+
35+
it('prop: sticky', () => {
36+
const { getByTestId } = render(
37+
<Tabs testId={tabsId} sticky>
38+
<Tab label="label 1" active>
39+
Tab 1
40+
</Tab>
41+
<Tab label="label 2" />
42+
</Tabs>
43+
)
44+
45+
const tabs = getByTestId(tabsId)
46+
expect(tabs).toHaveClass('overflow-y-hidden')
47+
48+
const tabsContent = tabs.querySelector('.overflow-y-auto')
49+
expect(tabsContent).not.toBeNull()
50+
expect(tabsContent).toBeDefined()
51+
})
52+
53+
it('prop: fullWidth', () => {
54+
const { getByTestId } = render(
55+
<Tabs testId={tabsId} fullWidth>
56+
<Tab testId={tab1Id} label="label 1" active>
57+
Tab 1
58+
</Tab>
59+
<Tab label="label 2">Tab 2</Tab>
60+
<Tab label="label 3">Tab 3</Tab>
61+
</Tabs>
62+
)
63+
64+
expect(getByTestId(tabsId)).toHaveClass('w-100')
65+
expect(getByTestId(tab1Id)).toHaveClass('w-100')
66+
})
67+
})
68+
69+
describe('Behavior', () => {
70+
it('active tab content', () => {
71+
const { getByTestId } = render(
72+
<Tabs testId={tabsId}>
73+
<Tab label="label 1" active>
74+
Tab 1
75+
</Tab>
76+
<Tab label="label 2">Tab 2</Tab>
77+
</Tabs>
78+
)
79+
80+
expect(getByTestId(tabsId)).toHaveTextContent('Tab 1')
81+
})
82+
})
83+
})

0 commit comments

Comments
 (0)