Add interactive questionnaire editor and typed save payloads
This commit is contained in:
@@ -174,8 +174,11 @@ test("draft saves clear inactive answers and submit only effective answers", asy
|
||||
const recorder = new SaveEventRecorder(engine, event => events.push(event), { attending: true, supportRequired: true, supportDetails: "Ramp" });
|
||||
const session = engine.createSession({ fullName: "Alex", attending: false, supportRequired: true, supportDetails: "Ramp" }, today);
|
||||
await recorder.save(session, ["attending"], "blur", "registration");
|
||||
const patch = events.at(-1)!.data! as { changes: Answers };
|
||||
assert.deepEqual(patch.changes, { attending: false, supportRequired: null, supportDetails: null });
|
||||
assert.deepEqual(events.at(-1)!.data!.changes, {
|
||||
attending: { type: "boolean", value: false },
|
||||
supportRequired: { type: "boolean", value: null },
|
||||
supportDetails: { type: "text", value: null },
|
||||
});
|
||||
assert.deepEqual(session.getEffectiveAnswers(), { fullName: "Alex", attending: false });
|
||||
});
|
||||
test("employment changes clear occupation from live answers and draft patches", async () => {
|
||||
@@ -186,12 +189,16 @@ test("employment changes clear occupation from live answers and draft patches",
|
||||
const events: SaveEvent[] = [];
|
||||
const recorder = new SaveEventRecorder(engine, event => events.push(event), initial);
|
||||
await recorder.save(engine.createSession(updated, today), ["employmentStatus"], "Question blur", "claimantDetails");
|
||||
assert.deepEqual((events.at(-1)!.data! as { changes: Answers }).changes, { ...updated, unableToWork: null });
|
||||
assert.deepEqual(events.at(-1)!.data!.changes, {
|
||||
employmentStatus: { type: "select", value: "UNEMPLOYED" },
|
||||
occupation: { type: "text", value: null },
|
||||
unableToWork: { type: "boolean", value: null },
|
||||
});
|
||||
const restored = engine.createSession({ ...updated, employmentStatus: "FULL_TIME" }, today);
|
||||
assert.equal(restored.answers.occupation, null);
|
||||
assert.ok(restored.validateQuestion("occupation").some(issue => issue.severity === "ERROR"));
|
||||
await recorder.save(restored, ["employmentStatus"], "Question blur", "claimantDetails");
|
||||
assert.deepEqual((events.at(-1)!.data! as { changes: Answers }).changes, { employmentStatus: "FULL_TIME" });
|
||||
assert.deepEqual(events.at(-1)!.data!.changes, { employmentStatus: { type: "select", value: "FULL_TIME" } });
|
||||
});
|
||||
|
||||
test("newly hidden occupation is explicitly reset even without a previously saved value", async () => {
|
||||
@@ -203,9 +210,9 @@ test("newly hidden occupation is explicitly reset even without a previously save
|
||||
const recorder = new SaveEventRecorder(engine, event => events.push(event), initial);
|
||||
const session = engine.createSession({ employmentStatus: "UNEMPLOYED", occupation: null }, today);
|
||||
await recorder.save(session, ["employmentStatus"], "Question blur", "claimantDetails");
|
||||
const changes = (events.at(-1)!.data! as { changes: Answers }).changes;
|
||||
assert.equal(changes.employmentStatus, "UNEMPLOYED");
|
||||
assert.equal(changes.occupation, null);
|
||||
const changes = events.at(-1)!.data!.changes!;
|
||||
assert.deepEqual(changes.employmentStatus, { type: "select", value: "UNEMPLOYED" });
|
||||
assert.deepEqual(changes.occupation, { type: "text", value: null });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user