import { screen, render } from '@testing-library/react'; import { ClipboardCopyExpanded } from '../ClipboardCopyExpanded'; import styles from '@patternfly/react-styles/css/components/ClipboardCopy/clipboard-copy'; import userEvent from '@testing-library/user-event'; test(`Renders with classname ${styles.clipboardCopyExpandableContent} by default`, () => { render(Expanded content); expect(screen.getByText('Expanded content')).toHaveClass(styles.clipboardCopyExpandableContent, { exact: true }); }); test(`Renders with custom class when className is passed`, () => { render(Expanded content); expect(screen.getByText('Expanded content')).toHaveClass('test-class'); }); test('Does not render with
 tag by default', () => {
  render(Expanded content);

  expect(screen.getByText('Expanded content').tagName).not.toBe('PRE');
});

test('Renders with 
 tag when isCode is true', () => {
  render(Expanded content);

  expect(screen.getByText('Expanded content').tagName).toBe('PRE');
});

test('Renders with contenteditable attribute of true by default', () => {
  render(Expanded content);

  expect(screen.getByText('Expanded content')).toHaveAttribute('contenteditable', 'true');
});

test('Renders with contenteditable attribute of false when isReadOnly is passed', () => {
  render(Expanded content);

  expect(screen.getByText('Expanded content')).toHaveAttribute('contenteditable', 'false');
});

test('Calls onChange when expanded content is typed in', async () => {
  const user = userEvent.setup();
  const onChangeMock = jest.fn();

  render(Expanded content);

  await user.type(screen.getByText('Expanded content'), 's');

  expect(onChangeMock).toHaveBeenCalledTimes(1);
});

test('Does not call onChange when expanded content is not typed in', async () => {
  const user = userEvent.setup();
  const onChangeMock = jest.fn();

  render(
    <>
      Expanded content
      
    
  );

  await user.type(screen.getByRole('textbox'), 'A');

  expect(onChangeMock).not.toHaveBeenCalled();
});

test('Spreads additional props to container', () => {
  render(Expanded content);

  expect(screen.getByText('Expanded content')).toHaveAttribute('data-prop', 'test');
});

test('Matches snapshot', () => {
  const { asFragment } = render(Expanded content);

  expect(asFragment()).toMatchSnapshot();
});