Skip to content

[QA-223] Add per-file E2E config override seam for patient registration - #16585

Open
nihal467 wants to merge 5 commits into
developfrom
e2e/patient-registration-config-overrides
Open

[QA-223] Add per-file E2E config override seam for patient registration#16585
nihal467 wants to merge 5 commits into
developfrom
e2e/patient-registration-config-overrides

Conversation

@nihal467

@nihal467 nihal467 commented Jul 20, 2026

Copy link
Copy Markdown
Member

Proposed Changes

Adds a small, build-flag-gated seam so Playwright specs can control patient-registration config flags per test file without editing .env.local.

Why

Build-time import.meta.env.REACT_* values are inlined and frozen into the production bundle, so specs running against the preview build cannot flip them per file. This adds a runtime window.__CARE_E2E_CONFIG__ seam that care.config.ts consults first.

What

  • care.config.ts — new E2EConfigOverrides seam that reads window.__CARE_E2E_CONFIG__, gated behind the new REACT_ENABLE_E2E_CONFIG_OVERRIDES build flag (default off, completely inert in normal production builds). Currently supports minimalPatientRegistration and minGeoOrganizationLevelsRequired.
  • package.json — new build:e2e script that builds with the flag enabled.
  • src/vite-env.d.ts — type for the new env var.
  • tests/helper/careConfig.tsapplyCareConfig(page, config) helper using page.addInitScript (runs before app scripts load).
  • tests/facility/patient/patientRegistration.spec.ts — example specs demonstrating per-file overrides for minimal registration and reduced geo-org levels.

Notes

  • Not a security boundary: the affected flags only relax client-side form validation; the backend independently enforces required fields.
  • The override is set per test context via addInitScript, so it applies to that test only and is torn down automatically.

@ohcnetwork/care-fe-code-reviewers

Summary by CodeRabbit

  • New Features
    • Added end-to-end, runtime patient-registration configuration overrides (E2E-only), enabled via a build-time flag.
    • Added a dedicated build:e2e script to run builds with overrides turned on.
  • Tests
    • Added per-file E2E scenarios for patient-registration overrides (minimal registration and limiting geo-organization selection).
    • Added patient card validation and conditional skipping when override support is inactive.

Adds a build-flag-gated (REACT_ENABLE_E2E_CONFIG_OVERRIDES) window seam in
care.config.ts so Playwright specs can flip minimalPatientRegistration and
minGeoOrganizationLevelsRequired per test file via page.addInitScript,
without editing .env.local. Includes a build:e2e script, the applyCareConfig
test helper, and example specs.
@nihal467
nihal467 requested review from a team and Copilot July 20, 2026 14:18
@github-actions

Copy link
Copy Markdown

⚠️ Merge Checklist Incomplete

Thank you for your contribution! To help us review your PR efficiently, please complete the merge checklist in your PR description.

Your PR will be reviewed once you have marked the appropriate checklist items.

To update the checklist:

  • Change - [ ] to - [x] for completed items
  • Only check items that are relevant to your PR
  • Leave items unchecked if they don't apply

The checklist helps ensure code quality, testing coverage, and documentation are properly addressed.

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 035a8d4a-93c6-4d4d-803d-23b37af42fee

📥 Commits

Reviewing files that changed from the base of the PR and between 047ddcf and 7a2b1c1.

📒 Files selected for processing (1)
  • tests/facility/patient/patientRegistration.spec.ts

Walkthrough

Changes

Adds a build-gated window.__CARE_E2E_CONFIG__ override path for patient-registration settings, Playwright helpers for injecting and detecting overrides, and E2E scenarios covering minimal registration and one-level geo-organization registration.

Patient registration E2E overrides

Layer / File(s) Summary
Runtime override resolution
care.config.ts, src/vite-env.d.ts, package.json
E2E builds enable browser-side configuration overrides, which take precedence over existing patient-registration environment settings.
Playwright override injection
tests/helper/careConfig.ts
Typed test configuration is injected before application scripts load, and tests can detect whether the override seam is active.
Registration scenario coverage
tests/facility/patient/patientRegistration.spec.ts
Tests cover minimal registration, reduced geo-organization requirements, and verification of the created patient card.

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the change well, but it omits the required Fixes #issue_number line and the merge checklist section. Add a Fixes #issue_number line and include the template's merge checklist items, or mark any unavailable items as not applicable.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is clear, specific, and matches the main change: adding an E2E config override seam for patient registration.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch e2e/patient-registration-config-overrides

