Repository: h2oai/wave
File: ui/src/dropdown.test.tsx (TypeScript)

Code before:

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

    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'] }} />)

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

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

    it('Do not select all options on Select all - dropdown disabled', () => {
      const { getByText } = render(<XDropdown model={{ ...defaultProps, values: ['A'], disabled: true }} />)

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

      expect(wave.args[name]).toMatchObject(['A'])
    })

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

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

      expect(pushMock).toHaveBeenCalled()
      expect(wave.args[name]).toMatchObject(['A', 'B', 'C', 'D'])
    })

    it('Deselects all options on Deselect all', () => {
      const { getByText } = render(<XDropdown model={{ ...defaultProps, values: ['A'], trigger: true }} />)

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

      expect(wave.args[name]).toMatchObject([])
      expect(pushMock).toHaveBeenCalled()
    })

    it('Do not deselect all options on Deselect all - dropdown disabled', () => {
      const { getByText } = render(<XDropdown model={{ ...defaultProps, values: ['A'], disabled: true }} />)

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

      expect(wave.args[name]).toMatchObject(['A'])
    })

Review comment (suggestion):
Let's make the initial state clear.
```suggestion
      expect(wave.args[name]).toMatchObject(['A'])

      fireEvent.click(getByText('Select All'))

      expect(wave.args[name]).toMatchObject(['A'])
```

Code after:

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

    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'] }} />)

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

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

    it('Do not select all options on Select all - dropdown disabled', () => {
      const { getByText } = render(<XDropdown model={{ ...defaultProps, values: ['A'], disabled: true }} />)

      expect(wave.args[name]).toMatchObject(['A'])

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

      expect(wave.args[name]).toMatchObject(['A'])
    })

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

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

      expect(pushMock).toHaveBeenCalled()
      expect(wave.args[name]).toMatchObject(['A', 'B', 'C', 'D'])
    })

    it('Deselects all options on Deselect all', () => {
      const { getByText } = render(<XDropdown model={{ ...defaultProps, values: ['A'], trigger: true }} />)

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

      expect(wave.args[name]).toMatchObject([])
      expect(pushMock).toHaveBeenCalled()
    })

    it('Do not deselect all options on Deselect all - dropdown disabled', () => {
      const { getByText } = render(<XDropdown model={{ ...defaultProps, values: ['A'], disabled: true }} />)

      expect(wave.args[name]).toMatchObject(['A'])