-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6aa4143
commit 93a2a00
Showing
21 changed files
with
509 additions
and
113 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
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 |
---|---|---|
|
@@ -32,4 +32,5 @@ Showcase.args = { | |
disabled: false, | ||
placeholder: 'Values', | ||
label: '', | ||
hasClear: false, | ||
}; |
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
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
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,76 @@ | ||
import {cleanup} from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
import {SelectQa} from '../constants'; | ||
import type {SelectProps} from '../types'; | ||
|
||
import {DEFAULT_OPTIONS, setup} from './utils'; | ||
|
||
afterEach(() => { | ||
cleanup(); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
const onUpdate = jest.fn(); | ||
|
||
describe('Select clear', () => { | ||
test.each<[string, Partial<SelectProps>]>([ | ||
['single', {hasClear: true, multiple: false}], | ||
['multiple', {hasClear: true, multiple: true}], | ||
])('hide clear icon with hasClear and no selected value', async () => { | ||
const {queryByTestId} = setup({hasClear: true}); | ||
expect(queryByTestId(SelectQa.CLEAR)).toBeNull(); | ||
}); | ||
|
||
test.each<[string, Partial<SelectProps>]>([ | ||
['single', {hasClear: true, multiple: false}], | ||
['multiple', {hasClear: true, multiple: true}], | ||
])('display clear icon with hasClear and with selected value', async () => { | ||
const {getByTestId} = setup({hasClear: true, value: [DEFAULT_OPTIONS[0].value]}); | ||
getByTestId(SelectQa.CLEAR); | ||
}); | ||
|
||
test.each<[string, Partial<SelectProps>]>([ | ||
['single', {hasClear: true, multiple: false}], | ||
['multiple', {hasClear: true, multiple: true}], | ||
])('hide clear icon for disabled select with hasClear and with selected value', async () => { | ||
const {queryByTestId} = setup({ | ||
hasClear: true, | ||
disabled: true, | ||
value: [DEFAULT_OPTIONS[0].value], | ||
}); | ||
expect(queryByTestId(SelectQa.CLEAR)).toBeNull(); | ||
}); | ||
|
||
test.each<[string, Partial<SelectProps>]>([ | ||
['single', {hasClear: true, multiple: false}], | ||
['multiple', {hasClear: true, multiple: true}], | ||
])('click on clear icon will remove selected value', async () => { | ||
const {getByTestId} = setup({ | ||
hasClear: true, | ||
value: [DEFAULT_OPTIONS[0].value], | ||
onUpdate, | ||
}); | ||
|
||
const user = userEvent.setup(); | ||
await user.click(getByTestId(SelectQa.CLEAR)); | ||
expect(onUpdate).toHaveBeenCalledWith([]); | ||
}); | ||
|
||
test.each<[string, Partial<SelectProps>]>([ | ||
['single', {hasClear: true, multiple: false}], | ||
['multiple', {hasClear: true, multiple: true}], | ||
])('check for correct focus on tab with hasClear and with selected value', async () => { | ||
setup({ | ||
hasClear: true, | ||
value: [DEFAULT_OPTIONS[0].value], | ||
onUpdate, | ||
}); | ||
const user = userEvent.setup(); | ||
await user.keyboard('[Tab]'); | ||
await user.keyboard('[Tab]'); | ||
// check that after double tab clear icon is focused and press enter will clear the value | ||
await user.keyboard('[Enter]'); | ||
expect(onUpdate).toHaveBeenCalledWith([]); | ||
}); | ||
}); |
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
Oops, something went wrong.