-
Notifications
You must be signed in to change notification settings - Fork 751
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: I've tested the frontend and backend of #1994
I've added a new jsx which tests the new component and also I've modified some test for not repeat code.
- Loading branch information
1 parent
8b165d3
commit 1dfe7cc
Showing
3 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
client/app/components/Input/__tests__/InputMultiSelect.spec.jsx
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,65 @@ | ||
// @flow | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { InputMocks } from 'mocks/InputMocks'; | ||
import { InputMultiSelect } from 'components/Input/InputMultiSelect'; | ||
|
||
const { | ||
id, name, ariaLabel, value, options, | ||
} = InputMocks.inputSelectProps; | ||
const someEvent = InputMocks.event; | ||
|
||
describe('InputMultiSelect', () => { | ||
beforeEach(() => { | ||
jest.spyOn(window, 'alert'); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('renders correctly', () => { | ||
render( | ||
<InputMultiSelect | ||
name={name} | ||
id={id} | ||
ariaLabel={ariaLabel} | ||
value={value} | ||
options={options} | ||
onChange={someEvent} | ||
/>, | ||
); | ||
const multiSelect = screen.getByRole('button', { className: 'buttonL' }); | ||
expect(multiSelect).toBeInTheDocument(); | ||
expect(screen.getAllByRole('checkbox').length).toEqual(2); | ||
}); | ||
|
||
it('toggles options correctly', () => { | ||
render( | ||
<InputMultiSelect | ||
name={name} | ||
id={id} | ||
ariaLabel={ariaLabel} | ||
options={options} | ||
onChange={someEvent} | ||
/>, | ||
); | ||
// toggle the first value | ||
const multiSelect = screen.getByRole('componentValue', { hidden: true }); | ||
const checkbox = screen.getByRole('checkbox', { name: options[0].label }); | ||
const checkbox2 = screen.getByRole('checkbox', { name: options[1].label }); | ||
|
||
userEvent.click(checkbox); | ||
expect(multiSelect.value).toEqual(`${options[0].value}`); | ||
|
||
// update the value | ||
userEvent.click(checkbox2); | ||
expect(multiSelect.value).toEqual(`${options[0].value},${options[1].value}`); | ||
|
||
// update the value by unchecking | ||
userEvent.click(checkbox); | ||
expect(multiSelect.value).toEqual(`${options[1].value}`); | ||
|
||
}); | ||
}); |
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