Sha256: 7144acfe60e7d3e6e60a176739ca1d8d56b677eb7dcbc51bff65293231b691b3

Contents?: true

Size: 1.77 KB

Versions: 15

Compression:

Stored size: 1.77 KB

Contents

import React from 'react';
import { CopyButton } from 'playbook-ui'
import { ensureAccessible, renderKit, render, fireEvent, screen } from '../utilities/test-utils'

const props = {
  data: { testid: 'default', value: 'copy' }
}

test('returns namespaced class name', () => {
  const kit = renderKit(CopyButton, props)
  expect(kit).toBeInTheDocument()
  expect(kit).toHaveClass('pb_copy_button_kit')
})

it('should be accessible', async () => {
  ensureAccessible(CopyButton, props)
})

// It's difficult to actually use navigator.clipboard.readText, so we mock
it('copies the value to clipboard and pastes it into an input', async () => {
  Object.defineProperty(global, 'navigator', {
    value: {
      clipboard: {
        writeText: jest.fn().mockResolvedValueOnce(undefined),
      },
    },
    writable: true,
  })

  render(<CopyButton {...props} />)

  const copyButton = screen.getByTestId('default')
  fireEvent.click(copyButton)

  await navigator.clipboard.writeText('copy')

  expect(navigator.clipboard.writeText).toHaveBeenCalledWith("copy");
})

test('passes text and tooltip props to button', () => {
  render(
      <CopyButton
          data={{ testid: 'text-test' }}
          text={"text"}
          tooltipPlacement="right"
          tooltipText="Text copied!"
          value="copy"
      />
  )

  const content = screen.getByText("text")
  expect(content).toHaveTextContent("text")

  const kit = screen.getByTestId('text-test')
  const button = kit.querySelector('.pb_button_kit_primary_inline_enabled')
  expect(button).toBeInTheDocument()

  fireEvent.click(button)
  const tooltipContent = screen.getByText("Text copied!")
  expect(tooltipContent).toHaveTextContent("Text copied!")

  const tooltip = kit.querySelector('.pb_tooltip_kit')
  expect(tooltip).toBeInTheDocument()
})

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
playbook_ui-14.13.0.pre.rc.5 app/pb_kits/playbook/pb_copy_button/copy_button.test.jsx
playbook_ui-14.12.0.pre.alpha.PLAY1602lightboxoverlapnitrobug5781 app/pb_kits/playbook/pb_copy_button/copy_button.test.jsx
playbook_ui-14.13.0.pre.rc.4 app/pb_kits/playbook/pb_copy_button/copy_button.test.jsx
playbook_ui-14.12.0.pre.alpha.playrailsinputmaskissue5775 app/pb_kits/playbook/pb_copy_button/copy_button.test.jsx
playbook_ui-14.12.0.pre.alpha.PBNTR456fixedconftoastrailsautoclose5757 app/pb_kits/playbook/pb_copy_button/copy_button.test.jsx
playbook_ui-14.12.0.pre.alpha.PBNTR456fixedconftoastrailsautoclose5754 app/pb_kits/playbook/pb_copy_button/copy_button.test.jsx
playbook_ui-14.12.0.pre.alpha.PLAY1602lightboxoverlapnitrobugzindextoken5751 app/pb_kits/playbook/pb_copy_button/copy_button.test.jsx
playbook_ui-14.12.0.pre.alpha.PBNTR456fixedconftoastrailsautoclose5738 app/pb_kits/playbook/pb_copy_button/copy_button.test.jsx
playbook_ui-14.13.0.pre.rc.3 app/pb_kits/playbook/pb_copy_button/copy_button.test.jsx
playbook_ui-14.12.0.pre.alpha.PLAY1865reactdatepickerreinitializingbug5732 app/pb_kits/playbook/pb_copy_button/copy_button.test.jsx
playbook_ui-14.12.0.pre.alpha.PBNTR456fixedconftoastrailsautoclose5728 app/pb_kits/playbook/pb_copy_button/copy_button.test.jsx
playbook_ui-14.12.0.pre.alpha.play1862buttondisabledlinkbug5716 app/pb_kits/playbook/pb_copy_button/copy_button.test.jsx
playbook_ui-14.12.0.pre.alpha.play1862buttondisabledlinkbug5714 app/pb_kits/playbook/pb_copy_button/copy_button.test.jsx
playbook_ui-14.13.0.pre.rc.2 app/pb_kits/playbook/pb_copy_button/copy_button.test.jsx
playbook_ui-14.13.0.pre.rc.1 app/pb_kits/playbook/pb_copy_button/copy_button.test.jsx