Skip to content

Commit

Permalink
chore: add tests for preventing disabled choices from being modified …
Browse files Browse the repository at this point in the history
…during Select/Deselect all #1959
  • Loading branch information
marek-mihok committed May 17, 2023
1 parent 98dc882 commit 932da7c
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions ui/src/dropdown.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,24 @@ describe('Dropdown.tsx', () => {
expect(wave.args[name]).toMatchObject(['A'])
})

it('Does not modify disabled choice on Select/Deselect all', () => {
const choices = [
{ name: '1', label: 'Choice 1' },
{ name: '2', label: 'Choice 2', disabled: true },
{ name: '3', label: 'Choice 3' }
]

const { getByText } = render(<XDropdown model={{ ...defaultProps, choices, values: ['2', '3'] }} />)

expect(wave.args[name]).toMatchObject(['2', '3'])

fireEvent.click(getByText('Select All'))
expect(wave.args[name]).toMatchObject(['1', '2', '3'])

fireEvent.click(getByText('Deselect All'))
expect(wave.args[name]).toMatchObject(['2'])
})

it('Calls sync on Select all - trigger enabled', async () => {
const { getByText } = render(<XDropdown model={{ ...defaultProps, values: ['A'], trigger: true }} />)

Expand Down Expand Up @@ -385,6 +403,28 @@ describe('Dropdown.tsx', () => {
expect(wave.args[name]).toMatchObject(['1', '3'])
})

it('Does not modify disabled choice on Select/Deselect all', () => {
const choices = [
{ name: '1', label: 'Choice 1' },
{ name: '2', label: 'Choice 2', disabled: true },
{ name: '3', label: 'Choice 3' }
]

const { getByText, getByTestId } = render(<XDropdown model={{ ...dialogProps, choices, values: ['2', '3'] }} />)

expect(wave.args[name]).toMatchObject(['2', '3'])

fireEvent.click(getByTestId(name))
fireEvent.click(getByText('Select All'))
fireEvent.click(getByText('Select'))
expect(wave.args[name]).toMatchObject(['1', '2', '3'])

fireEvent.click(getByTestId(name))
fireEvent.click(getByText('Deselect All'))
fireEvent.click(getByText('Select'))
expect(wave.args[name]).toMatchObject(['2'])
})

it('Sets correct args after filter', () => {
const { getByText, getByTestId, getAllByRole } = render(<XDropdown model={{ ...dialogProps, values: ['1'] }} />)

Expand Down

0 comments on commit 932da7c

Please sign in to comment.