From f254577283eb3714a75ff4be1e7ef14b9d9c570a Mon Sep 17 00:00:00 2001 From: kolbyVA Date: Fri, 4 Oct 2024 16:25:11 -0500 Subject: [PATCH] Added Unit Tests --- .../components/AttachmentsList.jsx | 2 +- .../Compose/AttachmentsList.unit.spec.jsx | 60 ++++++++++++++++++- 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/src/applications/mhv-secure-messaging/components/AttachmentsList.jsx b/src/applications/mhv-secure-messaging/components/AttachmentsList.jsx index 7e821c4ab1da..244088642235 100644 --- a/src/applications/mhv-secure-messaging/components/AttachmentsList.jsx +++ b/src/applications/mhv-secure-messaging/components/AttachmentsList.jsx @@ -69,7 +69,7 @@ const AttachmentsList = props => { useEffect( () => { - const alertButton = attachFileAlertRef?.current?.shadowRoot.querySelector( + const alertButton = attachFileAlertRef?.current?.shadowRoot?.querySelector( '#close-success-alert-button', ); if (attachFileSuccess && alertButton) { diff --git a/src/applications/mhv-secure-messaging/tests/components/Compose/AttachmentsList.unit.spec.jsx b/src/applications/mhv-secure-messaging/tests/components/Compose/AttachmentsList.unit.spec.jsx index 4c400e2b437e..d97eb7f00882 100644 --- a/src/applications/mhv-secure-messaging/tests/components/Compose/AttachmentsList.unit.spec.jsx +++ b/src/applications/mhv-secure-messaging/tests/components/Compose/AttachmentsList.unit.spec.jsx @@ -6,7 +6,7 @@ import triageTeams from '../../fixtures/recipients.json'; import categories from '../../fixtures/categories-response.json'; import reducer from '../../../reducers'; import ComposeForm from '../../../components/ComposeForm/ComposeForm'; -import { Paths } from '../../../util/constants'; +import { Paths, Alerts } from '../../../util/constants'; import noBlockedRecipients from '../../fixtures/json-triage-mocks/triage-teams-mock.json'; import AttachmentsList from '../../../components/AttachmentsList'; @@ -204,10 +204,64 @@ describe('Attachments List component', () => { 'http://127.0.0.1:3000/my_health/v1/messaging/messages/2664846/attachments/2664842', }, ], - attachmentScanError: false, + attachmentScanError: true, + editingEnabled: true, }; - const screen = setup(initialState, Paths.COMPOSE, customProps); + const screen = renderWithStoreAndRouter( + , + { + initialState, + reducers: reducer, + path: Paths.MESSAGE_THREAD, + }, + ); expect(screen.findByTestId('attachment-virus-alert')).to.exist; + expect(screen.getByText(Alerts.Message.ATTACHMENT_SCAN_FAIL)).to.exist; + }); + + it('renders error message when multiple attachments contain a virus', async () => { + const customProps = { + attachments: [ + { + id: 2664842, + messageId: 2664846, + name: 'BIRD 1.gif', + attachmentSize: 31127, + download: + 'http://127.0.0.1:3000/my_health/v1/messaging/messages/2664846/attachments/2664842', + }, + { + id: 2664843, + messageId: 2664846, + name: 'BIRD 2.gif', + attachmentSize: 31138, + download: + 'http://127.0.0.1:3000/my_health/v1/messaging/messages/2664846/attachments/2664843', + }, + ], + attachmentScanError: true, + editingEnabled: true, + }; + const screen = renderWithStoreAndRouter( + , + { + initialState, + reducers: reducer, + path: Paths.MESSAGE_THREAD, + }, + ); + + expect(screen.findByTestId('attachment-virus-alert')).to.exist; + expect( + screen.getByText( + 'One or more of the files you attached has a virus. You’ll need to remove it to send your message.', + ), + ).to.exist; + + const removeAllAttachments = await screen.findByTestId( + 'remove-all-attachments-button', + ); + expect(removeAllAttachments).to.exist; }); });