Comment @coderabbitai help to get the list of available commands.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 20, 2026

Copy link
Copy Markdown

Deploying care-preview with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7a2b1c1
Status: ✅  Deploy successful!
Preview URL: https://bc03779b.care-preview-a7w.pages.dev
Branch Preview URL: https://e2e-patient-registration-con.care-preview-a7w.pages.dev

View logs

@nihal467 nihal467 changed the title 🧪 Add per-file E2E config override seam for patient registration [QA-223] Add per-file E2E config override seam for patient registration Jul 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a build-flag-gated runtime config override seam to let Playwright E2E specs control select patient-registration flags per test file (via page.addInitScript), without editing .env.local, addressing the fact that import.meta.env.REACT_* values are inlined into the preview bundle.

Changes:

  • Introduces window.__CARE_E2E_CONFIG__ override support in care.config.ts, gated by REACT_ENABLE_E2E_CONFIG_OVERRIDES.
  • Adds a build:e2e script and env typing to enable the seam for E2E builds.
  • Adds a Playwright helper (applyCareConfig) and example specs demonstrating per-file overrides.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
care.config.ts Adds gated runtime override seam for patient-registration config used by E2E.
package.json Adds build:e2e script to build with overrides enabled.
src/vite-env.d.ts Types the new REACT_ENABLE_E2E_CONFIG_OVERRIDES env var.
tests/helper/careConfig.ts Adds applyCareConfig(page, config) helper using page.addInitScript.
tests/facility/patient/patientRegistration.spec.ts Demonstrates per-file config overrides with new helper and assertions.

Comment thread tests/facility/patient/patientRegistration.spec.ts Outdated
Comment thread care.config.ts Outdated
Comment on lines +72 to +77
const e2eConfigOverrides: E2EConfigOverrides =
booleanFromString(env.REACT_ENABLE_E2E_CONFIG_OVERRIDES, false) &&
typeof window !== "undefined"
? ((window as unknown as { __CARE_E2E_CONFIG__?: E2EConfigOverrides })
.__CARE_E2E_CONFIG__ ?? {})
: {};
@greptile-apps

greptile-apps Bot commented Jul 20, 2026

Copy link
Copy Markdown

Greptile Summary

This PR introduces a build-flag-gated runtime seam (window.__CARE_E2E_CONFIG__) that lets Playwright specs override patient-registration config flags per test file, without touching .env.local or rebuilding for each scenario.

  • care.config.ts gains readE2EConfigOverrides(), which reads the window seam only when REACT_ENABLE_E2E_CONFIG_OVERRIDES=true is baked into the build; type-checking and bounds-checking (levels >= 1) prevent malformed values from being applied.
  • tests/helper/careConfig.ts provides applyCareConfig (must be called before page.goto) and isCareConfigOverrideActive (must be called after page.goto) with clearly documented ordering contracts.
  • patientRegistration.spec.ts adds two new test cases exercising the seam — minimal registration and single geo-org level — each guarded with test.skip so they degrade gracefully when run against a standard build.

Confidence Score: 5/5

Safe to merge — the override seam is completely inert in normal production builds and the type/bounds validation in readE2EConfigOverrides is solid.

All changes are either test-only or gated behind a build flag that is off by default. The production bundle is unaffected. The runtime parsing in care.config.ts carefully validates types and enforces minGeoOrganizationLevelsRequired >= 1 before applying any override. The test helpers document their ordering constraints clearly, and the new specs degrade gracefully via test.skip when run against a non-e2e build.

No files require special attention.

Important Files Changed

Filename Overview
care.config.ts Adds a runtime E2E override seam gated behind REACT_ENABLE_E2E_CONFIG_OVERRIDES; validates field types and enforces levels >= 1 before applying; completely inert in normal builds.
tests/helper/careConfig.ts New helper that injects window.CARE_E2E_CONFIG via page.addInitScript and exposes isCareConfigOverrideActive for guarding skips; ordering contract (applyCareConfig before goto, check after goto) is clearly documented.
tests/facility/patient/patientRegistration.spec.ts Adds two new E2E tests exercising the config override seam; adds verifyPatientCard helper for post-registration assertions; test.skip guards handle missing build flag at runtime.
package.json Adds build:e2e script that sets REACT_ENABLE_E2E_CONFIG_OVERRIDES=true before the normal build pipeline.
src/vite-env.d.ts Adds REACT_ENABLE_E2E_CONFIG_OVERRIDES to ImportMetaEnv; straightforward type-only addition.

