From cbef30e59464b04b78da67f5f26148dd2b7e8f2f Mon Sep 17 00:00:00 2001 From: William Medders Date: Wed, 23 Oct 2024 16:20:52 -0500 Subject: [PATCH] jest test for ErrorsFoundAndCorrectedModal --- .../ErrorsFoundAndCorrectedModal.test.js | 93 +++++++++++ .../ErrorsFoundAndCorrectedModal.test.js.snap | 146 ++++++++++++++++++ 2 files changed, 239 insertions(+) create mode 100644 client/test/app/hearings/components/ErrorsFoundAndCorrectedModal.test.js create mode 100644 client/test/app/hearings/components/__snapshots__/ErrorsFoundAndCorrectedModal.test.js.snap diff --git a/client/test/app/hearings/components/ErrorsFoundAndCorrectedModal.test.js b/client/test/app/hearings/components/ErrorsFoundAndCorrectedModal.test.js new file mode 100644 index 00000000000..d88464d8400 --- /dev/null +++ b/client/test/app/hearings/components/ErrorsFoundAndCorrectedModal.test.js @@ -0,0 +1,93 @@ +import React from 'react'; +import { render, screen, waitFor } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import { axe } from 'jest-axe'; + +import ErrorsFoundAndCorrectedModal from 'app/hearings/components/ErrorsFoundAndCorrectedModal'; + +describe('ErrorsFoundAndCorrectedModal', () => { + const closeModal = jest.fn(); + + const defaultProps = { + taskId: '1000', + closeModal + }; + + it('renders correctly', () => { + const { container } = render(); + + expect(container).toMatchSnapshot(); + }); + + it('passes a11y testing', async () => { + const { container } = render(); + + const results = await axe(container); + + expect(results).toHaveNoViolations(); + }); + + it('displays the default page elements with default props', () => { + render( + + ); + + const textarea = screen.getByRole('textbox'); + + expect(screen.getByText('Upload transcript to VBMS')).toBeInTheDocument(); + expect(screen.getByText('Please upload the revised transcript file for upload to VBMS.')). + toBeInTheDocument(); + expect(screen.getByText('Please select PDF')).toBeInTheDocument(); + expect(screen.getByText('Choose from folder')).toBeInTheDocument(); + expect(screen.getByText('Please provide context and instructions for this action')). + toBeInTheDocument(); + expect(textarea.value).toBe(''); + }); + + it('can handle a file upload', async () => { + const file = new File(['test'], 'test.pdf', { type: 'application/pdf' }); + + render( + + ); + + const input = screen.getByLabelText(/Choose from folder/i); + + userEvent.upload(input, file); + + await waitFor(() => { + expect(input.files.length).toBe(1); + expect(screen.getByText('test.pdf')).toBeInTheDocument(); + expect(screen.getByText('Selected file')).toBeInTheDocument(); + expect(screen.getByText('Change file')).toBeInTheDocument(); + }); + }); + + it('the submit button is enabled when fields filled out', async () => { + const file = new File(['test'], 'test.pdf', { type: 'application/pdf' }); + + render( + + ); + + expect(screen.getByText('Upload to VBMS').closest('button')). + toBeDisabled(); + + const input = screen.getByLabelText(/Choose from folder/i); + const textarea = screen.getByRole('textbox'); + + userEvent.upload(input, file); + + await waitFor(() => { + expect(screen.getByText('Upload to VBMS').closest('button')). + toBeDisabled(); + }); + + userEvent.type(textarea, 'This is a note.'); + + await waitFor(() => { + expect(screen.getByText('Upload to VBMS').closest('button')). + toBeEnabled(); + }); + }); +}); diff --git a/client/test/app/hearings/components/__snapshots__/ErrorsFoundAndCorrectedModal.test.js.snap b/client/test/app/hearings/components/__snapshots__/ErrorsFoundAndCorrectedModal.test.js.snap new file mode 100644 index 00000000000..852097188e2 --- /dev/null +++ b/client/test/app/hearings/components/__snapshots__/ErrorsFoundAndCorrectedModal.test.js.snap @@ -0,0 +1,146 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ErrorsFoundAndCorrectedModal renders correctly 1`] = ` +
+