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

Code before:

      const { getByText } = render(<XTable model={tableProps} />)
      fireEvent.click(getByText(cell21))

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

    it('Sets args - multiple selection', () => {
      const { getAllByRole } = render(<XTable model={{ ...tableProps, multiple: true }} />)
      const checkboxes = getAllByRole('checkbox')

      fireEvent.click(checkboxes[1])
      fireEvent.click(checkboxes[2])

      expect(wave.args[name]).toMatchObject(['rowname1', 'rowname2'])
    })

    it('Sets args - single selection', () => {
      const { getAllByRole } = render(<XTable model={{ ...tableProps, isSingle: true }} />)
      const radioButtons = getAllByRole('radio')

      fireEvent.click(radioButtons[0])
      fireEvent.click(radioButtons[1])

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

    it('Fires event - multiple selection - select single', () => {
      const { getAllByRole } = render(<XTable model={{ ...tableProps, multiple: true, events: ['select'] }} />)
      const checkboxes = getAllByRole('checkbox')

      fireEvent.click(checkboxes[1])

      expect(emitMock).toHaveBeenCalledWith(tableProps.name, 'select', ['rowname1'])
      expect(emitMock).toHaveBeenCalledTimes(1)
    })

    it('Fires event - multiple selection - select multiple', () => {
      const { getAllByRole } = render(<XTable model={{ ...tableProps, multiple: true, events: ['select'] }} />)
      const checkboxes = getAllByRole('checkbox')

      fireEvent.click(checkboxes[1])
      fireEvent.click(checkboxes[2])

      expect(emitMock).toHaveBeenCalledWith(tableProps.name, 'select', ['rowname1', 'rowname2'])
      expect(emitMock).toHaveBeenCalledTimes(2)
    })

    it('Fires event - single selection', () => {
      const { getAllByRole } = render(<XTable model={{ ...tableProps, isSingle: true, events: ['select'] }} />)

Review comment (suggestion):
let's make this more clear
```suggestion
      fireEvent.click(radioButtons[0])
      expect(wave.args[name]).toMatchObject(['rowname1'])
      fireEvent.click(radioButtons[1])

      expect(wave.args[name]).toMatchObject(['rowname2'])
```

Code after:

      const { getByText } = render(<XTable model={tableProps} />)
      fireEvent.click(getByText(cell21))

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

    it('Sets args and calls sync on first col click - single selection', () => {
      const pushMock = jest.fn()
      wave.push = pushMock

      const { getByText } = render(<XTable model={{ ...tableProps, single: true }} />)
      fireEvent.click(getByText(cell21))

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

    it('Sets args and calls sync on first col click - multiple selection', () => {
      const pushMock = jest.fn()
      wave.push = pushMock

      const { getByText } = render(<XTable model={{ ...tableProps, multiple: true }} />)
      fireEvent.click(getByText(cell21))

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

    it('Do not set args and call sync on doubleclick - single selection', () => {
      const pushMock = jest.fn()
      wave.push = pushMock

      const { getAllByRole } = render(<XTable model={{ ...tableProps, single: true }} />)
      fireEvent.doubleClick(getAllByRole('row')[1])

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

    it('Do not set args and call sync on doubleclick - multiple selection', () => {
      const pushMock = jest.fn()
      wave.push = pushMock

      const { getAllByRole } = render(<XTable model={{ ...tableProps, multiple: true }} />)
      fireEvent.doubleClick(getAllByRole('row')[1])

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