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

Code before:
      const { getByText } = render(<XButtons model={btnPropsNameHash} />)
      fireEvent.click(getByText(name))

      expect(window.location.hash).toBe(hashName)
      expect(pushMock).toHaveBeenCalledTimes(0)
      expect(wave.args[name]).toBe(null)
    })

    it('Renders a link when specified', () => {
      const btnLinkProps: Buttons = { items: [{ button: { name, label: name, link: true } }] }
      const { getByTestId } = render(<XButtons model={btnLinkProps} />)

      expect(getByTestId(name)).toHaveClass('ms-Link')
    })

    it('Does not render a link when not specified', () => {
      const { queryByTestId } = render(<XButtons model={btnProps} />)

      expect(queryByTestId(name)).not.toHaveClass('ms-Link')
    })

    it('Does redirect if path is specified', () => {
      const
        windowOpenMock = jest.fn(),
        btnPathProps: Buttons = { items: [{ button: { name, label: name, path: 'https://h2o.ai/' } }] },
        { getByTestId } = render(<XButtons model={btnPathProps} />)

      window.open = windowOpenMock
      fireEvent.click(getByTestId(name))
      expect(windowOpenMock).toHaveBeenCalled()
    })
  })

  describe('Mini button', () => {
    const
      miniBtns: MiniButtons = { items: [{ mini_button: { name, label: name } }] },
      miniBtnsNameHash: MiniButtons = { items: [{ mini_button: { name: `#${name}`, label: name } }] }

    it('Renders data-test attr for MiniButton', () => {
      const { queryByTestId } = render(<XMiniButtons model={miniBtns} />)
      expect(queryByTestId(name)).toBeInTheDocument()
    })

    it('Calls sync() after click', () => {
      const { getByText } = render(<XMiniButtons model={miniBtns} />)

      fireEvent.click(getByText(name))

      expect(pushMock).toHaveBeenCalled()
      expect(wave.args[name]).toBe(true)
      expect(window.location.hash).toBe('')

Review comment (suggestion):
```suggestion
        { getByTestId } = render(<XButtons model={{ items: [{ button: { name, label: name, path: 'https://h2o.ai/' } }] }} />)
```

Code after:
      const { getByText } = render(<XButtons model={btnPropsNameHash} />)
      fireEvent.click(getByText(name))

      expect(window.location.hash).toBe(hashName)
      expect(pushMock).toHaveBeenCalledTimes(0)
      expect(wave.args[name]).toBe(null)
    })

    it('Renders a link when specified', () => {
      const btnLinkProps: Buttons = { items: [{ button: { name, label: name, link: true } }] }
      const { getByTestId } = render(<XButtons model={btnLinkProps} />)

      expect(getByTestId(name)).toHaveClass('ms-Link')
    })

    it('Does not render a link when not specified', () => {
      const { queryByTestId } = render(<XButtons model={btnProps} />)

      expect(queryByTestId(name)).not.toHaveClass('ms-Link')
    })

    it('Does redirect if path is specified', () => {
      const
        windowOpenMock = jest.fn(),
        { getByTestId } = render(<XButtons model={{ items: [{ button: { name, label: name, path: 'https://h2o.ai/' } }] }} />)

      window.open = windowOpenMock
      fireEvent.click(getByTestId(name))
      expect(windowOpenMock).toHaveBeenCalled()
    })
  })

  describe('Mini button', () => {
    const
      miniBtns: MiniButtons = { items: [{ mini_button: { name, label: name } }] },
      miniBtnsNameHash: MiniButtons = { items: [{ mini_button: { name: `#${name}`, label: name } }] }

    it('Renders data-test attr for MiniButton', () => {
      const { queryByTestId } = render(<XMiniButtons model={miniBtns} />)
      expect(queryByTestId(name)).toBeInTheDocument()
    })

    it('Calls sync() after click', () => {
      const { getByText } = render(<XMiniButtons model={miniBtns} />)

      fireEvent.click(getByText(name))

      expect(pushMock).toHaveBeenCalled()
      expect(wave.args[name]).toBe(true)
      expect(window.location.hash).toBe('')
    })