// Who the public pages say Context is for (VITE_CONTEXT_OPEN): the closed pilot unless the build
// says it is open, with Request access working the same either way. Rendered as the server would.
import { createElement } from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { afterEach, describe, expect, it, vi } from "vitest";
import Landing from "../src/clinician/site/Landing";
import RequestAccess from "../src/clinician/site/RequestAccess";
import { emptyAccessForm, toAccessRequest, validateAccess } from "../src/logic/access";
import { contextOpen, PILOT_LINE, siteWords } from "../src/logic/site";
const page = (component: () => unknown) =>
renderToStaticMarkup(createElement(component as never)).replace(/'/g, "'").replace(/"/g, '"').replace(/&/g, "&");
const OPEN_LINE = "MARMAR Context is open to clinicians in Nigeria.";
afterEach(() => {
vi.unstubAllEnvs();
});
describe("who the public pages say Context is for", () => {
it("is the closed pilot unless VITE_CONTEXT_OPEN is exactly true", () => {
for (const value of [undefined, "", "false", "TRUE", " true", "yes"]) expect(contextOpen(value)).toBe(false);
expect(contextOpen("true")).toBe(true);
});
it("says the pilot plainly on the home page and on Request access while closed", () => {
vi.stubEnv("VITE_CONTEXT_OPEN", "");
const home = page(Landing);
expect(home).toContain(PILOT_LINE);
expect(home).not.toContain(OPEN_LINE);
const request = page(RequestAccess);
expect(request).toContain("MARMAR Context is in a small pilot with clinicians in Lagos. Request access and we'll tell you when it opens to more clinicians.");
expect(request).not.toContain("Nigeria.");
expect(siteWords(false).receiptNext("MDCN")).toBe(
"MARMAR Context is in a small pilot with clinicians in Lagos. We keep your request, check your licence with the MDCN register, and email you when it opens to you.",
);
});
it("brings back today's wording when the build says Context is open", () => {
vi.stubEnv("VITE_CONTEXT_OPEN", "true");
const home = page(Landing);
expect(home).toContain(`${OPEN_LINE} Request access with your licence, or try it now with a fictional patient.`);
expect(home).not.toContain("small pilot");
expect(page(RequestAccess)).not.toContain("small pilot");
expect(siteWords(true).receiptNext("PCN")).toContain("usually within 2 working days");
});
it("keeps Request access working in both: the same form, the same checks, the same request", () => {
const form = { ...emptyAccessForm(), fullName: "Ada Obi", profession: "doctor" as const, licenceNumber: "MDCN/R/123456", clinicName: "Yaba Clinic",
clinicPhone: "+234 1 555 0100", workEmail: "ada@example.test", mobile: "+234 803 555 0100", heardFrom: "film" as const, acceptedTerms: true };
for (const open of ["", "true"]) {
vi.stubEnv("VITE_CONTEXT_OPEN", open);
const html = page(RequestAccess);
for (const id of ["acc-fullName", "acc-licenceNumber", "acc-workEmail", "acc-mobile", "acc-clinicName", "acc-acceptedTerms"]) expect(html).toContain(`id="${id}"`);
expect(html).toContain("Send request");
expect(validateAccess(form)).toEqual({});
expect(toAccessRequest(form, null)).toMatchObject({ country: "NG", mobile: "+234 803 555 0100", licensingBody: "MDCN" });
}
});
it("asks for the mobile with its country code, since urgent alerts text it", () => {
const form = { ...emptyAccessForm(), mobile: "0803 123 4567" };
expect(validateAccess(form).mobile).toBe("Enter your mobile number with its country code, for example +234 803 123 4567.");
expect(validateAccess({ ...form, mobile: "00234 803 123 4567" }).mobile).toBeUndefined();
});
});