Reviews (4): Last reviewed commit: "test(e2e): scope patient card age/gender..." | Re-trigger Greptile

Comment thread care.config.ts
Comment on lines +486 to +497
const additionalDetailsSectionText =
await additionalDetailsSection.textContent();

if (additionalDetailsSectionText?.toLowerCase().includes("optional")) {
await additionalDetailsSection.click();
}

await page
.getByRole("textbox", { name: "Address" })
.fill(patientData.address);
await page
.getByRole("spinbutton", { name: "PIN Code" })

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Fragile section-expansion guard in the geo-org test

The test checks additionalDetailsSectionText?.toLowerCase().includes("optional") to decide whether to click and expand the "Additional Details" section, mirroring the same pattern already in fillAdditionalDetails. If the section is collapsed but its label text doesn't contain "optional" (e.g. the label changes or the section is required in a different locale), the if block is skipped, the section remains closed, and the subsequent getByRole("textbox", { name: "Address" }) fill will fail silently or throw. Checking aria-expanded on the trigger button would be a more robust signal of the section's open/closed state.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@care.config.ts`:
- Around line 53-78: Export the E2EConfigOverrides type used by the window
override in care.config.ts. In tests/helper/careConfig.ts, remove the duplicate
CareE2EConfig declaration and import the exported type from care.config.ts,
confirming the test TypeScript/build configuration supports that src import;
update both affected sites so the app and tests share one override contract.

In `@tests/helper/careConfig.ts`:
- Around line 10-13: Remove the duplicate CareE2EConfig shape and reuse the
existing E2EConfigOverrides type from care.config.ts for the same configuration
contract. Update dependent references in the careConfig test helper to import
and use E2EConfigOverrides, keeping the existing optional fields and behavior
unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4bebee06-cd95-47b2-b00b-5c2a7bdb3e59

📥 Commits

Reviewing files that changed from the base of the PR and between 70b2972 and 58ff077.

📒 Files selected for processing (5)
  • care.config.ts
  • package.json
  • src/vite-env.d.ts
  • tests/facility/patient/patientRegistration.spec.ts
  • tests/helper/careConfig.ts

Comment thread care.config.ts
Comment on lines +53 to +78
/**
* E2E test-only runtime overrides for patient-registration config.
*
* Build-time `import.meta.env.REACT_*` values are inlined and frozen into the
* bundle, so Playwright specs (which run against the production `preview`
* build) cannot flip them per test file. To make per-file control possible, a
* spec sets `window.__CARE_E2E_CONFIG__` via `page.addInitScript(...)` — which
* runs before this module loads — and the values below are consulted first.
*
* This seam is gated behind the `REACT_ENABLE_E2E_CONFIG_OVERRIDES` build flag
* (default off), so it is completely inert in normal production builds. The
* affected flags only relax client-side form validation; the backend
* independently enforces required fields, so this is not a security boundary.
*/
interface E2EConfigOverrides {
minGeoOrganizationLevelsRequired?: number;
minimalPatientRegistration?: boolean;
}

const e2eConfigOverrides: E2EConfigOverrides =
booleanFromString(env.REACT_ENABLE_E2E_CONFIG_OVERRIDES, false) &&
typeof window !== "undefined"
? ((window as unknown as { __CARE_E2E_CONFIG__?: E2EConfigOverrides })
.__CARE_E2E_CONFIG__ ?? {})
: {};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

E2EConfigOverrides and CareE2EConfig duplicate the same override contract across app and test code. Both types describe the identical window.__CARE_E2E_CONFIG__ shape by hand, with no import relationship, so the two can silently drift out of sync as fields are added or changed.

  • care.config.ts#L53-L78: export E2EConfigOverrides (or an equivalent shared type) so it can be reused, instead of keeping it private to this module.
  • tests/helper/careConfig.ts#L10-L13: import the exported type from care.config.ts (or a shared location both files can reach) instead of redeclaring CareE2EConfig independently; verify the tests' tsconfig/build setup permits importing from src before doing so.
📍 Affects 2 files
  • care.config.ts#L53-L78 (this comment)
  • tests/helper/careConfig.ts#L10-L13
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@care.config.ts` around lines 53 - 78, Export the E2EConfigOverrides type used
by the window override in care.config.ts. In tests/helper/careConfig.ts, remove
the duplicate CareE2EConfig declaration and import the exported type from
care.config.ts, confirming the test TypeScript/build configuration supports that
src import; update both affected sites so the app and tests share one override
contract.

