-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add readonly functionality to select (#12405)
* feat: add readonly functionality to select * feat: add readonly functionality to select * chore: remove unnecessary scss vars * fix: cursor following review Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
baa7fd5
commit 99db21a
Showing
4 changed files
with
93 additions
and
0 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
53 changes: 53 additions & 0 deletions
53
packages/react/src/components/Select/__tests__/Select-test.js
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,53 @@ | ||
/** | ||
* Copyright IBM Corp. 2016, 2018 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React from 'react'; | ||
import Select from '../Select'; | ||
import SelectItem from '../../SelectItem'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
describe('Select', () => { | ||
describe('behaves as expected - Component API', () => { | ||
it.skip('should respect readOnly prop', () => { | ||
const onChange = jest.fn(); | ||
const onClick = jest.fn(); | ||
|
||
render( | ||
<Select | ||
id="select-1" | ||
label="Select label" | ||
readOnly={true} | ||
onClick={onClick} | ||
onChange={onChange}> | ||
<SelectItem text="Choose an option" value="placeholder-item" /> | ||
<SelectItem text="Option 1" value="option-1" /> | ||
<SelectItem text="Option 2" value="option-2" /> | ||
</Select> | ||
); | ||
|
||
// Click events should fire | ||
const theSelect = screen.getByRole('combobox'); | ||
userEvent.click(theSelect); | ||
expect(onClick).toHaveBeenCalledTimes(1); | ||
|
||
//------------------------------------------------------------------------ | ||
// Testing library - userEvent.type() does not work on <select> elements | ||
// and using selectOption causes the value to change. | ||
// Ideally we'd use userEvent.type(theSelect, '{arrowdown}{enter}') to test the readOnly prop | ||
// or have a way to click on a slotted option. | ||
// https://github.com/testing-library/user-event/issues/786 | ||
//------------------------------------------------------------------------ | ||
userEvent.selectOptions(theSelect, 'option-1'); | ||
|
||
// Change events should *not* fire | ||
expect(screen.getByText('Option 1').selected).toBe(false); | ||
|
||
expect(onChange).toHaveBeenCalledTimes(0); | ||
}); | ||
}); | ||
}); |
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