-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(Foldable): test for Foldable added (#685)
- Loading branch information
Showing
2 changed files
with
73 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React from 'react'; | ||
|
||
import {render, screen} from '@testing-library/react'; | ||
|
||
import {testCustomClassName} from '../../../../test-utils/shared/common'; | ||
import {getQaAttrubutes} from '../../../utils'; | ||
import Foldable, {FoldableProps} from '../Foldable'; | ||
|
||
const foldableProps: FoldableProps = { | ||
isOpened: false, | ||
qa: 'foldable-component', | ||
}; | ||
|
||
const IS_OPEN_CLASS_NAME = 'pc-foldable-block_open'; | ||
|
||
const qaAttributes = getQaAttrubutes(foldableProps.qa); | ||
|
||
const FoldableComponent = (props: FoldableProps) => ( | ||
<Foldable {...props}> | ||
<div>Children</div> | ||
</Foldable> | ||
); | ||
|
||
describe('Foldable', () => { | ||
test('render Foldable by default', async () => { | ||
render(<FoldableComponent {...foldableProps} />); | ||
const foldable = screen.getByTestId(qaAttributes.default); | ||
const children = screen.getByText('Children'); | ||
|
||
expect(foldable).toBeInTheDocument(); | ||
expect(foldable).toBeVisible(); | ||
expect(foldable).not.toBeDisabled(); | ||
expect(foldable).not.toHaveClass(IS_OPEN_CLASS_NAME); | ||
|
||
expect(children).toBeInTheDocument(); | ||
}); | ||
|
||
test('render Foldable with isOpened = false', async () => { | ||
render(<FoldableComponent {...foldableProps} />); | ||
const foldable = screen.getByTestId(qaAttributes.default); | ||
|
||
expect(foldable).not.toHaveClass(IS_OPEN_CLASS_NAME); | ||
}); | ||
|
||
test('render Foldable with isOpened = true', async () => { | ||
render(<FoldableComponent {...foldableProps} isOpened={true} />); | ||
const foldable = screen.getByTestId(qaAttributes.default); | ||
|
||
expect(foldable).toHaveClass(IS_OPEN_CLASS_NAME); | ||
}); | ||
|
||
test('add className', () => { | ||
testCustomClassName<FoldableProps>({ | ||
component: FoldableComponent, | ||
props: foldableProps, | ||
}); | ||
}); | ||
}); |