Skip to content

Commit

Permalink
Refactor LabsAndTestsDetailsScreen tests and add base64 decoding for …
Browse files Browse the repository at this point in the history
…report data
  • Loading branch information
mdewey committed Feb 19, 2025
1 parent 572787a commit 8f34c3a
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 130 deletions.
3 changes: 2 additions & 1 deletion VAMobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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(<AllergyDetailsScreen {...props} />)
// }

// 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'

Check warning on line 3 in VAMobile/src/screens/HealthScreen/LabsAndTests/LabsAndTestsDetails/LabsAndTestsDetailsScreen.test.tsx

View workflow job for this annotation

GitHub Actions / lint

'screen' is defined but never used

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(<LabsAndTestsDetailsScreen {...props} />)
}

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'))
})
})
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -88,7 +89,9 @@ function LabsAndTestsDetailsScreen({ route, navigation }: LabsAndTestsDetailsScr
))}
<Box accessibilityRole="header" accessible={true} mb={standardMarginBetween}>
<TextView variant="MobileBodyBold">Report</TextView>
<TextView variant="MobileBody">{decodedReport}</TextView>
<TextView variant="MobileBody" testID="decoded-report">
{decodedReport}
</TextView>
</Box>
</TextArea>
</Box>
Expand Down
7 changes: 7 additions & 0 deletions VAMobile/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 8f34c3a

Please sign in to comment.