Skip to content

Commit

Permalink
chore: fix failing UI unit tests (h2oai#2221)
Browse files Browse the repository at this point in the history
  • Loading branch information
marek-mihok committed Dec 8, 2023
1 parent a0151cd commit 7887ef6
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions ui/src/combobox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ describe('Combobox.tsx', () => {
})

it('Adds new typed option only once to options list', () => {
const { getAllByRole, getByRole, queryAllByTitle, } = render(<XCombobox model={{ ...comboboxProps, value: 'A' }} />)
const { getAllByRole, getByRole, queryAllByText } = render(<XCombobox model={{ ...comboboxProps, value: 'A' }} />)
fireEvent.click(getByRole('presentation', { hidden: true }))
expect(getAllByRole('option')).toHaveLength(3)
expect(queryAllByTitle('D')).toHaveLength(0)
expect(queryAllByText('D')).toHaveLength(0)

userEvent.type(getByRole('combobox'), '{backspace}D{enter}')
fireEvent.click(getByRole('presentation', { hidden: true }))
expect(getAllByRole('option')).toHaveLength(4)
expect(queryAllByTitle('D')).toHaveLength(1)
expect(queryAllByText('D')).toHaveLength(1)
})

describe('Wave args', () => {
Expand All @@ -78,13 +78,13 @@ describe('Combobox.tsx', () => {
})

it('Sets args to manually selected option', () => {
const { getByRole, getByTitle } = render(<XCombobox model={{ ...comboboxProps }} />)
const { getByRole, getByText } = render(<XCombobox model={{ ...comboboxProps }} />)
fireEvent.click(getByRole('presentation', { hidden: true }))
fireEvent.click(getByTitle('A'))
fireEvent.click(getByText('A'))
expect(wave.args[name]).toBe('A')

fireEvent.click(getByRole('presentation', { hidden: true }))
fireEvent.click(getByTitle('B'))
fireEvent.click(getByText('B'))
expect(wave.args[name]).toBe('B')
})

Expand Down Expand Up @@ -206,23 +206,23 @@ describe('Combobox.tsx', () => {
})

it('Adds initial value to options if it\'s not included in "choices" prop', () => {
const { getByTitle, getAllByRole, getByRole } = render(<XCombobox model={{ ...comboboxProps, value: 'Z' }} />)
const { getByText, getAllByRole, getByRole } = render(<XCombobox model={{ ...comboboxProps, value: 'Z' }} />)
expect(wave.args[name]).toEqual('Z')
expect(getByRole('combobox')).toHaveValue('Z')
fireEvent.click(getByRole('presentation', { hidden: true }))
expect(getAllByRole('option')).toHaveLength(4)
expect(getByTitle('Z')).toBeDefined()
expect(getByText('Z')).toBeDefined()
})

it('Adds value to choices when both are updated and value was included in previous choices but not in the new choices', () => {
const { getByRole, getAllByRole, getByTitle, rerender } = render(<XCombobox model={{ ...comboboxProps, value: 'A' }} />)
const { getByRole, getAllByRole, getByText, rerender } = render(<XCombobox model={{ ...comboboxProps, value: 'A' }} />)
expect(getByRole('combobox')).toHaveValue('A')

rerender(<XCombobox model={{ ...comboboxProps, value: 'C', choices: ['A', 'B'] }} />)
expect(getByRole('combobox')).toHaveValue('C')
fireEvent.click(getByRole('presentation', { hidden: true }))
expect(getAllByRole('option')).toHaveLength(3)
expect(getByTitle('C')).toBeDefined()
expect(getByText('C')).toBeDefined()
})

it('Display same value if choices change and value is included in choices', () => {
Expand Down Expand Up @@ -324,12 +324,12 @@ describe('Combobox.tsx', () => {
})

it('Adds initial values to options if they are not already included in options ', () => {
const { getByTitle, getAllByRole, getByRole } = render(<XCombobox model={{ ...comboboxProps, value: 'Z' }} />)
const { getByText, getAllByRole, getByRole } = render(<XCombobox model={{ ...comboboxProps, value: 'Z' }} />)
expect(wave.args[name]).toEqual('Z')
expect(getByRole('combobox')).toHaveValue('Z')
fireEvent.click(getByRole('presentation', { hidden: true }))
expect(getAllByRole('option')).toHaveLength(4)
expect(getByTitle('Z')).toBeDefined()
expect(getByText('Z')).toBeDefined()
})
})
})
Expand Down

0 comments on commit 7887ef6

Please sign in to comment.