import React from 'react'; import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { Label } from '../Label'; const labelColors = ['blue', 'cyan', 'green', 'orange', 'purple', 'red', 'grey']; describe('Label', () => { test('renders', () => { const { asFragment } = render(); expect(asFragment()).toMatchSnapshot(); }); test('renders with outline variant', () => { const { asFragment } = render(); expect(asFragment()).toMatchSnapshot(); }); test('renders with isCompact', () => { const { asFragment } = render(); expect(asFragment()).toMatchSnapshot(); }); test('label with href', () => { const { asFragment } = render(); expect(asFragment()).toMatchSnapshot(); }); test('label with href with outline variant', () => { const { asFragment } = render( ); expect(asFragment()).toMatchSnapshot(); }); test('label with close button', () => { const { asFragment } = render(); expect(asFragment()).toMatchSnapshot(); }); test('label with close button and outline variant', () => { const { asFragment } = render( ); expect(asFragment()).toMatchSnapshot(); }); labelColors.forEach((color: string) => test(`label with ${color} color`, () => { const { asFragment } = render(); expect(asFragment()).toMatchSnapshot(); }) ); labelColors.forEach((color: string) => test(`label with ${color} color with outline variant`, () => { const { asFragment } = render( ); expect(asFragment()).toMatchSnapshot(); }) ); test('label with additional class name', () => { const { asFragment } = render(); expect(asFragment()).toMatchSnapshot(); }); test('label with additional class name and props', () => { const { asFragment } = render( ); expect(asFragment()).toMatchSnapshot(); }); test('label with truncation', () => { const { asFragment } = render( ); expect(asFragment()).toMatchSnapshot(); }); test('editable label', async () => { const user = userEvent.setup(); const { asFragment } = render( ); const button = screen.getByRole('button', { name: 'Something' }); expect(button).toBeInTheDocument(); expect(asFragment()).toMatchSnapshot(); await user.click(button); expect(screen.queryByRole('button', { name: 'Something' })).toBeNull(); expect(asFragment()).toMatchSnapshot(); }); });