From 56d301267ff6497fa90a17c8351907767f686671 Mon Sep 17 00:00:00 2001 From: jy95 Date: Mon, 25 Mar 2024 22:40:03 +0100 Subject: [PATCH] test: timeOfDay / patientInstruction --- .../patientInstruction.test.tsx | 34 ++++++++++ __tests__/fromDosageToText/timeOfDay.test.tsx | 64 +++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 __tests__/fromDosageToText/patientInstruction.test.tsx create mode 100644 __tests__/fromDosageToText/timeOfDay.test.tsx diff --git a/__tests__/fromDosageToText/patientInstruction.test.tsx b/__tests__/fromDosageToText/patientInstruction.test.tsx new file mode 100644 index 00000000..759ff0b8 --- /dev/null +++ b/__tests__/fromDosageToText/patientInstruction.test.tsx @@ -0,0 +1,34 @@ +// For typings autocomplete whatever your IDE +import { expect, test, describe } from "@jest/globals"; +import FhirDosageUtils from "../../src/index"; + +// types +import type { Dosage } from "fhir/r4"; + +describe("fromDosageToText - patientInstruction", () => { + let dosageUtils: FhirDosageUtils; + + beforeAll(async () => { + dosageUtils = await FhirDosageUtils.build({ + displayOrder: ["patientInstruction"], + }); + }); + + test("No patientInstruction", () => { + const dosage: Dosage = { + text: "no patientInstruction", + }; + + let result = dosageUtils.fromDosageToText(dosage); + expect(result).toBe(""); + }); + + test("Simple case", () => { + const dosage: Dosage = { + patientInstruction: "patientInstruction", + }; + + let result = dosageUtils.fromDosageToText(dosage); + expect(result).toBe("patientInstruction"); + }); +}); diff --git a/__tests__/fromDosageToText/timeOfDay.test.tsx b/__tests__/fromDosageToText/timeOfDay.test.tsx new file mode 100644 index 00000000..a11d6406 --- /dev/null +++ b/__tests__/fromDosageToText/timeOfDay.test.tsx @@ -0,0 +1,64 @@ +// For typings autocomplete whatever your IDE +import { expect, test, describe } from "@jest/globals"; +import FhirDosageUtils from "../../src/index"; + +// types +import type { Dosage } from "fhir/r4"; + +describe("fromDosageToText - timeOfDay", () => { + let dosageUtils: FhirDosageUtils; + + beforeAll(async () => { + dosageUtils = await FhirDosageUtils.build({ + displayOrder: ["timeOfDay"], + }); + }); + + test("No timeOfDay", () => { + const dosage: Dosage = { + text: "no timeOfDay", + }; + + let result = dosageUtils.fromDosageToText(dosage); + expect(result).toBe(""); + }); + + test("timeOfDay - empty", () => { + const dosage: Dosage = { + timing: { + repeat: { + timeOfDay: [], + }, + }, + }; + + let result = dosageUtils.fromDosageToText(dosage); + expect(result).toBe(""); + }); + + test("timeOfDay - 1 item", () => { + const dosage: Dosage = { + timing: { + repeat: { + timeOfDay: ["15:00:00"], + }, + }, + }; + + let result = dosageUtils.fromDosageToText(dosage); + expect(result).toBe("at 15:00"); + }); + + test("timeOfDay - N+1 items", () => { + const dosage: Dosage = { + timing: { + repeat: { + timeOfDay: ["15:00:00", "12:12:12"], + }, + }, + }; + + let result = dosageUtils.fromDosageToText(dosage); + expect(result).toBe("at 15:00 and 12:12:12"); + }); +});