Skip to content

Commit abddc1f

Browse files
igorbrasileiroemersonlaurentino
authored andcommitted
Add test to Tabs component
1 parent b93bc9c commit abddc1f

File tree

3 files changed

+81
-5
lines changed

3 files changed

+81
-5
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/Tab.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Tab extends Component {
77
}
88

99
render() {
10-
const { active, fullWidth, label, disabled, testId } = this.props
10+
const { active, fullWidth, label, disabled } = this.props
1111

1212
let tabStyle =
1313
'c-muted-1 b--transparent hover-c-action-primary pointer vtex-tab__button--inactive'
@@ -22,7 +22,6 @@ class Tab extends Component {
2222

2323
return (
2424
<button
25-
data-testid={testId}
2625
type="button"
2726
onClick={this.handleClick}
2827
className={`vtex-tab__button bt-0 bl-0 br-0 bw1 ${
@@ -42,8 +41,6 @@ Tab.defaultProps = {
4241
}
4342

4443
Tab.propTypes = {
45-
/** Data attribute */
46-
testId: PropTypes.string,
4744
active: PropTypes.bool,
4845
fullWidth: PropTypes.bool,
4946
children: PropTypes.node,

react/components/Tabs/index.test.tsx

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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

Comments
 (0)