This repository has been archived by the owner on Jan 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
text: ResourceCard unit tests & factories
- Loading branch information
Showing
2 changed files
with
172 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import React from "react"; | ||
|
||
import { DateTime } from "luxon"; | ||
|
||
import { render, screen } from "common/tests/test-utils"; | ||
import { | ||
carePlanFactory, | ||
conditionFactory, | ||
encounterFactory, | ||
} from "services/api/factory"; | ||
|
||
import { TERMINOLOGY_SYSTEM_URL } from "../../../constants"; | ||
import ResourceCard from "../ResourceCard"; | ||
|
||
const condition = conditionFactory.build(); | ||
const encounter = encounterFactory.build(); | ||
const carePlan = carePlanFactory.build(); | ||
|
||
describe("ResourceCard", () => { | ||
it("Displays ConditionCard", async () => { | ||
render(<ResourceCard resource={condition} />); | ||
|
||
await screen.findByText(new RegExp(`${condition.resourceType}`, "i")); | ||
|
||
await screen.findByText( | ||
new RegExp(`${condition.code?.coding?.[0]?.display}`, "i") | ||
); | ||
await screen.findByText( | ||
new RegExp(`${condition.code?.coding?.[0]?.system}`, "i") | ||
); | ||
await screen.findByText( | ||
new RegExp(`${condition.code?.coding?.[0]?.code}`, "i") | ||
); | ||
|
||
expect(condition.onsetDateTime).not.toBeUndefined(); | ||
await screen.findByText( | ||
new RegExp( | ||
`${DateTime.fromISO(condition.onsetDateTime ?? "").toLocaleString( | ||
{ | ||
day: "numeric", | ||
month: "long", | ||
year: "numeric", | ||
}, | ||
{ locale: navigator.language } | ||
)}`, | ||
"i" | ||
) | ||
); | ||
|
||
const tagValue = condition.meta?.tag?.find( | ||
({ system }) => system === TERMINOLOGY_SYSTEM_URL | ||
); | ||
expect(tagValue).not.toBeUndefined(); | ||
await screen.findByText(new RegExp(`${tagValue?.display}`, "i")); | ||
}); | ||
|
||
it("Displays EncounterCard", async () => { | ||
render(<ResourceCard resource={encounter} />); | ||
await screen.findByText(new RegExp(`${encounter.resourceType}`, "i")); | ||
|
||
await screen.findByText( | ||
new RegExp(`${encounter.location?.[0]?.location?.display}`, "i") | ||
); | ||
|
||
expect(encounter.period?.start).not.toBeUndefined(); | ||
await screen.findByText( | ||
new RegExp( | ||
`${DateTime.fromISO(encounter.period?.start ?? "").toLocaleString( | ||
{ | ||
day: "numeric", | ||
month: "long", | ||
year: "numeric", | ||
}, | ||
{ | ||
locale: navigator.language, | ||
} | ||
)}`, | ||
"i" | ||
) | ||
); | ||
|
||
expect(encounter.period?.end).not.toBeUndefined(); | ||
await screen.findByText( | ||
new RegExp( | ||
`${DateTime.fromISO(encounter.period?.end ?? "").toLocaleString( | ||
{ | ||
day: "numeric", | ||
month: "long", | ||
year: "numeric", | ||
}, | ||
{ | ||
locale: navigator.language, | ||
} | ||
)}`, | ||
"i" | ||
) | ||
); | ||
|
||
const tagValue = encounter.meta?.tag?.find( | ||
({ system }) => system === TERMINOLOGY_SYSTEM_URL | ||
); | ||
expect(tagValue).not.toBeUndefined(); | ||
await screen.findByText(new RegExp(`${tagValue?.display}`, "i")); | ||
}); | ||
|
||
it("Displays Default card", async () => { | ||
render(<ResourceCard resource={carePlan} />); | ||
await screen.findByText(new RegExp(`^${carePlan.resourceType}$`, "i")); | ||
await screen.findByText(new RegExp(`${JSON.stringify(carePlan)}`, "i")); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters