|
| 1 | +import React from 'react'; |
| 2 | + |
| 3 | +import { render, screen } from '@testing-library/react'; |
| 4 | +import { WizardHeader } from '../WizardHeader'; |
| 5 | +import userEvent from '@testing-library/user-event'; |
| 6 | + |
| 7 | +// close button related tests |
| 8 | +test(`Renders close button by default`, () => { |
| 9 | + render(<WizardHeader data-testid="header-component" />); |
| 10 | + expect(screen.getByRole('button')).toBeInTheDocument(); |
| 11 | +}); |
| 12 | + |
| 13 | +test(`Close button is hidden when isCloseHidden is passed`, () => { |
| 14 | + render(<WizardHeader isCloseHidden />); |
| 15 | + expect(screen.queryByRole('button')).toBeNull(); |
| 16 | +}); |
| 17 | + |
| 18 | +test(`Close button renders passed aria label`, () => { |
| 19 | + render(<WizardHeader closeButtonAriaLabel="test aria label" />); |
| 20 | + expect(screen.getByRole('button', { name: 'test aria label' })).toBeInTheDocument(); |
| 21 | +}); |
| 22 | + |
| 23 | +test(`Callback function fires when onClose passed`, async () => { |
| 24 | + const onClose = jest.fn(); |
| 25 | + const user = userEvent.setup(); |
| 26 | + render(<WizardHeader onClose={onClose} />); |
| 27 | + await user.click(screen.getByRole('button')); |
| 28 | + expect(onClose).toHaveBeenCalled(); |
| 29 | +}); |
| 30 | + |
| 31 | +// description related tests |
| 32 | +test(`Renders a description when passed description`, () => { |
| 33 | + render(<WizardHeader description="test description" />); |
| 34 | + expect(screen.getByText('test description')).toBeVisible(); |
| 35 | +}); |
| 36 | + |
| 37 | +test(`Renders the id passed via descriptionId`, () => { |
| 38 | + render(<WizardHeader description="test description" descriptionId="test-id" />); |
| 39 | + expect(screen.queryByText('test description')).toHaveAttribute('id', 'test-id'); |
| 40 | +}); |
| 41 | + |
| 42 | +// other prop tests |
| 43 | +test(`Renders title when prop is passed`, () => { |
| 44 | + render(<WizardHeader title="Test" />); |
| 45 | + expect(screen.getByText('Test')).toBeVisible(); |
| 46 | +}); |
| 47 | + |
| 48 | +test(`Renders with additional classes when className is passed`, () => { |
| 49 | + render(<WizardHeader className="custom-class" data-testid="header-component" />); |
| 50 | + expect(screen.getByTestId('header-component')).toHaveClass('custom-class'); |
| 51 | +}); |
0 commit comments