import { render, screen } from '@testing-library/react'; import '@testing-library/jest-dom'; import { Card } from '../Card'; import { createRef } from 'react'; describe('Card', () => { test('renders with PatternFly Core styles', () => { const { asFragment } = render(); expect(asFragment()).toMatchSnapshot(); }); test('className is added to the root element', () => { render(card); expect(screen.getByText('card')).toHaveClass('extra-class'); }); test('extra props are spread to the root element', () => { const testId = 'card'; render(); expect(screen.getByTestId(testId)).toBeInTheDocument(); }); test('allows passing in a string as the component', () => { const component = 'section'; render(section content); expect(screen.getByText('section content')).toBeInTheDocument(); }); test('allows passing in a React Component as the component', () => { const Component = () =>
im a div
; render(); expect(screen.getByText('im a div')).toBeInTheDocument(); }); test('card with isCompact applied ', () => { const { asFragment } = render(); expect(asFragment()).toMatchSnapshot(); }); test('card with isSelectable applied ', () => { render(selectable card); const card = screen.getByText('selectable card'); expect(card).toHaveClass('pf-m-selectable'); }); test('card with isSelectable and isSelected applied ', () => { render( selected and selectable card ); const card = screen.getByText('selected and selectable card'); expect(card).toHaveClass('pf-m-selectable'); expect(card).toHaveClass('pf-m-selected'); }); test('card with only isSelected applied - not change', () => { render(selected card); const card = screen.getByText('selected card'); expect(card).not.toHaveClass('pf-m-selected'); expect(card.getAttribute('tabindex')).toBeNull(); }); test('card with isExpanded applied', () => { render(expanded card); expect(screen.getByText('expanded card')).toHaveClass('pf-m-expanded'); }); test('card with isLarge applied', () => { render(large card); expect(screen.getByText('large card')).toHaveClass('pf-m-display-lg'); }); test('card warns when isLarge and isCompact', () => { const consoleWarnMock = jest.fn(); global.console = { warn: consoleWarnMock } as any; render(); expect(consoleWarnMock).toHaveBeenCalled(); }); test('card with isGlass applied', () => { render(glass card); expect(screen.getByText('glass card')).toHaveClass('pf-m-glass'); }); test('card with variant set to secondary ', () => { render(secondary card); const card = screen.getByText('secondary card'); expect(card).toHaveClass('pf-m-secondary'); }); test('ref is added to the root element', () => { const ref = createRef(); render( card ); expect(ref.current).toBe(screen.getByText('card')); }); });