fix(frontend): refresh the landing page, keep the employer sidebar full height, and align the candidate home
This commit is contained in:
1 parent
ac57c05aca
commit
a5990d3fc6
12 files changed
+460
-51
No files matched your search
@@ -2,6 +2,7 @@ import { describe, expect, it, vi } from "vitest";
|
||||
import { ApiRequestError, networkErrorCode } from "../../../shared/api";
|
||||
import type {
|
||||
AssessmentAvailability,
|
||||
AssessmentResultHistoryPage,
|
||||
CandidateProfile,
|
||||
CandidateQuestionnaire,
|
||||
} from "../../../shared/api/schemas";
|
||||
@@ -36,29 +37,35 @@ const availability = {
|
||||
{ specialization: "backend", confirmed_grade: null, active_attempt_id: null, grades: [] },
|
||||
],
|
||||
} as AssessmentAvailability;
|
||||
const results = {
|
||||
items: [],
|
||||
page: { has_more: false, next_cursor: null },
|
||||
} as AssessmentResultHistoryPage;
|
||||
|
||||
function apiError(status: number) {
|
||||
return new ApiRequestError({ status, code: networkErrorCode, title: "Failed." });
|
||||
}
|
||||
|
||||
describe("combineJourneyReads", () => {
|
||||
it("stays pending until all three reads arrive", () => {
|
||||
it("stays pending until all four reads arrive", () => {
|
||||
const state = combineJourneyReads(
|
||||
"candidate_profile",
|
||||
read("success", profile),
|
||||
read("pending"),
|
||||
read("success", availability),
|
||||
read("success", results),
|
||||
);
|
||||
|
||||
expect(state).toEqual({ status: "pending" });
|
||||
});
|
||||
|
||||
it("builds the journey from the three reads", () => {
|
||||
it("builds the journey from the four reads", () => {
|
||||
const state = combineJourneyReads(
|
||||
"candidate_assessment",
|
||||
read("success", profile),
|
||||
read("success", questionnaire),
|
||||
read("success", availability),
|
||||
read("success", results),
|
||||
);
|
||||
|
||||
expect(state.status).toBe("success");
|
||||
@@ -75,6 +82,20 @@ describe("combineJourneyReads", () => {
|
||||
read("error", undefined, failure),
|
||||
read("success", questionnaire),
|
||||
read("success", availability),
|
||||
read("success", results),
|
||||
);
|
||||
|
||||
expect(state).toMatchObject({ status: "error", error: failure });
|
||||
});
|
||||
|
||||
it("fails when the results read fails, so a confirmed category is never hidden", () => {
|
||||
const failure = apiError(500);
|
||||
const state = combineJourneyReads(
|
||||
"candidate_assessment",
|
||||
read("success", profile),
|
||||
read("success", questionnaire),
|
||||
read("success", availability),
|
||||
read("error", undefined, failure),
|
||||
);
|
||||
|
||||
expect(state).toMatchObject({ status: "error", error: failure });
|
||||
@@ -90,6 +111,7 @@ describe("combineJourneyReads", () => {
|
||||
read("error", undefined, apiError(500), failedProfile),
|
||||
read("success", questionnaire, null, okQuestionnaire),
|
||||
read("error", undefined, denied, failedAvailability),
|
||||
read("success", results),
|
||||
);
|
||||
|
||||
expect(state.status).toBe("error");
|
||||
|
||||
@@ -28,6 +28,9 @@ type CandidateProfileVersion = Pick<CandidateProfile, "version">;
|
||||
|
||||
const homeQueryPrefix = ["candidate-home"] as const;
|
||||
|
||||
/** Largest page the results list accepts; see ListMyAssessmentResults. */
|
||||
const homeResultsPageSize = 50;
|
||||
|
||||
/** Account-scoped keys: a response for one account never fills another's cache. */
|
||||
export const candidateHomeQueryKeys = {
|
||||
root: homeQueryPrefix,
|
||||
@@ -117,12 +120,17 @@ export function useCandidateAvailabilityRead(session: Session | undefined) {
|
||||
);
|
||||
}
|
||||
|
||||
/** Newest real result only: the home screen links to the full history. */
|
||||
/**
|
||||
* The first page of real results, newest first. The home screen shows its
|
||||
* first item as the last result and reads the current category of each
|
||||
* specialization from the newest decision in the same page. The page size is
|
||||
* the maximum of the list endpoint; the full history stays on the results page.
|
||||
*/
|
||||
export function useCandidateLatestResultRead(session: Session | undefined) {
|
||||
return useHomeQuery<AssessmentResultHistoryPage>(
|
||||
session,
|
||||
candidateHomeQueryKeys.latestResult,
|
||||
(signal) => listMyAssessmentResults({ limit: 1 }, { signal }),
|
||||
(signal) => listMyAssessmentResults({ limit: homeResultsPageSize }, { signal }),
|
||||
AssessmentResultHistoryPage,
|
||||
);
|
||||
}
|
||||
@@ -154,18 +162,21 @@ function isAccessError(error: unknown): boolean {
|
||||
}
|
||||
|
||||
/**
|
||||
* Joins the three reads that the next step depends on. One failed read fails
|
||||
* the whole state, because a step chosen from partial data could send the
|
||||
* candidate to a form they already completed. A denied read wins over other
|
||||
* failures so that the forbidden state is shown instead of a retry.
|
||||
* Joins the four reads that the next step depends on: the profile version,
|
||||
* the questionnaire, the assessment availability, and the first page of
|
||||
* results. One failed read fails the whole state, because a step chosen from
|
||||
* partial data could send the candidate to a form they already completed, or
|
||||
* hide a confirmed category. A denied read wins over other failures so that
|
||||
* the forbidden state is shown instead of a retry.
|
||||
*/
|
||||
export function combineJourneyReads(
|
||||
savedStep: CandidateJourney["savedStep"],
|
||||
profile: ReadResult<CandidateProfileVersion>,
|
||||
questionnaire: ReadResult<CandidateQuestionnaire>,
|
||||
availability: ReadResult<AssessmentAvailability>,
|
||||
results: ReadResult<AssessmentResultHistoryPage>,
|
||||
): CandidateJourneyState {
|
||||
const reads = [profile, questionnaire, availability];
|
||||
const reads = [profile, questionnaire, availability, results];
|
||||
const failed = reads.filter((read) => read.status === "error");
|
||||
if (failed.length > 0) {
|
||||
const denied = failed.find((read) => isAccessError(read.error));
|
||||
@@ -178,7 +189,12 @@ export function combineJourneyReads(
|
||||
},
|
||||
};
|
||||
}
|
||||
if (profile.data === undefined || questionnaire.data === undefined || !availability.data) {
|
||||
if (
|
||||
profile.data === undefined ||
|
||||
questionnaire.data === undefined ||
|
||||
!availability.data ||
|
||||
results.data === undefined
|
||||
) {
|
||||
return { status: "pending" };
|
||||
}
|
||||
return {
|
||||
@@ -188,6 +204,7 @@ export function combineJourneyReads(
|
||||
profileVersion: profile.data.version,
|
||||
questionnaire: questionnaire.data,
|
||||
availability: availability.data,
|
||||
results: results.data,
|
||||
}),
|
||||
};
|
||||
}
|
||||
@@ -197,6 +214,13 @@ export function useCandidateJourney(session: Session | undefined): CandidateJour
|
||||
const profile = useCandidateProfileRead(session);
|
||||
const questionnaire = useCandidateQuestionnaireRead(session);
|
||||
const availability = useCandidateAvailabilityRead(session);
|
||||
const results = useCandidateLatestResultRead(session);
|
||||
if (!session) return { status: "pending" };
|
||||
return combineJourneyReads(session.account.onboarding_step, profile, questionnaire, availability);
|
||||
return combineJourneyReads(
|
||||
session.account.onboarding_step,
|
||||
profile,
|
||||
questionnaire,
|
||||
availability,
|
||||
results,
|
||||
);
|
||||
}
|
||||
@@ -54,12 +54,49 @@ function questionnaire(
|
||||
};
|
||||
}
|
||||
|
||||
type ResultRow = CandidateJourneyInput["results"]["items"][number];
|
||||
|
||||
/**
|
||||
* One real result as the results list returns it. A v2 result carries the
|
||||
* category decision with the grade in force when the attempt ended; a legacy
|
||||
* result carries none.
|
||||
*/
|
||||
function resultRow(
|
||||
specialization: SpecializationCode,
|
||||
options: { grade?: GradeCode | null; decidedAt?: string; legacy?: boolean } = {},
|
||||
): ResultRow {
|
||||
const grade = options.grade ?? null;
|
||||
const decision = options.legacy
|
||||
? {}
|
||||
: {
|
||||
category_decision: {
|
||||
status: grade ? "assigned" : "not_eligible",
|
||||
previous_confirmed_grade: null,
|
||||
current_confirmed_grade: grade,
|
||||
method: grade ? "demo_basic_pass_mark" : null,
|
||||
source: grade ? "synthetic_demo" : null,
|
||||
calibration_status: "uncalibrated",
|
||||
},
|
||||
};
|
||||
return {
|
||||
kind: "root",
|
||||
attempt_id: "0199b4f2-7c1e-7d3a-9f00-aabbccddee10",
|
||||
specialization,
|
||||
outcome: grade ? "confirmed" : "not_confirmed",
|
||||
confirmed_grade: grade,
|
||||
previous_confirmed_grade: null,
|
||||
decided_at: options.decidedAt ?? "2026-10-08T10:00:00Z",
|
||||
...decision,
|
||||
} as unknown as ResultRow;
|
||||
}
|
||||
|
||||
function input(overrides: Partial<CandidateJourneyInput> = {}): CandidateJourneyInput {
|
||||
return {
|
||||
savedStep: "candidate_consents",
|
||||
profileVersion: 0,
|
||||
questionnaire: questionnaire([]),
|
||||
availability: { specializations: [] },
|
||||
results: { items: [] },
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
@@ -197,6 +234,115 @@ describe("buildCandidateJourney next step", () => {
|
||||
});
|
||||
});
|
||||
|
||||
// Regression: the availability read reported no confirmed grade for a candidate
|
||||
// whose newest result confirmed Junior, so the next step said "take the test"
|
||||
// while the result block said the category was confirmed.
|
||||
describe("buildCandidateJourney confirmed category", () => {
|
||||
it("confirms the category from the newest result when the availability read has none", () => {
|
||||
const journey = buildCandidateJourney(
|
||||
input({
|
||||
savedStep: "candidate_consents",
|
||||
profileVersion: 1,
|
||||
questionnaire: questionnaire([["backend", "junior"]]),
|
||||
availability: { specializations: [availabilityRow("backend")] },
|
||||
results: { items: [resultRow("backend", { grade: "junior" })] },
|
||||
}),
|
||||
);
|
||||
|
||||
expect(journey.nextStep).toEqual({ kind: "result" });
|
||||
expect(journey.confirmed.map((standing) => standing.specialization)).toEqual(["backend"]);
|
||||
expect(journey.standings[0]).toMatchObject({
|
||||
declaredGrade: "junior",
|
||||
confirmedGrade: "junior",
|
||||
});
|
||||
expect(journey.hasResults).toBe(true);
|
||||
});
|
||||
|
||||
it("keeps the grade of the availability read when both sources name one", () => {
|
||||
const journey = buildCandidateJourney(
|
||||
input({
|
||||
profileVersion: 1,
|
||||
questionnaire: questionnaire([["backend", "middle"]]),
|
||||
availability: { specializations: [availabilityRow("backend", { confirmed: "middle" })] },
|
||||
results: { items: [resultRow("backend", { grade: "junior" })] },
|
||||
}),
|
||||
);
|
||||
|
||||
expect(journey.standings[0]?.confirmedGrade).toBe("middle");
|
||||
});
|
||||
|
||||
it("takes the grade in force from the newest decision, whatever the order of the page", () => {
|
||||
const journey = buildCandidateJourney(
|
||||
input({
|
||||
profileVersion: 1,
|
||||
questionnaire: questionnaire([["backend", "senior"]]),
|
||||
results: {
|
||||
items: [
|
||||
resultRow("backend", { grade: "junior", decidedAt: "2026-10-01T10:00:00Z" }),
|
||||
resultRow("backend", { grade: "senior", decidedAt: "2026-10-08T10:00:00Z" }),
|
||||
],
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
expect(journey.standings[0]?.confirmedGrade).toBe("senior");
|
||||
});
|
||||
|
||||
it("does not revive an older grade behind a newer decision that confirms none", () => {
|
||||
const journey = buildCandidateJourney(
|
||||
input({
|
||||
profileVersion: 1,
|
||||
questionnaire: questionnaire([["backend", "junior"]]),
|
||||
results: {
|
||||
items: [
|
||||
resultRow("backend", { grade: "junior", decidedAt: "2026-10-01T10:00:00Z" }),
|
||||
resultRow("backend", { grade: null, decidedAt: "2026-10-08T10:00:00Z" }),
|
||||
],
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
expect(journey.confirmed).toEqual([]);
|
||||
expect(journey.nextStep).toEqual({ kind: "assessment" });
|
||||
});
|
||||
|
||||
it("ignores legacy results that carry no category decision", () => {
|
||||
const journey = buildCandidateJourney(
|
||||
input({
|
||||
profileVersion: 1,
|
||||
questionnaire: questionnaire([["backend", "junior"]]),
|
||||
availability: { specializations: [availabilityRow("backend")] },
|
||||
results: { items: [resultRow("backend", { grade: "junior", legacy: true })] },
|
||||
}),
|
||||
);
|
||||
|
||||
expect(journey.confirmed).toEqual([]);
|
||||
expect(journey.hasResults).toBe(true);
|
||||
expect(journey.nextStep).toEqual({ kind: "assessment" });
|
||||
});
|
||||
|
||||
it("keeps a confirmed category visible when the questionnaire no longer lists it", () => {
|
||||
const journey = buildCandidateJourney(
|
||||
input({
|
||||
profileVersion: 1,
|
||||
questionnaire: questionnaire([]),
|
||||
results: { items: [resultRow("qa", { grade: "junior" })] },
|
||||
}),
|
||||
);
|
||||
|
||||
expect(journey.standings).toEqual([
|
||||
{
|
||||
specialization: "qa",
|
||||
declaredGrade: null,
|
||||
confirmedGrade: "junior",
|
||||
activeAttemptId: null,
|
||||
canStartAttempt: false,
|
||||
},
|
||||
]);
|
||||
expect(journey.nextStep).toEqual({ kind: "result" });
|
||||
});
|
||||
});
|
||||
|
||||
describe("summarizeVisibility", () => {
|
||||
function settings(overrides: {
|
||||
publication?: Partial<PrivacySettings["publication"]>;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type {
|
||||
Account,
|
||||
AssessmentAvailability,
|
||||
AssessmentResultHistoryPage,
|
||||
CandidateQuestionnaire,
|
||||
GradeCode,
|
||||
PrivacySettings,
|
||||
@@ -50,28 +51,64 @@ export type CandidateJourneyInput = {
|
||||
profileVersion: number;
|
||||
questionnaire: Pick<CandidateQuestionnaire, "version" | "specializations">;
|
||||
availability: Pick<AssessmentAvailability, "specializations">;
|
||||
/** The first page of the candidate's real results, newest first. */
|
||||
results: Pick<AssessmentResultHistoryPage, "items">;
|
||||
};
|
||||
|
||||
export type CandidateJourney = {
|
||||
savedStep: OnboardingStep;
|
||||
profileSaved: boolean;
|
||||
questionnaireSaved: boolean;
|
||||
/** True when the candidate has at least one real assessment result. */
|
||||
hasResults: boolean;
|
||||
standings: readonly SpecializationStanding[];
|
||||
/** Standings whose grade an assessment confirmed. */
|
||||
confirmed: readonly SpecializationStanding[];
|
||||
nextStep: CandidateNextStep;
|
||||
};
|
||||
|
||||
function buildStandings(input: CandidateJourneyInput): SpecializationStanding[] {
|
||||
type ResultItem = AssessmentResultHistoryPage["items"][number];
|
||||
|
||||
/**
|
||||
* Grade in force for each specialization, read from the newest result of that
|
||||
* specialization. A v2 result records the grade in force when its attempt
|
||||
* ended, so the newest decision is the current category. A legacy result has
|
||||
* no decision and yields no grade; a result that confirms no grade leaves the
|
||||
* specialization unconfirmed. Older results never override a newer decision.
|
||||
*/
|
||||
export function currentGradesFromResults(
|
||||
results: readonly ResultItem[],
|
||||
): Map<SpecializationCode, GradeCode> {
|
||||
// The server lists results newest first; sorting here keeps the rule local.
|
||||
const newestFirst = [...results].sort((left, right) =>
|
||||
right.decided_at.localeCompare(left.decided_at),
|
||||
);
|
||||
const grades = new Map<SpecializationCode, GradeCode>();
|
||||
const decided = new Set<SpecializationCode>();
|
||||
for (const result of newestFirst) {
|
||||
if (decided.has(result.specialization)) continue;
|
||||
decided.add(result.specialization);
|
||||
const grade = result.category_decision?.current_confirmed_grade ?? null;
|
||||
if (grade !== null) grades.set(result.specialization, grade);
|
||||
}
|
||||
return grades;
|
||||
}
|
||||
|
||||
function buildStandings(
|
||||
input: CandidateJourneyInput,
|
||||
resultGrades: ReadonlyMap<SpecializationCode, GradeCode>,
|
||||
): SpecializationStanding[] {
|
||||
const standings = new Map<SpecializationCode, SpecializationStanding>();
|
||||
|
||||
// The availability list is the server's view of the questionnaire
|
||||
// specializations; the questionnaire adds the declared grade.
|
||||
// specializations; the questionnaire adds the declared grade. The current
|
||||
// confirmed grade comes from the availability read when it has one, and from
|
||||
// the newest result of the specialization otherwise.
|
||||
for (const item of input.availability.specializations) {
|
||||
standings.set(item.specialization, {
|
||||
specialization: item.specialization,
|
||||
declaredGrade: null,
|
||||
confirmedGrade: item.confirmed_grade,
|
||||
confirmedGrade: item.confirmed_grade ?? resultGrades.get(item.specialization) ?? null,
|
||||
activeAttemptId: item.active_attempt_id,
|
||||
canStartAttempt: item.grades.some((grade) => grade.status === "available"),
|
||||
});
|
||||
@@ -81,11 +118,23 @@ function buildStandings(input: CandidateJourneyInput): SpecializationStanding[]
|
||||
standings.set(item.specialization, {
|
||||
specialization: item.specialization,
|
||||
declaredGrade: item.self_assessed_grade,
|
||||
confirmedGrade: existing?.confirmedGrade ?? null,
|
||||
confirmedGrade: existing?.confirmedGrade ?? resultGrades.get(item.specialization) ?? null,
|
||||
activeAttemptId: existing?.activeAttemptId ?? null,
|
||||
canStartAttempt: existing?.canStartAttempt ?? false,
|
||||
});
|
||||
}
|
||||
// A result can name a specialization that the current questionnaire no
|
||||
// longer lists. Its confirmed grade is still a fact, so it stays visible.
|
||||
for (const [specialization, grade] of resultGrades) {
|
||||
if (standings.has(specialization)) continue;
|
||||
standings.set(specialization, {
|
||||
specialization,
|
||||
declaredGrade: null,
|
||||
confirmedGrade: grade,
|
||||
activeAttemptId: null,
|
||||
canStartAttempt: false,
|
||||
});
|
||||
}
|
||||
return [...standings.values()];
|
||||
}
|
||||
|
||||
@@ -95,22 +144,26 @@ function buildStandings(input: CandidateJourneyInput): SpecializationStanding[]
|
||||
* only input because the server advances it only when the profile or the
|
||||
* questionnaire is saved from the matching step, so a saved profile can sit
|
||||
* behind an earlier stored step. Presence of saved data therefore decides
|
||||
* between the profile, the questionnaire, and the test.
|
||||
* between the profile, the questionnaire, and the test. Facts about the
|
||||
* category and the test come only from the availability and results reads.
|
||||
*
|
||||
* The client invents no category, grade, or threshold: a category exists only
|
||||
* when the availability read returns a confirmed grade.
|
||||
* when the availability read or the newest result returns a confirmed grade.
|
||||
*/
|
||||
export function buildCandidateJourney(input: CandidateJourneyInput): CandidateJourney {
|
||||
const standings = buildStandings(input);
|
||||
const resultGrades = currentGradesFromResults(input.results.items);
|
||||
const standings = buildStandings(input, resultGrades);
|
||||
const confirmed = standings.filter((standing) => standing.confirmedGrade !== null);
|
||||
const profileSaved = input.profileVersion > 0;
|
||||
const questionnaireSaved =
|
||||
input.questionnaire.version > 0 && input.questionnaire.specializations.length > 0;
|
||||
const hasResults = input.results.items.length > 0;
|
||||
|
||||
return {
|
||||
savedStep: input.savedStep,
|
||||
profileSaved,
|
||||
questionnaireSaved,
|
||||
hasResults,
|
||||
standings,
|
||||
confirmed,
|
||||
nextStep: chooseNextStep({ profileSaved, questionnaireSaved, standings, confirmed }),
|
||||
|
||||
Reference in new issue
Block a user