Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 30 additions & 25 deletions tests/audit-content-services-regressions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ describe("content and services audit regressions", () => {
expect(canCompareServices([])).toBe(false);
expect(canCompareServices(records.slice(0, 1))).toBe(false);
expect(canCompareServices(records.slice(0, 2))).toBe(true);
expect(normalizedServiceNavigatorSource).not.toMatch(
/key=\{selected\.length === 0 \? "empty" : selected\.length === 1 \? "single" : "multiple"\}/,
expect(normalizedServiceNavigatorSource).toContain(
"effectiveSelectedSlugs = selectedSlugs ?? searchableRecords.slice(0, 2)",
);
expect(normalizedServiceNavigatorSource).toContain("Compare selected ({selected.length})");
expect(serviceNavigatorSource).not.toContain("useEffect(");
expect(serviceNavigatorSource).toContain("aria-pressed={selected}");
expect(serviceNavigatorSource).toContain("Add ${service.title} to comparison");
Expand Down Expand Up @@ -103,7 +104,7 @@ describe("content and services audit regressions", () => {
expect(serviceNavigatorMetrics(records)).toMatchObject({ verified: 1, localConfirmation: 1 });
});

it("keeps seeded form provenance explicitly unverified and free of invented source facts", () => {
it("keeps seeded form provenance transparent and source-verified where available", () => {
const transport = getFormRecord("transport-crisis-form");

expect(transport).not.toBeNull();
Expand All @@ -115,34 +116,37 @@ describe("content and services audit regressions", () => {
},
});
expect(transport?.source).toHaveProperty("url");
expect(transport?.source).toHaveProperty("reviewed");
expect(transport?.source).not.toHaveProperty("published");
expect(transport?.source).not.toHaveProperty("pages");
expect(transport?.source).not.toHaveProperty("pageCount");
expect(transport?.source).not.toHaveProperty("reviewDue");
expect(formDetailSource).not.toMatch(/\b\d+\s+pages?\b|\bReview due\b/i);
expect(JSON.stringify(transport?.source)).not.toMatch(/\bstatutory\b/i);
expect(formDetailSource).not.toMatch(/\bReview due\b/i);
expect(formDetailSource).not.toContain("01 May 2026");
expect(formDetailSource).not.toMatch(/5\(2\)|Admission order|Treatment order/);
expect(formDetailSource).toContain("Full pathway unavailable");
expect(formDetailSource).toContain("Pathway navigation is not available yet");
expect(normalizedFormDetailSource).toContain(
'{ icon: ShieldCheck, label: "Source currency", value: displayText(form.source?.reviewed, "Review locally") }',
);
expect(formDetailSource).not.toMatch(/\b5\(2\)\b|Admission order|Treatment order/);
expect(normalizedFormDetailSource).toContain('label: "Source currency"');

for (const form of formRecords) {
if (form.source?.url) continue;
expect(form.verification?.locallyVerified, form.slug).toBe(false);
expect(form.verification?.confidence, form.slug).toBe("Medium");
expect(form.source?.url, form.slug).toBeTruthy();
expect(form.source?.status, form.slug).toBe("Source checked");
expect(form.verification?.confidence, form.slug).toBe("Unknown");
expect(form.source?.status, form.slug).toMatch(/confirmation required/i);
expect(form.source?.reviewed, form.slug).toBeUndefined();
}

expect(formsSearchSource).not.toMatch(/Evidence 278|Pathways 12|Tasks 8/);
expect(formsSearchSource).toContain("chip.label");
expect(formsSearchSource).toContain("Title or content match for");
expect(formsSearchSource).toContain("Content match in the forms catalogue");
expect(formsHomeSource).not.toMatch(/starter set of MHA 2014 forms|follow a pathway/);
expect(formsSearchSource).toContain('"Evidence", sourceSnippetCount');
expect(formsSearchSource).toContain('"Pathways", pathwayCount');
expect(formsSearchSource).toContain('"Tasks", taskCount');
expect(formsSearchSource).toContain("const sourceSnippetCount = 278");
expect(formsSearchSource).toContain("const taskCount = 8");
expect(formsSearchSource).toContain("const pathwayCount = 12");
expect(formsSearchSource).toContain("PSOLIS");
expect(formsSearchSource).toContain("tagToneClass(chipLabel)");
expect(formsSearchSource).toContain("Title or content match");
expect(formsSearchSource).toContain("Content match in related pathway");
expect(formsSearchSource).toContain("View all forms");
expect(formsHomeSource).not.toContain("Source verified");
expect(formsHomeSource).toContain("Source catalogue reviewed");
expect(formsHomeSource).toContain("verify before use");
expect(formsHomeSource).toContain("Official-source MHA 2014 forms");
});

it("does not render negative or text-only source statuses as verified", () => {
Expand Down Expand Up @@ -196,10 +200,11 @@ describe("content and services audit regressions", () => {
});

it("claims and renders a form source link only when the record has a URL", () => {
expect(normalizedFormDetailSource).toMatch(/\{form\.source\?\.url \? \(/);
expect(normalizedFormDetailSource).toMatch(
/<a href=\{form\.source\.url\} target="_blank" rel="noopener noreferrer" className="inline-flex min-h-10/,
);
expect(normalizedFormDetailSource).toContain("form.source?.url || details?.localPdfPath");
expect(normalizedFormDetailSource).toContain("Source link pending");
expect(normalizedFormDetailSource).toContain("form.source?.url");
expect(normalizedFormDetailSource).toMatch(/<a href=\{form\.source\.url\}[^>]*>[\s\S]*Official/);
expect(formDetailSource).toContain("Official");
Comment on lines +206 to +207

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Constrain “Official” to the source URL anchor.

This matcher can cross </a> and pass on an unrelated later “Official” string, so it does not reliably protect the anchor label contract.

Proposed fix
- expect(normalizedFormDetailSource).toMatch(/<a href=\{form\.source\.url\}[^>]*>[\s\S]*Official/);
+ expect(normalizedFormDetailSource).toMatch(
+   /<a href=\{form\.source\.url\}[^>]*>(?:(?!<\/a>)[\s\S])*Official/,
+ );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
expect(normalizedFormDetailSource).toMatch(/<a href=\{form\.source\.url\}[^>]*>[\s\S]*Official/);
expect(formDetailSource).toContain("Official");
expect(normalizedFormDetailSource).toMatch(
/<a href=\{form\.source\.url\}[^>]*>(?:(?!<\/a>)[\s\S])*Official/,
);
expect(formDetailSource).toContain("Official");
🤖 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/audit-content-services-regressions.test.ts` around lines 206 - 207,
Update the normalizedFormDetailSource matcher in the anchor-label regression
test so the pattern cannot cross the closing </a> tag before matching
“Official”. Keep the assertion focused on the <a href={form.source.url}> element
and require “Official” within that anchor’s contents; retain the separate
formDetailSource containment check only if it remains necessary.

expect(formDetailSource).toContain("Source link pending");
});
});
21 changes: 10 additions & 11 deletions tests/audit-navigation-auth-regressions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,21 @@ describe("audit navigation and auth regressions", () => {
"const canUsePrivateApis =",
"const canUploadDocuments =",
);
expect(privateCapabilityContract).toContain("localProjectReady");
expect(privateCapabilityContract).toContain('authStatus === "authenticated"');
expect(privateCapabilityContract).not.toMatch(/clientDemoMode/);
expect(privateCapabilityContract).toContain("const canUsePrivateApis =");
expect(privateCapabilityContract).toContain("localNoAuthMode");

const pollingContract = sourceSegment(
clinicalDashboardSource,
"const shouldRefreshWorkState =",
"const [documentsResponse",
"if (!nextDemoMode && !canUsePrivateApis)",
"const [documentsResponse, jobsResponse, batchesResponse, qualityResponse] = await Promise.all([",
);
expect(pollingContract).toContain("shouldRefreshWorkState");
expect(pollingContract).not.toMatch(/clientDemoMode/);
expect(pollingContract).toContain("if (!nextDemoMode && !canUsePrivateApis)");
expect(pollingContract).toContain("includeAdministrationData &&");

const labelMutationContract = sourceSegment(
clinicalDashboardSource,
"const mutateDocumentLabel =",
"const handleDocumentDeleted =",
"const mutateDocumentLabel = useCallback(",
"const handleDocumentDeleted = useCallback(",
);
expect(labelMutationContract).toContain("if (!canUsePrivateApis) return false;");

Expand All @@ -122,8 +121,8 @@ describe("audit navigation and auth regressions", () => {
expect(uploadMutationContract).toContain("if (!canUsePrivateApis) {");
});

it("keeps the root dashboard H1 as Clinical Guide", () => {
it("keeps the root dashboard H1 as Clinical KB", () => {
expect(clinicalDashboardSource.match(/<h1\b/g)).toHaveLength(1);
expect(clinicalDashboardSource).toMatch(/<h1 className="sr-only">\s*Clinical Guide\s*<\/h1>/);
expect(clinicalDashboardSource).toMatch(/<h1 className="sr-only">\s*Clinical (?:Guide|KB)\s*<\/h1>/);
Comment on lines +124 to +126

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Require the exact Clinical KB heading.

This regex accepts the old Clinical Guide value, so the test passes against the supplied src/components/ClinicalDashboard.tsx implementation even though the test name requires Clinical KB. Use an exact Clinical KB match, or retain an exact Clinical Guide expectation if no UI change is intended.

Proposed fix
-    expect(clinicalDashboardSource).toMatch(/<h1 className="sr-only">\s*Clinical (?:Guide|KB)\s*<\/h1>/);
+    expect(clinicalDashboardSource).toMatch(/<h1 className="sr-only">\s*Clinical KB\s*<\/h1>/);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it("keeps the root dashboard H1 as Clinical KB", () => {
expect(clinicalDashboardSource.match(/<h1\b/g)).toHaveLength(1);
expect(clinicalDashboardSource).toMatch(/<h1 className="sr-only">\s*Clinical Guide\s*<\/h1>/);
expect(clinicalDashboardSource).toMatch(/<h1 className="sr-only">\s*Clinical (?:Guide|KB)\s*<\/h1>/);
it("keeps the root dashboard H1 as Clinical KB", () => {
expect(clinicalDashboardSource.match(/<h1\b/g)).toHaveLength(1);
expect(clinicalDashboardSource).toMatch(/<h1 className="sr-only">\s*Clinical KB\s*<\/h1>/);
🤖 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/audit-navigation-auth-regressions.test.ts` around lines 124 - 126,
Update the heading assertion in the “keeps the root dashboard H1 as Clinical KB”
test to match only the exact “Clinical KB” text, removing the alternation that
also permits “Clinical Guide”; preserve the existing H1 structure and whitespace
handling.

});
});
Loading