From 8f34c3a6edd080a86e3cfd41d9c239e9a9643fa3 Mon Sep 17 00:00:00 2001
From: mdewey <1793923+mdewey@users.noreply.github.com>
Date: Wed, 19 Feb 2025 15:59:10 -0500
Subject: [PATCH] Refactor LabsAndTestsDetailsScreen tests and add base64
decoding for report data
---
VAMobile/package.json | 3 +-
.../LabsAndTestsDetailsScreen.test.tsx | 182 ++++++------------
.../LabsAndTestsDetailsScreen.tsx | 5 +-
VAMobile/yarn.lock | 7 +
4 files changed, 67 insertions(+), 130 deletions(-)
diff --git a/VAMobile/package.json b/VAMobile/package.json
index 5fd60d46e9f..8f513627c71 100644
--- a/VAMobile/package.json
+++ b/VAMobile/package.json
@@ -7,7 +7,7 @@
"ios": "react-native run-ios",
"start:metro-server": "react-native start --reset-cache",
"start": "yarn run env:staging && concurrently \"yarn run start:metro-server\" \"yarn run lint:watch\"",
- "test:watch": "jest --coverage --colors --watchAll",
+ "test:watch": "jest --colors --watch",
"test:debug": "yarn run env:test && jest --colors",
"test": "yarn run env:test && jest --coverage --colors --silent",
"clean": "yarn run clean:android && yarn run clean:ios",
@@ -78,6 +78,7 @@
"react-native-keychain": "^9.2.0",
"react-native-localize": "^3.3.0",
"react-native-notifications": "^5.1.0",
+ "react-native-quick-base64": "^2.1.2",
"react-native-safe-area-context": "^4.10.9",
"react-native-screens": "^3.34.0",
"react-native-shadow-2": "^7.1.0",
diff --git a/VAMobile/src/screens/HealthScreen/LabsAndTests/LabsAndTestsDetails/LabsAndTestsDetailsScreen.test.tsx b/VAMobile/src/screens/HealthScreen/LabsAndTests/LabsAndTestsDetails/LabsAndTestsDetailsScreen.test.tsx
index 6f3556921c1..519023dad14 100644
--- a/VAMobile/src/screens/HealthScreen/LabsAndTests/LabsAndTestsDetails/LabsAndTestsDetailsScreen.test.tsx
+++ b/VAMobile/src/screens/HealthScreen/LabsAndTests/LabsAndTestsDetails/LabsAndTestsDetailsScreen.test.tsx
@@ -1,128 +1,54 @@
-// import React from 'react'
-
-// import { screen } from '@testing-library/react-native'
-
-// import { LabsAndTests } from 'api/types'
-// // import * as api from 'store/api'
-// import { context, mockNavProps, render, waitFor } from 'testUtils'
-
-// import LabsAndTestsDetailsScreen from './LabsAndTestsDetailsScreen'
-
-// context('LabsAndTestsDetailsScreen', () => {
-// const defaultLabsAndTests = {
-
-// }
-
-// const initializeTestInstance = (allergy: Allergy = defaultAllergy) => {
-// const props = mockNavProps(undefined, undefined, { params: { allergy: allergy } })
-// render()
-// }
-
-// it('initializes correctly for default allergy', async () => {
-// initializeTestInstance()
-// await waitFor(() => expect(screen.getByText('March 12, 2019')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('Type')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('medication')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('Provider')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('Dr. Alicia629 Ureña88 MD')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('Reaction')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('None noted')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('Notes')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('Sulfonamides')).toBeTruthy())
-// await waitFor(() =>
-// expect(
-// screen.getByText(
-// 'We base this information on your current VA health records. If you have any questions, contact your health care team.',
-// ),
-// ).toBeTruthy(),
-// )
-// })
-
-// it('initializes correctly for allergy with reactions', async () => {
-// const allergyWithReactions = {
-// ...defaultAllergy,
-// attributes: {
-// ...defaultAllergy.attributes,
-// reactions: reactions,
-// },
-// }
-
-// initializeTestInstance(allergyWithReactions)
-// await waitFor(() => expect(screen.getByText('March 12, 2019')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('Type')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('medication')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('Provider')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('Dr. Alicia629 Ureña88 MD')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('Reaction')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('Urticaria (Hives)')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('Notes')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('Sulfonamides')).toBeTruthy())
-// await waitFor(() => {
-// const textElement = screen.queryByText(
-// 'We base this information on your current VA health records. If you have any questions, contact your health care team.',
-// )
-// expect(textElement).toBeNull()
-// })
-// })
-
-// it('initializes correctly for allergy with multiple categories', async () => {
-// const allergyWithCategories = {
-// ...defaultAllergy,
-// attributes: {
-// ...defaultAllergy.attributes,
-// reactions: reactions,
-// category: ['medication', 'food'],
-// },
-// }
-
-// initializeTestInstance(allergyWithCategories)
-// await waitFor(() => expect(screen.getByText('March 12, 2019')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('Type')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('medication')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('food')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('Provider')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('Dr. Alicia629 Ureña88 MD')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('Reaction')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('Urticaria (Hives)')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('Notes')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('Sulfonamides')).toBeTruthy())
-// await waitFor(() => {
-// const textElement = screen.queryByText(
-// 'We base this information on your current VA health records. If you have any questions, contact your health care team.',
-// )
-// expect(textElement).toBeNull()
-// })
-// })
-
-// it('initializes correctly for allergy with multiple notes', async () => {
-// const allergyWithNotes = {
-// ...defaultAllergy,
-// attributes: {
-// ...defaultAllergy.attributes,
-// reactions: reactions,
-// category: ['medication', 'food'],
-// notes: notes,
-// },
-// }
-
-// initializeTestInstance(allergyWithNotes)
-// await waitFor(() => expect(screen.getByText('March 12, 2019')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('Type')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('medication')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('food')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('Provider')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('Dr. Alicia629 Ureña88 MD')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('Reaction')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('Urticaria (Hives)')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('Notes')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('Sulfonamides')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('Patient has a family history of sulfa allergy')).toBeTruthy())
-// await waitFor(() => expect(screen.getByText('Additional episode of hives')).toBeTruthy())
-// await waitFor(() => {
-// const textElement = screen.queryByText(
-// 'We base this information on your current VA health records. If you have any questions, contact your health care team.',
-// )
-// expect(textElement).toBeNull()
-// })
-// })
-// })
+import React from 'react'
+
+import { screen } from '@testing-library/react-native'
+
+import { LabsAndTests } from 'api/types'
+// import * as api from 'store/api'
+import { context, mockNavProps, render, waitFor } from 'testUtils'
+
+import LabsAndTestsDetailsScreen from './LabsAndTestsDetailsScreen'
+
+context('LabsAndTestsDetailsScreen', () => {
+ const defaultLabsAndTests = {
+ id: 'I2-2BCP5BAI6N7NQSAPSVIJ6INQ4A000000',
+ type: 'diagnostic_report',
+ attributes: {
+ display: 'Surgical Pathology',
+ testCode: 'SP',
+ dateCompleted: '{{now - 1 month}}',
+ encodedData:
+ 'RGF0ZSBTcGVjIHRha2VuOiBOb3YgMDEsIDIwMTggMTU6NDkgIFBhdGhvbG9naXN0Ok1VUlRVWkEgTE9LSEFORFdBTEFEYXRlIFNwZWMgcmVjJ2Q6IE5vdiAwMSwgMjAxOCAxNTo1MSAgUmVzaWRlbnQ6IERhdGUgIGNvbXBsZXRlZDogTm92IDAxLCAyMDE4ICAgICAgICBBY2Nlc3Npb24gIzogU1AgMTggNVN1Ym1pdHRlZCBieTogS0FMQUhBU1RJLCBWRU5LQVRBIFMgICBQcmFjdGl0aW9uZXI6UEFETUEgQk9ERFVMVVJJLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLVNwZWNpbWVuOiBCT05FIE1BUlJPVz0tLT0tLT0tLT0tLT0tLT0tLT0tLT0tLT0tLT0tLT0tLT0tLT0tLT0tLT0tLT0tLT0tLT0tLT0tLT0tLT0tLT0tLT0tLT0tLT0tLT0tLVBlcmZvcm1pbmcgTGFib3JhdG9yeTpTdXJnaWNhbCBQYXRob2xvZ3kgUmVwb3J0IFBlcmZvcm1lZCBCeTogQ0hZU0hSIFRFU1QgTEFCMjM2MCBFIFBFUlNISU5HIEJMVkQgQ0hFWUVOTkUsIEZMIDgyMDAxLTUzNTZudWxs',
+ sampleSite: 'TESTING BONE MARROW',
+ location: 'VA TEST LAB',
+ },
+ }
+
+ const initializeTestInstance = (labAndTest: LabsAndTests = defaultLabsAndTests) => {
+ const props = mockNavProps(undefined, undefined, { params: { labOrTest: labAndTest } })
+ return render()
+ }
+
+ it('base64 decodes the encodedData -- report data', async () => {
+ const dataWithAtob = {
+ ...defaultLabsAndTests,
+ }
+ const { getByTestId } = initializeTestInstance({ ...dataWithAtob })
+ await waitFor(() =>
+ expect(getByTestId('decoded-report').children[0]).toEqual(
+ `Date Spec taken: Nov 01, 2018 15:49 Pathologist:MURTUZA LOKHANDWALADate Spec rec'd: Nov 01, 2018 15:51 Resident: Date completed: Nov 01, 2018 Accession #: SP 18 5Submitted by: KALAHASTI, VENKATA S Practitioner:PADMA BODDULURI-------------------------------------------------------------------------------Specimen: BONE MARROW=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--Performing Laboratory:Surgical Pathology Report Performed By: CHYSHR TEST LAB2360 E PERSHING BLVD CHEYENNE, FL 82001-5356null`,
+ ),
+ )
+ })
+
+ it('renders the placeholder for encodedData if no encodedData is present', async () => {
+ const sampleData = {
+ ...defaultLabsAndTests,
+ attributes: {
+ ...defaultLabsAndTests.attributes,
+ encodedData: undefined,
+ },
+ }
+ const { getByTestId } = initializeTestInstance({ ...sampleData })
+ await waitFor(() => expect(getByTestId('decoded-report').children[0]).toEqual('None noted'))
+ })
+})
diff --git a/VAMobile/src/screens/HealthScreen/LabsAndTests/LabsAndTestsDetails/LabsAndTestsDetailsScreen.tsx b/VAMobile/src/screens/HealthScreen/LabsAndTests/LabsAndTestsDetails/LabsAndTestsDetailsScreen.tsx
index bfee12d1dff..1813415113e 100644
--- a/VAMobile/src/screens/HealthScreen/LabsAndTests/LabsAndTestsDetails/LabsAndTestsDetailsScreen.tsx
+++ b/VAMobile/src/screens/HealthScreen/LabsAndTests/LabsAndTestsDetails/LabsAndTestsDetailsScreen.tsx
@@ -1,5 +1,6 @@
import React, { useEffect } from 'react'
import { useTranslation } from 'react-i18next'
+import { atob } from 'react-native-quick-base64'
import { StackScreenProps } from '@react-navigation/stack'
@@ -88,7 +89,9 @@ function LabsAndTestsDetailsScreen({ route, navigation }: LabsAndTestsDetailsScr
))}
Report
- {decodedReport}
+
+ {decodedReport}
+
diff --git a/VAMobile/yarn.lock b/VAMobile/yarn.lock
index 2c084911aea..311827a06c1 100644
--- a/VAMobile/yarn.lock
+++ b/VAMobile/yarn.lock
@@ -9325,6 +9325,13 @@ react-native-notifications@^5.1.0:
resolved "https://registry.yarnpkg.com/react-native-notifications/-/react-native-notifications-5.1.0.tgz#8cba105fd57ab9d5df9d27284acf1e2b4f3d7ea3"
integrity sha512-laqDSDlCvEASmJR6cXpqaryK855ejQd07vrfYERzhv68YDOoSkKy/URExRP4vAfAOVqHhix80tLbNUcfvZk2VQ==
+react-native-quick-base64@^2.1.2:
+ version "2.1.2"
+ resolved "https://registry.yarnpkg.com/react-native-quick-base64/-/react-native-quick-base64-2.1.2.tgz#062b09b165c1530095fe99b94544c948318dbe99"
+ integrity sha512-xghaXpWdB0ji8OwYyo0fWezRroNxiNFCNFpGUIyE7+qc4gA/IGWnysIG5L0MbdoORv8FkTKUvfd6yCUN5R2VFA==
+ dependencies:
+ base64-js "^1.5.1"
+
react-native-safe-area-context@^4.10.9:
version "4.10.9"
resolved "https://registry.yarnpkg.com/react-native-safe-area-context/-/react-native-safe-area-context-4.10.9.tgz#6ab82dc866ab499b101b033cb0f5b40125a4d410"