Skip to content

Commit

Permalink
chore: tests refactor #1959
Browse files Browse the repository at this point in the history
  • Loading branch information
marek-mihok committed May 3, 2023
1 parent 073f9c3 commit d60e59d
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions ui/src/dropdown.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ import userEvent from '@testing-library/user-event'
import React from 'react'
import { Dropdown, XDropdown } from './dropdown'
import { wave } from './ui'
import { Choice } from './choice_group'

describe('Dropdown.tsx', () => {
const
name = 'dropdown-test',
choicesDisabled: Choice[] = [
{ name: '1', label: 'Choice 1' },
{ name: '2', label: 'Choice 2', disabled: true },
{ name: '3', label: 'Choice 3' }
],
// Need to test if wave.args are correct after calling push so mock the implementation.
pushMock = jest.fn(() => wave.args = {})

Expand Down Expand Up @@ -118,17 +124,11 @@ describe('Dropdown.tsx', () => {
})

it('Selects all options on Select all - except disabled', () => {
const choices = [
{ name: 'A', label: 'Choice A' },
{ name: 'B', label: 'Choice B' },
{ name: 'C', label: 'Choice C', disabled: true },
{ name: 'D', label: 'Choice D' },
]
const { getByText } = render(<XDropdown model={{ ...defaultProps, choices, values: ['A'] }} />)
const { getByText } = render(<XDropdown model={{ ...defaultProps, choices: choicesDisabled, values: ['1'] }} />)

fireEvent.click(getByText('Select All'))

expect(wave.args[name]).toMatchObject(['A', 'B', 'D'])
expect(wave.args[name]).toMatchObject(['1', '3'])
})

it('Do not select all options on Select all - dropdown disabled', () => {
Expand Down Expand Up @@ -369,13 +369,7 @@ describe('Dropdown.tsx', () => {
})

it('Selects all options on Select all - except disabled', () => {
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: ['1'] }} />)
const { getByText, getByTestId } = render(<XDropdown model={{ ...dialogProps, choices: choicesDisabled, values: ['1'] }} />)

expect(wave.args[name]).toMatchObject(['1'])
fireEvent.click(getByTestId(name))
Expand All @@ -386,13 +380,7 @@ describe('Dropdown.tsx', () => {
})

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'] }} />)
const { getByText, getByTestId } = render(<XDropdown model={{ ...dialogProps, choices: choicesDisabled, values: ['2', '3'] }} />)

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

Expand Down

0 comments on commit d60e59d

Please sign in to comment.