-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: pass disabled props for radio bar component (#997)
- Loading branch information
1 parent
312c8be
commit a4eb6f9
Showing
15 changed files
with
396 additions
and
10 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 |
---|---|---|
@@ -0,0 +1,176 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import CheckboxGroup from './CheckboxGroup'; | ||
import { CheckboxGroupProps } from './checkboxGroup.utils'; | ||
import { MODE_CREATE } from '../../constants/modes'; | ||
|
||
const handleChange = jest.fn(); | ||
|
||
const defaultCheckboxProps: CheckboxGroupProps = { | ||
mode: MODE_CREATE, | ||
field: 'api', | ||
value: 'collect_collaboration/1200,collect_file/1,collect_task/1', | ||
controlOptions: { | ||
rows: [ | ||
{ | ||
field: 'collect_collaboration', | ||
checkbox: { | ||
label: 'Collect folder collaboration', | ||
}, | ||
input: { | ||
defaultValue: 1200, | ||
required: false, | ||
}, | ||
}, | ||
{ | ||
field: 'collect_file', | ||
checkbox: { | ||
label: 'Collect file metadata', | ||
}, | ||
input: { | ||
defaultValue: 1, | ||
required: true, | ||
}, | ||
}, | ||
{ | ||
field: 'collect_task', | ||
checkbox: { | ||
label: 'Collect tasks and comments', | ||
}, | ||
input: { | ||
defaultValue: 1, | ||
required: true, | ||
}, | ||
}, | ||
], | ||
}, | ||
handleChange, | ||
}; | ||
|
||
const renderFeature = (additionalProps?: Partial<CheckboxGroupProps>) => { | ||
const props = { | ||
...defaultCheckboxProps, | ||
...additionalProps, | ||
}; | ||
render(<CheckboxGroup {...props} />); | ||
}; | ||
|
||
it('renders checkbox group correctly', async () => { | ||
renderFeature(); | ||
defaultCheckboxProps.controlOptions.rows.forEach((row) => { | ||
const optionWithCorrectText = screen.getByText(row?.checkbox?.label || 'unexisting string'); | ||
expect(optionWithCorrectText).toBeInTheDocument(); | ||
expect(optionWithCorrectText.dataset?.disabled).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
it('renders disabled checkbox group correctly', async () => { | ||
renderFeature({ disabled: true }); | ||
defaultCheckboxProps.controlOptions.rows.forEach((row) => { | ||
const optionWithCorrectText = screen.getByText(row?.checkbox?.label || 'unexisting string'); | ||
expect(optionWithCorrectText).toBeInTheDocument(); | ||
expect(optionWithCorrectText.dataset.disabled).toEqual('true'); | ||
}); | ||
}); | ||
|
||
it('increment value correctly', async () => { | ||
renderFeature(); | ||
const incrementButtons = screen.getAllByTestId('increment'); | ||
const [firstIncrementer, secondIncrementer, thirdIncrementer] = incrementButtons; | ||
|
||
await userEvent.click(firstIncrementer); | ||
expect(handleChange).toHaveBeenCalledWith( | ||
defaultCheckboxProps.field, | ||
'collect_collaboration/1201,collect_file/1,collect_task/1', | ||
'checkboxGroup' | ||
); | ||
await userEvent.click(secondIncrementer); | ||
expect(handleChange).toHaveBeenCalledWith( | ||
defaultCheckboxProps.field, | ||
'collect_collaboration/1201,collect_file/2,collect_task/1', | ||
'checkboxGroup' | ||
); | ||
await userEvent.click(thirdIncrementer); | ||
expect(handleChange).toHaveBeenCalledWith( | ||
defaultCheckboxProps.field, | ||
'collect_collaboration/1201,collect_file/2,collect_task/2', | ||
'checkboxGroup' | ||
); | ||
}); | ||
|
||
it('decrement value correctly', async () => { | ||
renderFeature(); | ||
const decrementButtons = screen.getAllByTestId('decrement'); | ||
const [firstDecrement, secondDecrement, thirdDecrement] = decrementButtons; | ||
|
||
await userEvent.click(firstDecrement); | ||
expect(handleChange).toHaveBeenCalledWith( | ||
defaultCheckboxProps.field, | ||
'collect_collaboration/1199,collect_file/1,collect_task/1', | ||
'checkboxGroup' | ||
); | ||
await userEvent.click(secondDecrement); | ||
expect(handleChange).toHaveBeenCalledWith( | ||
defaultCheckboxProps.field, | ||
'collect_collaboration/1199,collect_file/0,collect_task/1', | ||
'checkboxGroup' | ||
); | ||
await userEvent.click(thirdDecrement); | ||
expect(handleChange).toHaveBeenCalledWith( | ||
defaultCheckboxProps.field, | ||
'collect_collaboration/1199,collect_file/0,collect_task/0', | ||
'checkboxGroup' | ||
); | ||
}); | ||
|
||
it('mixed incrementing and decrementing value correctly', async () => { | ||
renderFeature(); | ||
const incrementButtons = screen.getAllByTestId('increment'); | ||
const [firstIncrementer, secondIncrementer, thirdIncrementer] = incrementButtons; | ||
|
||
const decrementButtons = screen.getAllByTestId('decrement'); | ||
const [firstDecrement, secondDecrement, thirdDecrement] = decrementButtons; | ||
|
||
await userEvent.click(firstDecrement); | ||
expect(handleChange).toHaveBeenCalledWith( | ||
defaultCheckboxProps.field, | ||
'collect_collaboration/1199,collect_file/1,collect_task/1', | ||
'checkboxGroup' | ||
); | ||
|
||
await userEvent.click(thirdIncrementer); | ||
expect(handleChange).toHaveBeenCalledWith( | ||
defaultCheckboxProps.field, | ||
'collect_collaboration/1199,collect_file/1,collect_task/2', | ||
'checkboxGroup' | ||
); | ||
|
||
await userEvent.click(secondDecrement); | ||
expect(handleChange).toHaveBeenCalledWith( | ||
defaultCheckboxProps.field, | ||
'collect_collaboration/1199,collect_file/0,collect_task/2', | ||
'checkboxGroup' | ||
); | ||
|
||
await userEvent.click(firstIncrementer); | ||
expect(handleChange).toHaveBeenCalledWith( | ||
defaultCheckboxProps.field, | ||
'collect_collaboration/1200,collect_file/0,collect_task/2', | ||
'checkboxGroup' | ||
); | ||
|
||
await userEvent.click(thirdDecrement); | ||
expect(handleChange).toHaveBeenCalledWith( | ||
defaultCheckboxProps.field, | ||
'collect_collaboration/1200,collect_file/0,collect_task/1', | ||
'checkboxGroup' | ||
); | ||
|
||
await userEvent.click(secondIncrementer); | ||
expect(handleChange).toHaveBeenCalledWith( | ||
defaultCheckboxProps.field, | ||
defaultCheckboxProps.value, | ||
'checkboxGroup' | ||
); | ||
}); |
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
File renamed without changes.
53 changes: 53 additions & 0 deletions
53
ui/src/components/MultiInputComponent/MultiInputComponent.test.tsx
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 @@ | ||
import React from 'react'; | ||
|
||
import { render, screen } from '@testing-library/react'; | ||
import MultiInputComponent, { MultiInputComponentProps } from './MultiInputComponent'; | ||
|
||
const handleChange = jest.fn(); | ||
|
||
const defaultInputProps: MultiInputComponentProps = { | ||
field: 'defaultFieldName', | ||
controlOptions: { | ||
delimiter: ',', | ||
createSearchChoice: true, | ||
referenceName: 'referenceName', | ||
dependencies: undefined, | ||
endpointUrl: undefined, | ||
labelField: 'labelField', | ||
items: [ | ||
{ label: 'label1', value: 'value1' }, | ||
{ label: 'label2', value: 'value2' }, | ||
{ label: 'label3', value: 'value3' }, | ||
], | ||
}, | ||
disabled: false, | ||
value: 'defaultValue', | ||
error: false, | ||
dependencyValues: {}, | ||
handleChange, | ||
}; | ||
|
||
const renderFeature = (additionalProps?: Partial<MultiInputComponentProps>) => { | ||
const props = { | ||
...defaultInputProps, | ||
...additionalProps, | ||
}; | ||
render(<MultiInputComponent {...props} />); | ||
}; | ||
|
||
it('renders correctly', () => { | ||
renderFeature(); | ||
const inputComponent = screen.getByTestId('multiselect'); | ||
expect(inputComponent).toBeInTheDocument(); | ||
expect(inputComponent.getAttribute('data-test-values')).toEqual( | ||
// eslint-disable-next-line no-useless-escape | ||
`[\"${defaultInputProps.value}\"]` | ||
); | ||
}); | ||
|
||
it('renders as disabled correctly', () => { | ||
renderFeature({ disabled: true }); | ||
const inputComponent = screen.getByTestId('multiselect'); | ||
expect(inputComponent).toBeInTheDocument(); | ||
expect(inputComponent.getAttribute('aria-disabled')).toEqual('true'); | ||
}); |
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 |
---|---|---|
|
@@ -29,5 +29,6 @@ export const Base: Story = { | |
}, | ||
], | ||
}, | ||
disabled: false, | ||
}, | ||
}; |
Oops, something went wrong.