Comment on lines +10 to +13
export type CareE2EConfig = {
minimalPatientRegistration?: boolean;
minGeoOrganizationLevelsRequired?: number;
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Shape duplicates E2EConfigOverrides in care.config.ts.

Both types describe the same override contract but are maintained independently. See the consolidated comment for the shared fix across both files.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/helper/careConfig.ts` around lines 10 - 13, Remove the duplicate
CareE2EConfig shape and reuse the existing E2EConfigOverrides type from
care.config.ts for the same configuration contract. Update dependent references
in the careConfig test helper to import and use E2EConfigOverrides, keeping the
existing optional fields and behavior unchanged.

@github-actions

github-actions Bot commented Jul 20, 2026

Copy link
Copy Markdown

🎭 Playwright Test Results

Status: ❌ Failed
Test Shards: 3

Metric Count
Total Tests 334
✅ Passed 332
❌ Failed 2
⏭️ Skipped 0

📊 Detailed results are available in the playwright-final-report artifact.

Run: #10332

@nihal467

Copy link
Copy Markdown
Member Author

@copilot fix all the AI review comments and the ci/cd failure, make sure it passes fully

Comment thread tests/facility/patient/patientRegistration.spec.ts
Co-authored-by: nihal467 <57055998+nihal467@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 20, 2026 14:40
Co-authored-by: nihal467 <57055998+nihal467@users.noreply.github.com>

Copilot AI commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

@copilot fix all the AI review comments and the ci/cd failure, make sure it passes fully

Addressed all review feedback and the CI failure:

  • Defensive validation (care.config.ts): window.__CARE_E2E_CONFIG__ is now read via readE2EConfigOverrides(), which type-checks and coerces each field — minimalPatientRegistration is only applied when it's a real boolean, and minGeoOrganizationLevelsRequired only when it's an integer >= 1. Anything malformed (e.g. the string "false") is ignored rather than trusted.
  • Hardcoded timeout (patientRegistration.spec.ts): removed the per-expect { timeout: 15000 } in verifyPatientCard; it now relies on the global timeout with the existing waitForURL state wait.
  • CI failure: the config-override demo specs previously failed under CI's default npm run build (the seam is off, so overrides had no effect). They now detect activation via isCareConfigOverrideActive(page) (set by care.config.ts only when built with REACT_ENABLE_E2E_CONFIG_OVERRIDES) and skip themselves otherwise — no workflow changes needed. They run normally against npm run build:e2e.

Done in the latest commits.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

care.config.ts:77

  • The comment says fields are "type-checked and coerced", but the implementation only validates and conditionally applies values (no coercion is performed). Updating the wording avoids misleading future readers about the safety guarantees here.
 * or out of range. Each field is therefore type-checked and coerced, and

Comment thread care.config.ts Outdated
Comment on lines +168 to +172
await page.waitForURL("**/patients/home**");
await expect(page.getByRole("heading", { name: data.name })).toBeVisible();
await expect(
page.getByText(new RegExp(`Y,\\s*${data.gender}`, "i")).first(),
).toBeVisible();
Copilot AI review requested due to automatic review settings July 20, 2026 14:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 5 changed files in this pull request and generated no new comments.

@nihal467

Copy link
Copy Markdown
Member Author

@copilot resolve all the AI comment

Co-authored-by: nihal467 <57055998+nihal467@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 21, 2026 12:54

Copilot AI commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve all the AI comment

Resolved the remaining AI review comment: verifyPatientCard now scopes the age/gender assertion to the specific patient's hover-card element (matched via the name heading), so it can no longer match another patient's line elsewhere on the page. The other flagged items (defensive validation of window.__CARE_E2E_CONFIG__, the typeof window guard, and the hardcoded per-expect timeout) were already addressed in earlier commits.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.

Comment thread care.config.ts
Comment on lines +83 to +86
if (
!booleanFromString(env.REACT_ENABLE_E2E_CONFIG_OVERRIDES, false) ||
typeof window === "undefined"
) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants