@photonhealth/react 0.0.0-stage → 2.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +15 -0
- package/README.md +111 -2
- package/dist/adapters/index.d.ts +2 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +2 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/tailwind.d.ts +3 -0
- package/dist/adapters/tailwind.d.ts.map +1 -0
- package/dist/adapters/tailwind.js +126 -0
- package/dist/adapters/tailwind.js.map +1 -0
- package/dist/analytics/PhotonAnalyticsProvider.d.ts +16 -0
- package/dist/analytics/PhotonAnalyticsProvider.d.ts.map +1 -0
- package/dist/analytics/PhotonAnalyticsProvider.js +57 -0
- package/dist/analytics/PhotonAnalyticsProvider.js.map +1 -0
- package/dist/analytics/fieldInteraction.d.ts +18 -0
- package/dist/analytics/fieldInteraction.d.ts.map +1 -0
- package/dist/analytics/fieldInteraction.js +102 -0
- package/dist/analytics/fieldInteraction.js.map +1 -0
- package/dist/analytics/tracker.d.ts +17 -0
- package/dist/analytics/tracker.d.ts.map +1 -0
- package/dist/analytics/tracker.js +36 -0
- package/dist/analytics/tracker.js.map +1 -0
- package/dist/analytics/viewed.d.ts +11 -0
- package/dist/analytics/viewed.d.ts.map +1 -0
- package/dist/analytics/viewed.js +16 -0
- package/dist/analytics/viewed.js.map +1 -0
- package/dist/components/ChangeList.d.ts +21 -0
- package/dist/components/ChangeList.d.ts.map +1 -0
- package/dist/components/ChangeList.js +40 -0
- package/dist/components/ChangeList.js.map +1 -0
- package/dist/components/PhotonOrder.d.ts +46 -0
- package/dist/components/PhotonOrder.d.ts.map +1 -0
- package/dist/components/PhotonOrder.js +274 -0
- package/dist/components/PhotonOrder.js.map +1 -0
- package/dist/components/PhotonPatient.d.ts +48 -0
- package/dist/components/PhotonPatient.d.ts.map +1 -0
- package/dist/components/PhotonPatient.js +85 -0
- package/dist/components/PhotonPatient.js.map +1 -0
- package/dist/components/PhotonPrescription.d.ts +32 -0
- package/dist/components/PhotonPrescription.d.ts.map +1 -0
- package/dist/components/PhotonPrescription.js +11 -0
- package/dist/components/PhotonPrescription.js.map +1 -0
- package/dist/components/ScreeningAlerts.d.ts +6 -0
- package/dist/components/ScreeningAlerts.d.ts.map +1 -0
- package/dist/components/ScreeningAlerts.js +11 -0
- package/dist/components/ScreeningAlerts.js.map +1 -0
- package/dist/components/SignedIn.d.ts +12 -0
- package/dist/components/SignedIn.d.ts.map +1 -0
- package/dist/components/SignedIn.js +84 -0
- package/dist/components/SignedIn.js.map +1 -0
- package/dist/components/activity.d.ts +7 -0
- package/dist/components/activity.d.ts.map +1 -0
- package/dist/components/activity.js +24 -0
- package/dist/components/activity.js.map +1 -0
- package/dist/components/display.d.ts +90 -0
- package/dist/components/display.d.ts.map +1 -0
- package/dist/components/display.js +223 -0
- package/dist/components/display.js.map +1 -0
- package/dist/components/flow.d.ts +35 -0
- package/dist/components/flow.d.ts.map +1 -0
- package/dist/components/flow.js +53 -0
- package/dist/components/flow.js.map +1 -0
- package/dist/components/format.d.ts +26 -0
- package/dist/components/format.d.ts.map +1 -0
- package/dist/components/format.js +61 -0
- package/dist/components/format.js.map +1 -0
- package/dist/components/index.d.ts +6 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +6 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/open.d.ts +47 -0
- package/dist/components/open.d.ts.map +1 -0
- package/dist/components/open.js +73 -0
- package/dist/components/open.js.map +1 -0
- package/dist/components/order/DraftOrderPrompt.d.ts +18 -0
- package/dist/components/order/DraftOrderPrompt.d.ts.map +1 -0
- package/dist/components/order/DraftOrderPrompt.js +26 -0
- package/dist/components/order/DraftOrderPrompt.js.map +1 -0
- package/dist/components/patient/Benefits.d.ts +25 -0
- package/dist/components/patient/Benefits.d.ts.map +1 -0
- package/dist/components/patient/Benefits.js +48 -0
- package/dist/components/patient/Benefits.js.map +1 -0
- package/dist/components/patient/Clinical.d.ts +56 -0
- package/dist/components/patient/Clinical.d.ts.map +1 -0
- package/dist/components/patient/Clinical.js +118 -0
- package/dist/components/patient/Clinical.js.map +1 -0
- package/dist/components/patient/IntakeForm.d.ts +10 -0
- package/dist/components/patient/IntakeForm.d.ts.map +1 -0
- package/dist/components/patient/IntakeForm.js +333 -0
- package/dist/components/patient/IntakeForm.js.map +1 -0
- package/dist/components/patient/Summary.d.ts +48 -0
- package/dist/components/patient/Summary.d.ts.map +1 -0
- package/dist/components/patient/Summary.js +90 -0
- package/dist/components/patient/Summary.js.map +1 -0
- package/dist/components/patient/fields.d.ts +42 -0
- package/dist/components/patient/fields.d.ts.map +1 -0
- package/dist/components/patient/fields.js +72 -0
- package/dist/components/patient/fields.js.map +1 -0
- package/dist/components/patient/query.d.ts +37 -0
- package/dist/components/patient/query.d.ts.map +1 -0
- package/dist/components/patient/query.js +70 -0
- package/dist/components/patient/query.js.map +1 -0
- package/dist/components/prescription/PrescriptionCard.d.ts +45 -0
- package/dist/components/prescription/PrescriptionCard.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionCard.js +179 -0
- package/dist/components/prescription/PrescriptionCard.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.d.ts +15 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.js +18 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.d.ts +23 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.js +42 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.d.ts +27 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.js +169 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.d.ts +8 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.js +12 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.d.ts +11 -0
- package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.js +25 -0
- package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.js.map +1 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentPicker.d.ts +50 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentPicker.d.ts.map +1 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentPicker.js +287 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentPicker.js.map +1 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentSearch.d.ts +28 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentSearch.d.ts.map +1 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentSearch.js +146 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentSearch.js.map +1 -0
- package/dist/components/schemaErrors.d.ts +12 -0
- package/dist/components/schemaErrors.d.ts.map +1 -0
- package/dist/components/schemaErrors.js +24 -0
- package/dist/components/schemaErrors.js.map +1 -0
- package/dist/components/search.d.ts +154 -0
- package/dist/components/search.d.ts.map +1 -0
- package/dist/components/search.js +295 -0
- package/dist/components/search.js.map +1 -0
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useLatestCallback.d.ts +7 -0
- package/dist/hooks/useLatestCallback.d.ts.map +1 -0
- package/dist/hooks/useLatestCallback.js +14 -0
- package/dist/hooks/useLatestCallback.js.map +1 -0
- package/dist/hooks/useLive.d.ts +15 -0
- package/dist/hooks/useLive.d.ts.map +1 -0
- package/dist/hooks/useLive.js +6 -0
- package/dist/hooks/useLive.js.map +1 -0
- package/dist/hooks/useOnChange.d.ts +11 -0
- package/dist/hooks/useOnChange.d.ts.map +1 -0
- package/dist/hooks/useOnChange.js +28 -0
- package/dist/hooks/useOnChange.js.map +1 -0
- package/dist/hooks/useSession.d.ts +7 -0
- package/dist/hooks/useSession.d.ts.map +1 -0
- package/dist/hooks/useSession.js +10 -0
- package/dist/hooks/useSession.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/meta/version.d.ts +5 -0
- package/dist/meta/version.d.ts.map +1 -0
- package/dist/meta/version.js +5 -0
- package/dist/meta/version.js.map +1 -0
- package/dist/primitives/PhotonProvider.d.ts +60 -0
- package/dist/primitives/PhotonProvider.d.ts.map +1 -0
- package/dist/primitives/PhotonProvider.js +103 -0
- package/dist/primitives/PhotonProvider.js.map +1 -0
- package/dist/primitives/defaults.d.ts +3 -0
- package/dist/primitives/defaults.d.ts.map +1 -0
- package/dist/primitives/defaults.js +70 -0
- package/dist/primitives/defaults.js.map +1 -0
- package/dist/primitives/icons.d.ts +6 -0
- package/dist/primitives/icons.d.ts.map +1 -0
- package/dist/primitives/icons.js +6 -0
- package/dist/primitives/icons.js.map +1 -0
- package/dist/primitives/index.d.ts +5 -0
- package/dist/primitives/index.d.ts.map +1 -0
- package/dist/primitives/index.js +5 -0
- package/dist/primitives/index.js.map +1 -0
- package/dist/primitives/photonContext.d.ts +3 -0
- package/dist/primitives/photonContext.d.ts.map +1 -0
- package/dist/primitives/photonContext.js +3 -0
- package/dist/primitives/photonContext.js.map +1 -0
- package/dist/primitives/select.d.ts +7 -0
- package/dist/primitives/select.d.ts.map +1 -0
- package/dist/primitives/select.js +16 -0
- package/dist/primitives/select.js.map +1 -0
- package/dist/primitives/types.d.ts +288 -0
- package/dist/primitives/types.d.ts.map +1 -0
- package/dist/primitives/types.js +3 -0
- package/dist/primitives/types.js.map +1 -0
- package/dist/primitives/useProvidedPhoton.d.ts +8 -0
- package/dist/primitives/useProvidedPhoton.d.ts.map +1 -0
- package/dist/primitives/useProvidedPhoton.js +8 -0
- package/dist/primitives/useProvidedPhoton.js.map +1 -0
- package/dist/styles.css +653 -0
- package/dist/test-utils/contract.d.ts +17 -0
- package/dist/test-utils/contract.d.ts.map +1 -0
- package/dist/test-utils/contract.js +282 -0
- package/dist/test-utils/contract.js.map +1 -0
- package/package.json +76 -4
- package/src/adapters/index.ts +1 -0
- package/src/adapters/tailwind.tsx +572 -0
- package/src/analytics/PhotonAnalyticsProvider.test.tsx +191 -0
- package/src/analytics/PhotonAnalyticsProvider.tsx +96 -0
- package/src/analytics/fieldInteraction.test.tsx +184 -0
- package/src/analytics/fieldInteraction.tsx +148 -0
- package/src/analytics/tracker.test.ts +52 -0
- package/src/analytics/tracker.ts +42 -0
- package/src/analytics/viewed.ts +27 -0
- package/src/components/ChangeList.tsx +85 -0
- package/src/components/PhotonOrder.test.tsx +256 -0
- package/src/components/PhotonOrder.tsx +508 -0
- package/src/components/PhotonPatient.tsx +188 -0
- package/src/components/PhotonPrescription.test.tsx +116 -0
- package/src/components/PhotonPrescription.tsx +45 -0
- package/src/components/ScreeningAlerts.tsx +28 -0
- package/src/components/SignedIn.tsx +144 -0
- package/src/components/activity.ts +23 -0
- package/src/components/display.ts +278 -0
- package/src/components/flow.ts +67 -0
- package/src/components/format.ts +73 -0
- package/src/components/index.ts +5 -0
- package/src/components/open.ts +100 -0
- package/src/components/order/DraftOrderPrompt.test.tsx +80 -0
- package/src/components/order/DraftOrderPrompt.tsx +81 -0
- package/src/components/patient/Benefits.tsx +133 -0
- package/src/components/patient/Clinical.tsx +215 -0
- package/src/components/patient/IntakeForm.test.tsx +89 -0
- package/src/components/patient/IntakeForm.tsx +564 -0
- package/src/components/patient/Summary.test.tsx +106 -0
- package/src/components/patient/Summary.tsx +330 -0
- package/src/components/patient/fields.tsx +158 -0
- package/src/components/patient/query.ts +83 -0
- package/src/components/prescription/PrescriptionCard.test.tsx +85 -0
- package/src/components/prescription/PrescriptionCard.tsx +347 -0
- package/src/components/prescription/PrescriptionDetailsForm/DirectionsInput.test.tsx +85 -0
- package/src/components/prescription/PrescriptionDetailsForm/DirectionsInput.tsx +41 -0
- package/src/components/prescription/PrescriptionDetailsForm/DispenseInputs.test.tsx +209 -0
- package/src/components/prescription/PrescriptionDetailsForm/DispenseInputs.tsx +99 -0
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.test.tsx +456 -0
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.tsx +238 -0
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.test.ts +63 -0
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.ts +15 -0
- package/src/components/prescription/PrescriptionDetailsForm/TemplatePicker.test.tsx +75 -0
- package/src/components/prescription/PrescriptionDetailsForm/TemplatePicker.tsx +41 -0
- package/src/components/prescription/TreatmentSearch/TreatmentPicker.tsx +375 -0
- package/src/components/prescription/TreatmentSearch/TreatmentSearch.test.tsx +699 -0
- package/src/components/prescription/TreatmentSearch/TreatmentSearch.tsx +220 -0
- package/src/components/schemaErrors.test.ts +49 -0
- package/src/components/schemaErrors.ts +33 -0
- package/src/components/search.tsx +377 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/useLatestCallback.ts +16 -0
- package/src/hooks/useLive.ts +21 -0
- package/src/hooks/useOnChange.ts +34 -0
- package/src/hooks/useSession.ts +11 -0
- package/src/index.ts +21 -0
- package/src/meta/version.test.ts +10 -0
- package/src/meta/version.ts +4 -0
- package/src/primitives/PhotonProvider.tsx +168 -0
- package/src/primitives/defaults.tsx +432 -0
- package/src/primitives/icons.tsx +37 -0
- package/src/primitives/index.ts +4 -0
- package/src/primitives/photonContext.ts +4 -0
- package/src/primitives/select.ts +15 -0
- package/src/primitives/types.ts +288 -0
- package/src/primitives/useProvidedPhoton.ts +21 -0
- package/src/styles.css +653 -0
- package/src/test-utils/contract.tsx +453 -0
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
import { cleanup, fireEvent, render, screen, within } from "@testing-library/react";
|
|
2
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { defaultComponents } from "../primitives/defaults.tsx";
|
|
4
|
+
import type { PhotonComponents } from "../primitives/types.ts";
|
|
5
|
+
|
|
6
|
+
/** A brand: a name for the test titles, and its building blocks (`undefined`: the stock HTML defaults). */
|
|
7
|
+
export type Brand = [name: string, components: Partial<PhotonComponents> | undefined];
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The building-block contract: what the cards rely on from every brand's building blocks, whichever design
|
|
11
|
+
* system draws them (a Button never submits a surrounding form, Inputs are labelled, a critical Alert is
|
|
12
|
+
* announced, …). An adapter that breaks one breaks the workflow in that brand only — what this catches.
|
|
13
|
+
*
|
|
14
|
+
* Registers Vitest tests; call it at the top level of a test file that runs in jsdom, with
|
|
15
|
+
* `@testing-library/react` installed:
|
|
16
|
+
*
|
|
17
|
+
* // @vitest-environment jsdom
|
|
18
|
+
* import { buildingBlocksContract } from "@photonhealth/react/test-utils/contract";
|
|
19
|
+
* buildingBlocksContract([["mine", myComponents]]);
|
|
20
|
+
*/
|
|
21
|
+
export function buildingBlocksContract(brands: Brand[]): void {
|
|
22
|
+
afterEach(cleanup);
|
|
23
|
+
|
|
24
|
+
describe.each(brands)("building blocks contract, brand=%s", (_name, components) => {
|
|
25
|
+
const c: PhotonComponents = { ...defaultComponents, ...components };
|
|
26
|
+
|
|
27
|
+
it("Button defaults to type=button (never submits a surrounding form)", () => {
|
|
28
|
+
const onSubmit = vi.fn((e: Event) => e.preventDefault());
|
|
29
|
+
const onClick = vi.fn();
|
|
30
|
+
render(
|
|
31
|
+
<form onSubmit={onSubmit as never}>
|
|
32
|
+
<c.Button onClick={onClick}>Pick</c.Button>
|
|
33
|
+
</form>,
|
|
34
|
+
);
|
|
35
|
+
fireEvent.click(screen.getByRole("button", { name: "Pick" }));
|
|
36
|
+
expect(onClick).toHaveBeenCalledOnce();
|
|
37
|
+
expect(onSubmit).not.toHaveBeenCalled();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("Button type=submit does submit", () => {
|
|
41
|
+
const onSubmit = vi.fn((e: Event) => e.preventDefault());
|
|
42
|
+
render(
|
|
43
|
+
<form onSubmit={onSubmit as never}>
|
|
44
|
+
<c.Button type="submit">Go</c.Button>
|
|
45
|
+
</form>,
|
|
46
|
+
);
|
|
47
|
+
fireEvent.click(screen.getByRole("button", { name: "Go" }));
|
|
48
|
+
expect(onSubmit).toHaveBeenCalledOnce();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("Button loading disables it", () => {
|
|
52
|
+
render(<c.Button loading>Send</c.Button>);
|
|
53
|
+
expect(screen.getByRole("button", { name: /Send/ })).toHaveProperty("disabled", true);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("Input is labelled and reports changes", () => {
|
|
57
|
+
const onChange = vi.fn();
|
|
58
|
+
render(<c.Input label="Last name" value="" onChange={onChange} />);
|
|
59
|
+
fireEvent.change(screen.getByLabelText("Last name"), { target: { value: "Lovelace" } });
|
|
60
|
+
expect(onChange).toHaveBeenCalled();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("Input passes native type / pattern through, so the browser validates", () => {
|
|
64
|
+
render(
|
|
65
|
+
<>
|
|
66
|
+
<c.Input label="Email" type="email" value="not-an-email" onChange={() => {}} />
|
|
67
|
+
<c.Input label="Phone" type="tel" pattern="\\d{10}" value="555" onChange={() => {}} />
|
|
68
|
+
</>,
|
|
69
|
+
);
|
|
70
|
+
const email = screen.getByLabelText("Email") as HTMLInputElement;
|
|
71
|
+
const phone = screen.getByLabelText("Phone") as HTMLInputElement;
|
|
72
|
+
expect(email.type).toBe("email");
|
|
73
|
+
expect(email.validity.typeMismatch).toBe(true);
|
|
74
|
+
expect(phone.type).toBe("tel");
|
|
75
|
+
expect(phone.validity.patternMismatch).toBe(true);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("Select narrows by the start of a word as you type ('m' → Male, not Female)", async () => {
|
|
79
|
+
render(
|
|
80
|
+
<c.Select
|
|
81
|
+
label="Sex"
|
|
82
|
+
options={[
|
|
83
|
+
{ value: "FEMALE", label: "Female" },
|
|
84
|
+
{ value: "MALE", label: "Male" },
|
|
85
|
+
]}
|
|
86
|
+
value={null}
|
|
87
|
+
onChange={() => {}}
|
|
88
|
+
/>,
|
|
89
|
+
);
|
|
90
|
+
const control = screen.getByLabelText("Sex");
|
|
91
|
+
if (control instanceof HTMLSelectElement) return; // native <select>: the browser jumps by first letter
|
|
92
|
+
fireEvent.focus(control);
|
|
93
|
+
fireEvent.change(control, { target: { value: "m" } });
|
|
94
|
+
expect(await screen.findByRole("option", { name: "Male" })).toBeTruthy();
|
|
95
|
+
expect(screen.queryByRole("option", { name: "Female" })).toBeNull();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("Select: Enter on the closed field opens it", async () => {
|
|
99
|
+
const showPicker = vi.fn();
|
|
100
|
+
Object.defineProperty(HTMLSelectElement.prototype, "showPicker", { value: showPicker, configurable: true });
|
|
101
|
+
render(
|
|
102
|
+
<c.Select
|
|
103
|
+
label="Unit"
|
|
104
|
+
options={[
|
|
105
|
+
{ value: "Tablet", label: "Tablet" },
|
|
106
|
+
{ value: "Bottle", label: "Bottle" },
|
|
107
|
+
]}
|
|
108
|
+
value={null}
|
|
109
|
+
onChange={() => {}}
|
|
110
|
+
/>,
|
|
111
|
+
);
|
|
112
|
+
const control = screen.getByLabelText("Unit");
|
|
113
|
+
control.focus();
|
|
114
|
+
fireEvent.keyDown(control, { key: "Enter" });
|
|
115
|
+
if (control instanceof HTMLSelectElement) expect(showPicker).toHaveBeenCalled();
|
|
116
|
+
else expect(await screen.findByRole("option", { name: "Tablet" })).toBeTruthy();
|
|
117
|
+
delete (HTMLSelectElement.prototype as { showPicker?: unknown }).showPicker;
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("Input with onClear: a × named clearLabel while it has a value — not while it's empty or loading", () => {
|
|
121
|
+
const onClear = vi.fn();
|
|
122
|
+
const { rerender } = render(
|
|
123
|
+
<c.Input
|
|
124
|
+
label="Treatment"
|
|
125
|
+
value="Amoxicillin"
|
|
126
|
+
onChange={() => {}}
|
|
127
|
+
onClear={onClear}
|
|
128
|
+
clearLabel="Clear treatment"
|
|
129
|
+
/>,
|
|
130
|
+
);
|
|
131
|
+
fireEvent.click(screen.getByRole("button", { name: "Clear treatment" }));
|
|
132
|
+
expect(onClear).toHaveBeenCalled();
|
|
133
|
+
rerender(
|
|
134
|
+
<c.Input label="Treatment" value="" onChange={() => {}} onClear={onClear} clearLabel="Clear treatment" />,
|
|
135
|
+
);
|
|
136
|
+
expect(screen.queryByRole("button", { name: "Clear treatment" })).toBeNull();
|
|
137
|
+
rerender(
|
|
138
|
+
<c.Input
|
|
139
|
+
label="Treatment"
|
|
140
|
+
value="amox"
|
|
141
|
+
onChange={() => {}}
|
|
142
|
+
onClear={onClear}
|
|
143
|
+
clearLabel="Clear treatment"
|
|
144
|
+
loading
|
|
145
|
+
/>,
|
|
146
|
+
);
|
|
147
|
+
expect(screen.queryByRole("button", { name: "Clear treatment" })).toBeNull();
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("Input with loading is marked busy", () => {
|
|
151
|
+
render(<c.Input label="First name" value="Otto" onChange={() => {}} loading />);
|
|
152
|
+
expect(screen.getByLabelText("First name").getAttribute("aria-busy")).toBe("true");
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("Spinner alone (no label) is still a status", () => {
|
|
156
|
+
render(<c.Spinner />);
|
|
157
|
+
expect(screen.getByRole("status")).toBeTruthy();
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("Spinner says what's happening, as a status", () => {
|
|
161
|
+
render(<c.Spinner label="Saving…" />);
|
|
162
|
+
expect(screen.getByRole("status").textContent).toBe("Saving…");
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("Card with a label is a region by that name", () => {
|
|
166
|
+
render(<c.Card label="Amoxicillin">body</c.Card>);
|
|
167
|
+
expect(screen.getByRole("region", { name: "Amoxicillin" }).textContent).toBe("body");
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("CardFooter puts `start` before the actions", () => {
|
|
171
|
+
render(
|
|
172
|
+
<c.CardFooter start={<span>left</span>}>
|
|
173
|
+
<button type="button">right</button>
|
|
174
|
+
</c.CardFooter>,
|
|
175
|
+
);
|
|
176
|
+
const left = screen.getByText("left");
|
|
177
|
+
expect(
|
|
178
|
+
left.compareDocumentPosition(screen.getByRole("button", { name: "right" })) & Node.DOCUMENT_POSITION_FOLLOWING,
|
|
179
|
+
).toBeTruthy();
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("Checkbox reports its new value", () => {
|
|
183
|
+
const onChange = vi.fn();
|
|
184
|
+
render(<c.Checkbox label="Dispense as written" checked={false} onChange={onChange} />);
|
|
185
|
+
fireEvent.click(screen.getByLabelText("Dispense as written"));
|
|
186
|
+
expect(onChange).toHaveBeenCalledWith(true);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("Badge with onRemove has a labelled remove control", () => {
|
|
190
|
+
const onRemove = vi.fn();
|
|
191
|
+
render(
|
|
192
|
+
<c.Badge tone="warning" onRemove={onRemove} removeLabel="Remove Penicillin">
|
|
193
|
+
Penicillin
|
|
194
|
+
</c.Badge>,
|
|
195
|
+
);
|
|
196
|
+
fireEvent.click(screen.getByRole("button", { name: "Remove Penicillin" }));
|
|
197
|
+
expect(onRemove).toHaveBeenCalledOnce();
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it("ChoiceList: a labelled list whose options are buttons that report their key", () => {
|
|
201
|
+
const onChoose = vi.fn();
|
|
202
|
+
render(
|
|
203
|
+
<c.ChoiceList
|
|
204
|
+
label="Treatment"
|
|
205
|
+
onChoose={onChoose}
|
|
206
|
+
choices={[
|
|
207
|
+
{ key: "a", label: "metFORMIN HCl ER (MOD) Oral Tablet Extended Release 24 Hour 1000 MG" },
|
|
208
|
+
{ key: "b", label: "metFORMIN HCl Oral Tablet 500 MG" },
|
|
209
|
+
]}
|
|
210
|
+
/>,
|
|
211
|
+
);
|
|
212
|
+
expect(screen.getByRole("list", { name: "Treatment" })).toBeTruthy();
|
|
213
|
+
fireEvent.click(screen.getByRole("button", { name: "metFORMIN HCl Oral Tablet 500 MG" }));
|
|
214
|
+
expect(onChoose).toHaveBeenCalledWith("b");
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it("ChoiceList: `action` is a last row that reports itself, in both shapes", () => {
|
|
218
|
+
for (const activeKey of [undefined, null]) {
|
|
219
|
+
const onChoose = vi.fn();
|
|
220
|
+
const { unmount } = render(
|
|
221
|
+
<c.ChoiceList
|
|
222
|
+
label="Matching patients"
|
|
223
|
+
onChoose={() => {}}
|
|
224
|
+
activeKey={activeKey}
|
|
225
|
+
choices={[{ key: "a", label: "Ada Lovelace" }]}
|
|
226
|
+
action={{ label: "Add new patient", icon: "add", onChoose }}
|
|
227
|
+
/>,
|
|
228
|
+
);
|
|
229
|
+
const role = activeKey === undefined ? "button" : "option";
|
|
230
|
+
fireEvent.click(screen.getByRole(role, { name: "Add new patient" }));
|
|
231
|
+
expect(onChoose).toHaveBeenCalledTimes(1);
|
|
232
|
+
unmount();
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it("ChoiceList: with `activeKey` it is a listbox of options the field points at, not buttons", () => {
|
|
237
|
+
const onChoose = vi.fn();
|
|
238
|
+
render(
|
|
239
|
+
<c.ChoiceList
|
|
240
|
+
label="Matching patients"
|
|
241
|
+
id="list"
|
|
242
|
+
onChoose={onChoose}
|
|
243
|
+
activeKey="b"
|
|
244
|
+
choices={[
|
|
245
|
+
{ key: "a", label: "Ada Lovelace" },
|
|
246
|
+
{ key: "b", label: "Ada Byron" },
|
|
247
|
+
]}
|
|
248
|
+
/>,
|
|
249
|
+
);
|
|
250
|
+
// A field keeps the cursor, so nothing here is focusable — the active row is marked, not focused.
|
|
251
|
+
expect(screen.getByRole("listbox", { name: "Matching patients" })).toBeTruthy();
|
|
252
|
+
expect(screen.queryByRole("button", { name: "Ada Byron" })).toBeNull();
|
|
253
|
+
const [first, second] = screen.getAllByRole("option");
|
|
254
|
+
expect(first!.getAttribute("aria-selected")).toBe("false");
|
|
255
|
+
expect(second!.getAttribute("aria-selected")).toBe("true");
|
|
256
|
+
// Its id is where `aria-activedescendant` points.
|
|
257
|
+
expect(second!.id).toBe("list-b");
|
|
258
|
+
fireEvent.click(second!);
|
|
259
|
+
expect(onChoose).toHaveBeenCalledWith("b");
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it("ChoiceList: the pending choice is aria-busy (drawn selected while its call runs); the others aren't", () => {
|
|
263
|
+
render(
|
|
264
|
+
<c.ChoiceList
|
|
265
|
+
label="Matching patients"
|
|
266
|
+
onChoose={() => {}}
|
|
267
|
+
pendingKey="b"
|
|
268
|
+
choices={[
|
|
269
|
+
{ key: "a", label: "Anna Conda" },
|
|
270
|
+
{ key: "b", label: "Barb Dwyer" },
|
|
271
|
+
]}
|
|
272
|
+
/>,
|
|
273
|
+
);
|
|
274
|
+
expect(screen.getByRole("button", { name: "Barb Dwyer" }).getAttribute("aria-busy")).toBe("true");
|
|
275
|
+
expect(screen.getByRole("button", { name: "Anna Conda" }).getAttribute("aria-busy")).toBeNull();
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it("ChoiceList: `meta` sits on the label's line, `description` below — both inside the option", () => {
|
|
279
|
+
render(
|
|
280
|
+
<c.ChoiceList
|
|
281
|
+
label="Matching patients"
|
|
282
|
+
onChoose={() => {}}
|
|
283
|
+
choices={[{ key: "a", label: "Anna Conda", meta: "03-12-1984", description: "Last seen 2026" }]}
|
|
284
|
+
/>,
|
|
285
|
+
);
|
|
286
|
+
const option = screen.getByRole("button", { name: /Anna Conda/ });
|
|
287
|
+
const name = within(option).getByText("Anna Conda");
|
|
288
|
+
const meta = within(option).getByText("03-12-1984");
|
|
289
|
+
expect(name.parentElement).toBe(meta.parentElement); // same line
|
|
290
|
+
expect(within(option).getByText("Last seen 2026").parentElement).not.toBe(name.parentElement);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it("OptionList: rows are buttons reporting their key; the active row is open, its heading a button too, and shows its details", () => {
|
|
294
|
+
const onSelect = vi.fn();
|
|
295
|
+
const onKeyDown = vi.fn();
|
|
296
|
+
render(
|
|
297
|
+
<c.OptionList
|
|
298
|
+
label="Pick a treatment"
|
|
299
|
+
activeKey="a"
|
|
300
|
+
onSelect={onSelect}
|
|
301
|
+
onKeyDown={onKeyDown}
|
|
302
|
+
options={[
|
|
303
|
+
{ key: "a", label: "Lisinopril" },
|
|
304
|
+
{ key: "b", label: "Amlodipine" },
|
|
305
|
+
{ key: "c", label: "Losartan", ariaLabel: "Losartan Potassium Oral Tablet 50 MG" },
|
|
306
|
+
]}
|
|
307
|
+
>
|
|
308
|
+
<span>Lisinopril details</span>
|
|
309
|
+
</c.OptionList>,
|
|
310
|
+
);
|
|
311
|
+
expect(screen.getByText("Lisinopril details")).toBeTruthy();
|
|
312
|
+
const open = screen.getByRole("button", { name: /Lisinopril/, expanded: true });
|
|
313
|
+
expect(open.contains(screen.getByText("Lisinopril details"))).toBe(false); // the details sit beside it
|
|
314
|
+
fireEvent.click(open);
|
|
315
|
+
expect(onSelect).toHaveBeenCalledWith("a");
|
|
316
|
+
fireEvent.click(screen.getByRole("button", { name: /Amlodipine/ }));
|
|
317
|
+
expect(onSelect).toHaveBeenCalledWith("b");
|
|
318
|
+
fireEvent.click(screen.getByRole("button", { name: "Losartan Potassium Oral Tablet 50 MG" }));
|
|
319
|
+
expect(onSelect).toHaveBeenCalledWith("c");
|
|
320
|
+
const list = screen.getByRole("list", { name: "Pick a treatment" }).parentElement!;
|
|
321
|
+
expect(screen.queryByText("Pick a treatment")).toBeNull(); // the label names the list; it isn't shown
|
|
322
|
+
expect(list.tabIndex).toBe(0);
|
|
323
|
+
fireEvent.keyDown(list, { key: "2" });
|
|
324
|
+
expect(onKeyDown).toHaveBeenCalled();
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
it("OptionList: a direct row is the choice itself — a button with no chevron, open or not", () => {
|
|
328
|
+
const onSelect = vi.fn();
|
|
329
|
+
render(
|
|
330
|
+
<c.OptionList
|
|
331
|
+
label="Pick a treatment"
|
|
332
|
+
activeKey="a"
|
|
333
|
+
onSelect={onSelect}
|
|
334
|
+
options={[
|
|
335
|
+
{ key: "a", label: "Amoxapine", ariaLabel: "Amoxapine Oral Tablet 25 MG", direct: true },
|
|
336
|
+
{ key: "b", label: "Atenolol", ariaLabel: "Atenolol Oral Tablet 25 MG", direct: true },
|
|
337
|
+
{ key: "c", label: "Amoxicillin" },
|
|
338
|
+
]}
|
|
339
|
+
/>,
|
|
340
|
+
);
|
|
341
|
+
const open = screen.getByRole("button", { name: "Amoxapine Oral Tablet 25 MG", current: true });
|
|
342
|
+
const closed = screen.getByRole("button", { name: "Atenolol Oral Tablet 25 MG", current: false });
|
|
343
|
+
expect(open.querySelector("svg")).toBeNull();
|
|
344
|
+
expect(closed.querySelector("svg")).toBeNull();
|
|
345
|
+
expect(screen.getByRole("button", { name: /Amoxicillin/ }).querySelector("svg")).not.toBeNull();
|
|
346
|
+
fireEvent.click(open);
|
|
347
|
+
expect(onSelect).toHaveBeenCalledWith("a");
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
it("OptionList: a loading row is busy, its spinner where the chevron goes — open or not", () => {
|
|
351
|
+
render(
|
|
352
|
+
<c.OptionList
|
|
353
|
+
label="Pick a treatment"
|
|
354
|
+
activeKey="a"
|
|
355
|
+
onSelect={() => {}}
|
|
356
|
+
options={[
|
|
357
|
+
{ key: "a", label: "Lipitor", loading: true },
|
|
358
|
+
{ key: "b", label: "Amoxapine", ariaLabel: "Amoxapine Oral Tablet 25 MG", direct: true, loading: true },
|
|
359
|
+
{ key: "c", label: "Amoxicillin" },
|
|
360
|
+
]}
|
|
361
|
+
/>,
|
|
362
|
+
);
|
|
363
|
+
const open = screen.getByText("Lipitor").closest('[aria-current="true"]')!;
|
|
364
|
+
expect(open.getAttribute("aria-busy")).toBe("true");
|
|
365
|
+
const direct = screen.getByRole("button", { name: "Amoxapine Oral Tablet 25 MG" });
|
|
366
|
+
expect(direct.getAttribute("aria-busy")).toBe("true");
|
|
367
|
+
expect(direct.querySelector("svg")).toBeNull(); // the spinner, not a chevron
|
|
368
|
+
expect(screen.getByRole("button", { name: /Amoxicillin/ }).getAttribute("aria-busy")).toBeNull();
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
it("ToggleGroup: a muted chip is greyed but still pickable", () => {
|
|
372
|
+
const onChange = vi.fn();
|
|
373
|
+
render(
|
|
374
|
+
<c.ToggleGroup
|
|
375
|
+
label="Strength"
|
|
376
|
+
value={null}
|
|
377
|
+
onChange={onChange}
|
|
378
|
+
options={[
|
|
379
|
+
{ value: "5", label: "5 mg", muted: true },
|
|
380
|
+
{ value: "10", label: "10 mg" },
|
|
381
|
+
]}
|
|
382
|
+
/>,
|
|
383
|
+
);
|
|
384
|
+
const muted = screen.getByRole("button", { name: "5 mg" });
|
|
385
|
+
expect(muted).toHaveProperty("disabled", false);
|
|
386
|
+
expect(muted.dataset.muted).toBeDefined();
|
|
387
|
+
expect(screen.getByRole("button", { name: "10 mg" }).dataset.muted).toBeUndefined();
|
|
388
|
+
fireEvent.click(muted);
|
|
389
|
+
expect(onChange).toHaveBeenCalledWith("5");
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
it("ToggleGroup: a labelled group of pressed / unpressed buttons that report their value", () => {
|
|
393
|
+
const onChange = vi.fn();
|
|
394
|
+
render(
|
|
395
|
+
<c.ToggleGroup
|
|
396
|
+
label="Strength"
|
|
397
|
+
value="10"
|
|
398
|
+
onChange={onChange}
|
|
399
|
+
options={[
|
|
400
|
+
{ value: "5", label: "5 mg" },
|
|
401
|
+
{ value: "10", label: "10 mg" },
|
|
402
|
+
]}
|
|
403
|
+
/>,
|
|
404
|
+
);
|
|
405
|
+
expect(screen.getByRole("group", { name: /Strength/ })).toBeTruthy();
|
|
406
|
+
expect(screen.getByRole("button", { name: "10 mg" }).getAttribute("aria-pressed")).toBe("true");
|
|
407
|
+
expect(screen.getByRole("button", { name: "5 mg" }).getAttribute("aria-pressed")).toBe("false");
|
|
408
|
+
fireEvent.click(screen.getByRole("button", { name: "5 mg" }));
|
|
409
|
+
expect(onChange).toHaveBeenCalledWith("5");
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
it("ActionBar: holds the action", () => {
|
|
413
|
+
const onClick = vi.fn();
|
|
414
|
+
render(
|
|
415
|
+
<c.ActionBar>
|
|
416
|
+
<c.Button onClick={onClick}>Send prescription to patient</c.Button>
|
|
417
|
+
</c.ActionBar>,
|
|
418
|
+
);
|
|
419
|
+
const button = screen.getByRole("button", { name: "Send prescription to patient" });
|
|
420
|
+
fireEvent.click(button);
|
|
421
|
+
expect(onClick).toHaveBeenCalledOnce();
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
it("Alert with warning/critical tone is announced as an alert", () => {
|
|
425
|
+
render(<c.Alert tone="critical" title="Blocked" description="Allergy conflict" />);
|
|
426
|
+
expect(screen.getByRole("alert").textContent).toContain("Blocked");
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
it("Disclosure: the summary is a button with aria-expanded; children render only while open", () => {
|
|
430
|
+
const onOpenChange = vi.fn();
|
|
431
|
+
const { rerender } = render(
|
|
432
|
+
<c.Disclosure summary="1 allergy · 2 medications" open={false} onOpenChange={onOpenChange}>
|
|
433
|
+
<span>Penicillin</span>
|
|
434
|
+
</c.Disclosure>,
|
|
435
|
+
);
|
|
436
|
+
const toggle = screen.getByRole("button", { name: "1 allergy · 2 medications" });
|
|
437
|
+
expect(toggle.getAttribute("aria-expanded")).toBe("false");
|
|
438
|
+
expect(screen.queryByText("Penicillin")).toBeNull();
|
|
439
|
+
fireEvent.click(toggle);
|
|
440
|
+
expect(onOpenChange).toHaveBeenCalledWith(true);
|
|
441
|
+
|
|
442
|
+
rerender(
|
|
443
|
+
<c.Disclosure summary="1 allergy · 2 medications" open onOpenChange={onOpenChange}>
|
|
444
|
+
<span>Penicillin</span>
|
|
445
|
+
</c.Disclosure>,
|
|
446
|
+
);
|
|
447
|
+
expect(toggle.getAttribute("aria-expanded")).toBe("true");
|
|
448
|
+
expect(screen.getByText("Penicillin")).toBeTruthy();
|
|
449
|
+
fireEvent.click(toggle);
|
|
450
|
+
expect(onOpenChange).toHaveBeenLastCalledWith(false);
|
|
451
|
+
});
|
|
452
|
+
});
|
|
453
|
+
}
|