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
19 changes: 19 additions & 0 deletions builder-frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,22 @@ The component renders sanitized Markdown without template evaluation. Web links
accept HTTP(S) URLs and open in a new tab. Pending or failed evaluations hide old
instructions until fresh decisions arrive. Forms containing the component use
its progress heading; existing forms without it keep the legacy completion message.

## Unanswered questions in Next steps

For an undecided benefit, Next steps lists the form's question labels for missing
inputs used by that benefit's undecided checks. Shared inputs are deduplicated;
inputs used only by decided checks are omitted. Fields sharing a label add their
group's label, and items of a repeated section with more than one item are
numbered, such as "Age (Household member #2)". Questions a form condition
currently hides are left out, since no one can answer them. Zero, No, and explicit None
answers remain answered. The list uses the same normalized data sent to the
eligibility service, including unknown CRM prefill preserved as null.

Published screeners, Preview, and the print summary share these labels. Pending
or failed evaluations suppress old prompts along with old instructions, and
prompts disappear when the benefit is decided. Labels are kept separately from
answers in the results snapshot; answers and technical input paths are never
printed by this feature. If an input has no static form label, Next steps keeps
its general need-more-information message rather than inventing a question.
The CRM `nextSteps` extension continues to contain decided benefits only.
2 changes: 2 additions & 0 deletions builder-frontend/src/components/screener/FormRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ function FormRenderer({
additionalModules: [CustomFormFieldsModule, screeningResultsModule],
});
connectScreeningResults(form, {
schema: () => schema,
evaluatedAnswers: formData,
results,
screenerName,
pending,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,34 @@ it("shows decided benefits immediately, preserves answers/schema, and lists unde
expect((form as any)._getState().data).toEqual({});
});

it("lists missing questions for undecided benefits and hides stale questions while pending", async () => {
const { container, service } = await mount();
const current = result();
service.update(current, false, false, {
food: ["Your date of birth", "Annual income"],
});
await vi.waitFor(() =>
expect(container.textContent).toContain("Find answers to these questions"),
);
expect(container.textContent).toContain("Your date of birth");
service.update(current, true, false, { food: ["Your date of birth"] });
await vi.waitFor(() =>
expect(container.textContent).not.toContain("Your date of birth"),
);
service.update(
{ ...current, food: { ...current.food, result: "TRUE" } },
false,
false,
{},
);
await vi.waitFor(() =>
expect(container.textContent).toContain("Screening complete"),
);
expect(container.textContent).not.toContain(
"Find answers to these questions",
);
});

it("uses failed check aliases with name fallback and the analyst's note", async () => {
const { container, service } = await mount();
const results = result("FALSE");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Text,
} from "@bpmn-io/form-js-viewer";
import type { BenefitResult } from "@/types";
import type { UnansweredQuestions } from "@/utils/unansweredQuestions";
import { useScreeningResults } from "../screeningResults/useScreeningResults";
import {
NEXT_STEPS_TYPE,
Expand Down Expand Up @@ -106,7 +107,8 @@ export function NextSteps({ field }: { field: NextStepsField }) {
() => getService("screeningResults", false)?.showNextSteps(field.id),
[getService, field.id],
);
const { results, pending, failed, mode } = useScreeningResults();
const { results, pending, failed, mode, unansweredQuestions } =
useScreeningResults();
const benefits = Object.entries(results ?? {});
const complete =
benefits.length > 0 && benefits.every(([, benefit]) => isDecided(benefit));
Expand All @@ -124,6 +126,7 @@ export function NextSteps({ field }: { field: NextStepsField }) {
pending=${pending}
failed=${failed}
mode=${mode}
unansweredQuestions=${unansweredQuestions}
/>
</div>`;
}
Expand All @@ -136,6 +139,7 @@ export function NextStepsBody({
failed,
mode,
forPrint = false,
unansweredQuestions,
}: {
field: NextStepsField;
benefits: [string, BenefitResult][];
Expand All @@ -144,6 +148,7 @@ export function NextStepsBody({
failed: boolean;
mode: "live" | "editor";
forPrint?: boolean;
unansweredQuestions?: UnansweredQuestions;
}) {
if (failed)
return html`<div class="fjs-form-field bdt-next-steps">
Expand Down Expand Up @@ -186,6 +191,13 @@ export function NextStepsBody({
return html`<section key=${id}>
<h3>${benefit.name}</h3>
<p>Still needs more information.</p>
${!!unansweredQuestions?.[id]?.length &&
html`
<p>Find answers to these questions to continue:</p>
<ul>
${unansweredQuestions[id].map((label) => html`<li>${label}</li>`)}
</ul>
`}
</section>`;
if (hideDecided) return null;
const unmet = steps.unmetRequirements;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ it("prints current results and copied content with full URLs, without answers, a
const { button, service, container } = await mount();
expect(button.disabled).toBe(true);
service.setScreenerName("Local benefit screener");
service.update(results, false);
service.update(results, false, false, { utility: ["Your date of birth"] });
await vi.waitFor(() => expect(button.disabled).toBe(false));
let root!: HTMLElement;
let printing = false;
Expand All @@ -115,6 +115,7 @@ it("prints current results and copied content with full URLs, without answers, a
expect(root.textContent).toContain("Income limit");
expect(root.textContent).toContain("Ask about other help");
expect(root.textContent).toContain("Still needs more information");
expect(root.textContent).toContain("Your date of birth");
expect(root.textContent).toContain(
"https://example.org/apply?program=housing",
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export function PrintSummary() {
failed=${false}
mode="live"
forPrint=${true}
unansweredQuestions=${current.unansweredQuestions}
/>
<//>`,
root,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,18 @@ describe.each(["published", "preview"])(
document.body.replaceChildren();
});

async function mount() {
async function mount(
data: object = { answer: "Keep this answer" },
formSchema: object = schema,
) {
const [results, setResults] = createSignal<ScreenerResult>();
const [pending, setPending] = createSignal(false);
const [failed, setFailed] = createSignal(false);
const container = document.body.appendChild(
document.createElement("div"),
);
const common = {
formData: () => ({ answer: "Keep this answer" }),
formData: () => data,
hiddenQuestionPaths: () => [],
submitForm: vi.fn(),
results,
Expand All @@ -86,9 +89,9 @@ describe.each(["published", "preview"])(
render(
() =>
mode === "published" ? (
<PublishedForm schema={schema} {...common} />
<PublishedForm schema={formSchema} {...common} />
) : (
<PreviewForm schema={() => schema} {...common} />
<PreviewForm schema={() => formSchema} {...common} />
),
container,
),
Expand All @@ -110,6 +113,91 @@ describe.each(["published", "preview"])(
};
}

it("maps unanswered inputs to question labels and clears them after a decision", async () => {
const s = await mount({ answer: "" });
s.setResults({
benefit: {
name: "Benefit",
result: "UNABLE_TO_DETERMINE",
check_results: {
missing: {
result: "UNABLE_TO_DETERMINE",
inputPaths: ["answer"],
} as any,
},
},
});
await vi.waitFor(() =>
expect(s.snapshot().unansweredQuestions).toEqual({
benefit: ["Answer"],
}),
);
expect(s.snapshot()).not.toHaveProperty("answers");
const service = s.form.get("screeningResults") as ScreeningResultsService;
const questions = service.getSnapshot().unansweredQuestions;
s.setResults({
benefit: {
name: "Benefit",
result: "UNABLE_TO_DETERMINE",
check_results: {
missing: {
result: "UNABLE_TO_DETERMINE",
inputPaths: ["answer"],
} as any,
},
},
});
expect(service.getSnapshot().unansweredQuestions).toBe(questions);
s.setResults({
benefit: { name: "Benefit", result: "TRUE", check_results: {} },
});
await vi.waitFor(() =>
expect(s.snapshot().unansweredQuestions).toEqual({}),
);
});

it("leaves out unanswered questions a condition hides", async () => {
const s = await mount(
{ answer: "", married: false },
{
...schema,
components: [
...schema.components,
{
id: "married",
type: "checkbox",
key: "married",
label: "Married",
},
{
id: "spouseIncome",
type: "number",
key: "spouse.income",
label: "Spouse income",
conditional: { hide: "=married != true" },
},
],
},
);
s.setResults({
benefit: {
name: "Benefit",
result: "UNABLE_TO_DETERMINE",
check_results: {
missing: {
result: "UNABLE_TO_DETERMINE",
inputPaths: ["answer", "spouse.income"],
} as any,
},
},
});
await vi.waitFor(() =>
expect(s.snapshot().unansweredQuestions).toEqual({
benefit: ["Answer"],
}),
);
});

it("updates custom fields without reimporting the schema or submitting answers", async () => {
const s = await mount();
const importSchema = vi.spyOn(s.form, "importSchema");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ const decided: ScreenerResult = {
};

describe("screening results service", () => {
it("publishes immutable question labels without storing the evaluated answers", () => {
const { service } = setup();
const questions = { benefit: ["Annual income"] };
service.update(decided, false, false, questions);
expect(service.getSnapshot().unansweredQuestions).toBe(questions);
expect(() => questions.benefit.push("Later edit")).toThrow(TypeError);
expect(service.getSnapshot().unansweredQuestions).toEqual({
benefit: ["Annual income"],
});
service.update(decided, false);
expect(service.getSnapshot().unansweredQuestions).toBeUndefined();
});
it("keeps the screener name local to the form without notifying results subscribers", () => {
const { service } = setup();
const other = setup().service;
Expand Down
Loading
Loading