a7cecce13d
Phase 5.3. Three read-only reads that answer "how suitable is this job", "how
does my experience match", "what am I missing", "what happened previously".
Timeline (GET /{id}/timeline) is an interpretation layer over JobEvent, which
stays the source of historical truth. Each row gains a readable summary, a
category and a milestone flag; events group by day. Milestones are returned
unfiltered, because narrowing the detail must not hide what actually happened.
Job analysis (GET /{id}/analysis) extracts role, company, location, employment
type, seniority, salary, technologies, skills, responsibilities and keywords
from the advert, reusing the existing SkillTagger so the vocabulary matches the
job importer. It also reports what the advert does NOT say, which is usually the
more useful half.
Career matching (GET /{id}/match) feeds the master CareerProfile into the same
JobCvMatchService the CV builder uses, so one application scores identically
whichever surface asks. It returns the score, matched and missing skills, and
which experience and project entries are the evidence for each match.
All three are deterministic and own no data — no new table, no new column, and
nothing writes to the CareerProfile, a CvVariant, or the JobApplication. The AI
narrative stays where it already was, in AiWorkspaceService's job-analysis and
career-match modules, generated only when the user asks and versioned by the
append-only AiInteraction history. Opening a section costs nothing and changes
nothing.
Frontend adds Timeline, Analysis and Match sections to the workspace, sharing
one loader so loading, empty and error states are consistent. The deterministic
answer renders first, with the AI panel below it.
345 backend tests, 104 frontend tests, type check, production build all pass
locally.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
181 lines
6.2 KiB
TypeScript
181 lines
6.2 KiB
TypeScript
import React from "react";
|
||
import "@testing-library/jest-dom";
|
||
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||
|
||
import {
|
||
ApplicationAnalysis, ApplicationMatch, ApplicationTimeline,
|
||
} from "./components/ApplicationIntelligence";
|
||
import { api } from "./api";
|
||
|
||
jest.mock("./api", () => ({
|
||
api: {
|
||
get: jest.fn(),
|
||
interceptors: { request: { use: jest.fn() }, response: { use: jest.fn() } },
|
||
},
|
||
getApiErrorMessage: (_e: any, fallback?: string) => fallback || "Request failed.",
|
||
}));
|
||
|
||
const mockedApi = api as jest.Mocked<typeof api>;
|
||
|
||
const timeline = {
|
||
days: [
|
||
{
|
||
date: "2026-07-19",
|
||
label: "Today",
|
||
events: [
|
||
{ id: 2, type: "StatusChanged", category: "stage", summary: "Moved from Applied to Interview", detail: null, isMilestone: true, at: "2026-07-19T09:00:00Z" },
|
||
{ id: 3, type: "AiRefreshed", category: "ai", summary: "AI suggestions refreshed", detail: null, isMilestone: false, at: "2026-07-19T08:00:00Z" },
|
||
],
|
||
},
|
||
],
|
||
milestones: [
|
||
{ id: 2, type: "StatusChanged", category: "stage", summary: "Moved from Applied to Interview", detail: null, isMilestone: true, at: "2026-07-19T09:00:00Z" },
|
||
],
|
||
categories: ["ai", "stage"],
|
||
totalEvents: 2,
|
||
};
|
||
|
||
const analysis = {
|
||
role: "Senior Backend Developer",
|
||
company: "Acme",
|
||
location: "Oslo",
|
||
employmentType: "Full-time",
|
||
seniority: "Senior",
|
||
salary: null,
|
||
technologies: ["C#", ".NET"],
|
||
skills: ["Collaboration"],
|
||
responsibilities: ["Build and operate REST APIs"],
|
||
keywords: ["C#", ".NET", "Collaboration"],
|
||
summary: "Senior Backend Developer at Acme · Oslo.",
|
||
importantRequirements: ["Strong experience with C# and .NET"],
|
||
interviewTopics: ["C#", ".NET"],
|
||
missingInformation: ["Salary or compensation range"],
|
||
hasJobDescription: true,
|
||
aiSuggestionCount: 0,
|
||
};
|
||
|
||
const match = {
|
||
score: 72,
|
||
band: "Good",
|
||
hasEnoughSignal: true,
|
||
hasCareerProfile: true,
|
||
matchedSkills: ["C#", "SQL"],
|
||
missingSkills: ["Kubernetes"],
|
||
relevantExperience: [{ title: "Backend Developer", subtitle: "Initech · 2021 – present", matched: ["C#"] }],
|
||
relevantProjects: [],
|
||
suggestions: ["Solid match. Lead with the matched skills."],
|
||
aiSuggestionCount: 0,
|
||
};
|
||
|
||
beforeEach(() => jest.clearAllMocks());
|
||
|
||
// ---------- Timeline ----------
|
||
|
||
test("timeline renders grouped days, milestones and readable summaries", async () => {
|
||
mockedApi.get.mockResolvedValue({ data: timeline } as any);
|
||
|
||
render(<ApplicationTimeline jobId={7} />);
|
||
|
||
expect(await screen.findByText("Milestones")).toBeInTheDocument();
|
||
expect(screen.getByText("Today")).toBeInTheDocument();
|
||
expect(screen.getAllByText("Moved from Applied to Interview").length).toBeGreaterThan(0);
|
||
expect(screen.getByText("AI suggestions refreshed")).toBeInTheDocument();
|
||
});
|
||
|
||
test("timeline filters by category", async () => {
|
||
mockedApi.get.mockResolvedValue({ data: timeline } as any);
|
||
|
||
render(<ApplicationTimeline jobId={7} />);
|
||
fireEvent.click(await screen.findByRole("button", { name: "AI" }));
|
||
|
||
await waitFor(() =>
|
||
expect(mockedApi.get).toHaveBeenLastCalledWith(
|
||
"/jobapplications/7/timeline",
|
||
{ params: { category: "ai", milestonesOnly: undefined } },
|
||
));
|
||
});
|
||
|
||
test("timeline shows an empty state when nothing has happened", async () => {
|
||
mockedApi.get.mockResolvedValue({ data: { days: [], milestones: [], categories: [], totalEvents: 0 } } as any);
|
||
|
||
render(<ApplicationTimeline jobId={7} />);
|
||
|
||
expect(await screen.findByText(/Nothing has happened yet/i)).toBeInTheDocument();
|
||
});
|
||
|
||
test("timeline surfaces an error instead of rendering nothing", async () => {
|
||
mockedApi.get.mockRejectedValue(new Error("boom"));
|
||
|
||
render(<ApplicationTimeline jobId={7} />);
|
||
|
||
expect(await screen.findByText(/Could not load this section/i)).toBeInTheDocument();
|
||
});
|
||
|
||
// ---------- Analysis ----------
|
||
|
||
test("analysis renders the extracted structure", async () => {
|
||
mockedApi.get.mockResolvedValue({ data: analysis } as any);
|
||
|
||
render(<ApplicationAnalysis jobId={7} />);
|
||
|
||
expect(await screen.findByText("Senior Backend Developer at Acme · Oslo.")).toBeInTheDocument();
|
||
expect(screen.getByText("Full-time")).toBeInTheDocument();
|
||
expect(screen.getByText("Strong experience with C# and .NET")).toBeInTheDocument();
|
||
expect(screen.getByText("Salary or compensation range")).toBeInTheDocument();
|
||
});
|
||
|
||
test("analysis prompts for the advert when there is none", async () => {
|
||
mockedApi.get.mockResolvedValue({
|
||
data: { ...analysis, hasJobDescription: false, technologies: [], responsibilities: [], importantRequirements: [] },
|
||
} as any);
|
||
|
||
render(<ApplicationAnalysis jobId={7} />);
|
||
|
||
expect(await screen.findByText(/No advert text saved yet/i)).toBeInTheDocument();
|
||
});
|
||
|
||
test("analysis shows a loading state before the data arrives", () => {
|
||
mockedApi.get.mockReturnValue(new Promise(() => {}) as any);
|
||
|
||
const { container } = render(<ApplicationAnalysis jobId={7} />);
|
||
|
||
expect(container.querySelectorAll(".MuiSkeleton-root").length).toBeGreaterThan(0);
|
||
});
|
||
|
||
// ---------- Match ----------
|
||
|
||
test("match renders the score, evidence and suggestions", async () => {
|
||
mockedApi.get.mockResolvedValue({ data: match } as any);
|
||
|
||
render(<ApplicationMatch jobId={7} />);
|
||
|
||
expect(await screen.findByText("72%")).toBeInTheDocument();
|
||
expect(screen.getByText("Good")).toBeInTheDocument();
|
||
expect(screen.getByText("Backend Developer")).toBeInTheDocument();
|
||
expect(screen.getByText("Kubernetes")).toBeInTheDocument();
|
||
expect(screen.getByText(/Solid match/i)).toBeInTheDocument();
|
||
});
|
||
|
||
test("match asks for a career profile before showing a score", async () => {
|
||
mockedApi.get.mockResolvedValue({
|
||
data: {
|
||
...match, score: 0, band: "No profile", hasCareerProfile: false,
|
||
matchedSkills: [], missingSkills: [], relevantExperience: [],
|
||
suggestions: ["Build your career profile first."],
|
||
},
|
||
} as any);
|
||
|
||
render(<ApplicationMatch jobId={7} />);
|
||
|
||
expect(await screen.findByText(/No career profile yet/i)).toBeInTheDocument();
|
||
expect(screen.queryByText("0%")).not.toBeInTheDocument();
|
||
});
|
||
|
||
test("match warns when the advert is too short to score", async () => {
|
||
mockedApi.get.mockResolvedValue({ data: { ...match, hasEnoughSignal: false } } as any);
|
||
|
||
render(<ApplicationMatch jobId={7} />);
|
||
|
||
expect(await screen.findByText(/too short to score reliably/i)).toBeInTheDocument();
|
||
});
|