import { render, screen } from '@testing-library/react'; import '@testing-library/jest-dom'; import userEvent from '@testing-library/user-event'; import TermsOfUse from './TermsOfUse'; import { Content } from '@patternfly/react-core'; const handleModalToggle = jest.fn(); const onPrimaryAction = jest.fn(); const onSecondaryAction = jest.fn(); const body = (

Heading 1

Legal text

); describe('TermsOfUse', () => { afterEach(() => { jest.clearAllMocks(); }); it('should render modal correctly', () => { render( {body} ); expect(screen.getByRole('heading', { name: /Terms of use/i })).toBeTruthy(); expect(screen.getByRole('button', { name: /Accept/i })).toBeTruthy(); expect(screen.getByRole('button', { name: /Decline/i })).toBeTruthy(); expect(screen.getByRole('heading', { name: /Heading 1/i })).toBeTruthy(); expect(screen.getByText(/Legal text/i)).toBeTruthy(); expect(screen.getByRole('dialog')).toHaveClass('pf-chatbot__terms-of-use-modal'); expect(screen.getByRole('dialog')).toHaveClass('pf-chatbot__terms-of-use-modal--default'); }); it('should handle image and altText props', () => { render( {body} ); expect(screen.getByRole('img')).toBeTruthy(); expect(screen.getByRole('img')).toHaveAttribute('alt', 'Test image'); }); it('should handle className prop', () => { render( {body} ); expect(screen.getByRole('dialog')).toHaveClass('pf-chatbot__terms-of-use-modal'); expect(screen.getByRole('dialog')).toHaveClass('pf-chatbot__terms-of-use-modal--default'); expect(screen.getByRole('dialog')).toHaveClass('test'); }); it('should handle title prop', () => { render( {body} ); expect(screen.getByRole('heading', { name: /Updated title/i })).toBeTruthy(); expect(screen.queryByRole('heading', { name: /Terms of use/i })).toBeFalsy(); }); it('should handle primary button prop', () => { render( {body} ); expect(screen.getByRole('button', { name: /First/i })).toBeTruthy(); expect(screen.queryByRole('button', { name: /Accept/i })).toBeFalsy(); }); it('should handle secondary button prop', () => { render( {body} ); expect(screen.getByRole('button', { name: /Second/i })).toBeTruthy(); expect(screen.queryByRole('button', { name: /Deny/i })).toBeFalsy(); }); it('should handle primary button click', async () => { render( {body} ); await userEvent.click(screen.getByRole('button', { name: /Accept/i })); expect(onPrimaryAction).toHaveBeenCalledTimes(1); expect(handleModalToggle).toHaveBeenCalledTimes(1); }); it('should handle secondary button click', async () => { render( {body} ); await userEvent.click(screen.getByRole('button', { name: /Decline/i })); expect(onSecondaryAction).toHaveBeenCalledTimes(1); expect(handleModalToggle).not.toHaveBeenCalled(); }); });