Skip to content

Commit

Permalink
syphilis card support pt 3 (#7674)
Browse files Browse the repository at this point in the history
* moving code around

* fix some stuff

* fix some stuff

* fix test card issue

* use centralized aoe component hooks

* fix test

* submission mock improvement

* simplify mock generation

* .only removal

* dedupe test constants

* use generation code for mocks in test card test

* add in mock generation utils for the test card

* make diff smaller

* lint

* remove specific function strategies in favor of general one

* replace respiratory bools too

* lint

* fix copy paste
  • Loading branch information
fzhao99 committed May 17, 2024
1 parent 97b7efa commit 2aef352
Show file tree
Hide file tree
Showing 13 changed files with 879 additions and 1,048 deletions.
743 changes: 131 additions & 612 deletions frontend/src/app/testQueue/TestCard/TestCard.test.tsx

Large diffs are not rendered by default.

208 changes: 16 additions & 192 deletions frontend/src/app/testQueue/TestCardForm/TestCardForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,194 +2,34 @@ import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { MockedProvider } from "@apollo/client/testing";

import { getAppInsights } from "../../TelemetryService";
import * as srToast from "../../utils/srToast";
import { PhoneType } from "../../../generated/graphql";
import mockSupportedDiseaseCovid from "../mocks/mockSupportedDiseaseCovid";
import mockSupportedDiseaseMultiplex, {
mockSupportedDiseaseFlu,
} from "../mocks/mockSupportedDiseaseMultiplex";

import TestCardForm, { TestCardFormProps } from "./TestCardForm";
import { QueriedFacility, QueriedTestOrder } from "./types";
import {
asymptomaticTestOrderInfo,
covidDeviceId,
covidDeviceName,
devicesMap,
facilityInfo,
fluDeviceId,
fluDeviceName,
hivDeviceId,
hivDeviceName,
multiplexDeviceId,
multiplexDeviceName,
} from "./testUtils/testConstants";

jest.mock("../../TelemetryService", () => ({
getAppInsights: jest.fn(),
}));

const setStartTestPatientIdMock = jest.fn();

const covidDeviceName = "LumiraDX";
const multiplexDeviceName = "Multiplex";
const multiplexAndCovidOnlyDeviceName = "MultiplexAndCovidOnly";
const fluDeviceName = "FLU";
const hivDeviceName = "HIV";

const covidDeviceId = "COVID-DEVICE-ID";
const multiplexDeviceId = "MULTIPLEX-DEVICE-ID";
const multiplexAndCovidOnlyDeviceId = "MULTIPLEX-COVID-DEVICE-ID";
const fluDeviceId = "FLU-DEVICE-ID";
const hivDeviceId = "HIV-DEVICE-ID";

const specimen1Name = "Swab of internal nose";
const specimen1Id = "SPECIMEN-1-ID";
const specimen2Name = "Nasopharyngeal swab";
const specimen2Id = "SPECIMEN-2-ID";

describe("TestCardForm", () => {
let nowFn = Date.now;
let alertSpy: jest.SpyInstance;
const trackEventMock = jest.fn();
const trackMetricMock = jest.fn();
const trackExceptionMock = jest.fn();

const testOrderInfo: QueriedTestOrder = {
internalId: "1b02363b-ce71-4f30-a2d6-d82b56a91b39",
dateAdded: "2022-11-08 13:33:07.503",
symptoms:
'{"64531003":"false","103001002":"false","84229001":"false","68235000":"false","426000000":"false","49727002":"false","68962001":"false","422587007":"false","267036007":"false","62315008":"false","43724002":"false","36955009":"false","44169009":"false","422400008":"false","230145002":"false","25064002":"false","162397003":"false"}',
symptomOnset: null,
noSymptoms: true,
deviceType: {
internalId: multiplexDeviceId,
name: multiplexDeviceName,
model: multiplexDeviceName,
testLength: 15,
},
specimenType: {
internalId: specimen1Id,
name: specimen1Name,
typeCode: "445297001",
},
patient: {
internalId: "72b3ce1e-9d5a-4ad2-9ae8-e1099ed1b7e0",
telephone: "(571) 867-5309",
birthDate: "2015-09-20",
firstName: "Althea",
middleName: "Hedda Mclaughlin",
lastName: "Dixon",
gender: "refused",
testResultDelivery: null,
preferredLanguage: null,
email: "sywaporoce@mailinator.com",
emails: ["sywaporoce@mailinator.com"],
phoneNumbers: [
{
type: PhoneType.Mobile,
number: "(553) 223-0559",
},
{
type: PhoneType.Landline,
number: "(669) 789-0799",
},
],
},
results: [],
dateTested: null,
correctionStatus: "ORIGINAL",
reasonForCorrection: null,
};

const facilityInfo: QueriedFacility = {
id: "f02cfff5-1921-4293-beff-e2a5d03e1fda",
name: "Testing Site",
deviceTypes: [
{
internalId: covidDeviceId,
name: covidDeviceName,
testLength: 15,
supportedDiseaseTestPerformed: mockSupportedDiseaseCovid,
swabTypes: [
{
name: specimen1Name,
internalId: specimen1Id,
typeCode: "445297001",
},
{
name: specimen2Name,
internalId: specimen2Id,
typeCode: "258500001",
},
],
},
{
internalId: multiplexDeviceId,
name: multiplexDeviceName,
testLength: 15,
supportedDiseaseTestPerformed: mockSupportedDiseaseMultiplex,
swabTypes: [
{
name: specimen1Name,
internalId: specimen1Id,
typeCode: "445297001",
},
{
name: specimen2Name,
internalId: specimen2Id,
typeCode: "258500001",
},
],
},
{
internalId: fluDeviceId,
name: fluDeviceName,
testLength: 15,
supportedDiseaseTestPerformed: [...mockSupportedDiseaseFlu],
swabTypes: [
{
name: specimen1Name,
internalId: specimen1Id,
typeCode: "445297001",
},
{
name: specimen2Name,
internalId: specimen2Id,
typeCode: "258500001",
},
],
},
{
internalId: multiplexAndCovidOnlyDeviceId,
name: multiplexAndCovidOnlyDeviceName,
testLength: 15,
supportedDiseaseTestPerformed: [
...mockSupportedDiseaseFlu,
{
supportedDisease: mockSupportedDiseaseCovid[0].supportedDisease,
testPerformedLoincCode: "123456",
testOrderedLoincCode: "445566",
},
{
supportedDisease: mockSupportedDiseaseCovid[0].supportedDisease,
testPerformedLoincCode: "123456",
testOrderedLoincCode: "778899",
},
],
swabTypes: [
{
name: specimen1Name,
internalId: specimen1Id,
typeCode: "445297001",
},
{
name: specimen2Name,
internalId: specimen2Id,
typeCode: "258500001",
},
],
},
],
};

const devicesMap = new Map();
facilityInfo.deviceTypes.map((d) => devicesMap.set(d.internalId, d));

const testProps: TestCardFormProps = {
refetchQueue: jest.fn().mockReturnValue(null),
testOrder: testOrderInfo,
testOrder: asymptomaticTestOrderInfo,
facility: facilityInfo,
devicesMap: devicesMap,
startTestPatientId: "",
startTestPatientId: "f2dde6ff-52bc-4a6c-9946-f48724f46e6e",
setStartTestPatientId: setStartTestPatientIdMock,
};

Expand All @@ -198,9 +38,7 @@ describe("TestCardForm", () => {
mocks?: any;
};

async function renderTestCardForm(
{ props, mocks }: testRenderProps = { props: testProps, mocks: [] }
) {
async function renderTestCardForm({ props, mocks }: testRenderProps) {
props = props || testProps;
const view = render(
<>
Expand Down Expand Up @@ -228,25 +66,11 @@ describe("TestCardForm", () => {
}

beforeEach(() => {
(getAppInsights as jest.Mock).mockImplementation(() => ({
trackEvent: trackEventMock,
trackMetric: trackMetricMock,
trackException: trackExceptionMock,
}));
// jest.spyOn(console, "error").mockImplementation(() => {});
jest.spyOn(global.Math, "random").mockReturnValue(1);
alertSpy = jest.spyOn(srToast, "showError");
});

afterEach(() => {
Date.now = nowFn;
(getAppInsights as jest.Mock).mockReset();
jest.spyOn(console, "error").mockRestore();
jest.spyOn(global.Math, "random").mockRestore();
alertSpy.mockRestore();
});

afterAll(() => {
jest.restoreAllMocks();
});

Expand Down
20 changes: 11 additions & 9 deletions frontend/src/app/testQueue/TestCardForm/TestCardForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,18 @@ import {
TestCorrectionReason,
TestCorrectionReasons,
} from "../../testResults/viewResults/actionMenuModals/TestResultCorrectionModal";
import { PregnancyCode } from "../../../patientApp/timeOfTest/constants";
import {
PregnancyCode,
SyphilisHistoryCode,
} from "../../../patientApp/timeOfTest/constants";
import { QueueItemSubmitLoader } from "../QueueItemSubmitLoader";

import {
testCardFormReducer,
TestFormActionCase,
TestFormState,
} from "./TestCardFormReducer";
import CovidAoEForm, {
parseRespiratorySymptoms,
} from "./diseaseSpecificComponents/CovidAoEForm";
import CovidAoEForm from "./diseaseSpecificComponents/CovidAoEForm";
import {
AOEFormOption,
areAOEAnswersComplete,
Expand All @@ -53,6 +54,7 @@ import { TestResultInputGroup } from "./diseaseSpecificComponents/TestResultInpu
import { DevicesMap, QueriedFacility, QueriedTestOrder } from "./types";
import { IncompleteAOEWarningModal } from "./IncompleteAOEWarningModal";
import { HIVAoEForm } from "./diseaseSpecificComponents/HIVAoEForm";
import { stringifySymptomJsonForAoeUpdate } from "./diseaseSpecificComponents/aoeUtils";

const DEBOUNCE_TIME = 300;

Expand Down Expand Up @@ -82,9 +84,10 @@ const TestCardForm = ({
testResults: convertFromMultiplexResponse(testOrder.results),
aoeResponses: {
pregnancy: testOrder.pregnancy as PregnancyCode,
syphilisHistory: testOrder.syphilisHistory as SyphilisHistoryCode,
noSymptoms: testOrder.noSymptoms,
symptomOnset: testOrder.symptomOnset,
symptoms: JSON.stringify(parseRespiratorySymptoms(testOrder.symptoms)),
symptoms: stringifySymptomJsonForAoeUpdate(testOrder.symptoms),
genderOfSexualPartners: testOrder.genderOfSexualPartners,
},
};
Expand Down Expand Up @@ -193,14 +196,12 @@ const TestCardForm = ({
variables: {
patientId: testOrder.patient.internalId,
noSymptoms: state.aoeResponses.noSymptoms,
// automatically converts boolean strings like "false" to false
symptoms: JSON.stringify(
parseRespiratorySymptoms(state.aoeResponses.symptoms)
),
symptoms: stringifySymptomJsonForAoeUpdate(state.aoeResponses.symptoms),
symptomOnset: state.aoeResponses.symptomOnset
? state.aoeResponses.symptomOnset
: null,
pregnancy: state.aoeResponses.pregnancy,
syphilisHistory: state.aoeResponses.syphilisHistory,
genderOfSexualPartners:
state.aoeResponses.genderOfSexualPartners ?? null,
},
Expand Down Expand Up @@ -553,6 +554,7 @@ const TestCardForm = ({
<CovidAoEForm
testOrder={testOrder}
responses={state.aoeResponses}
hasAttemptedSubmit={hasAttemptedSubmit}
onResponseChange={(responses) => {
dispatch({
type: TestFormActionCase.UPDATE_AOE_RESPONSES,
Expand Down

0 comments on commit 2aef352

Please sign in to comment.