feat(jobs): expose discovery provenance
CI and Deploy / test (pull_request) Successful in 4m15s
CI and Deploy / deploy (pull_request) Has been skipped

This commit is contained in:
cesnimda
2026-08-10 10:38:01 +02:00
parent 986f58522b
commit 511a9f6795
5 changed files with 58 additions and 9 deletions
+5 -2
View File
@@ -8,14 +8,17 @@ import JobDiscoveryPage from "./views/JobDiscoveryPage";
jest.mock("./api", () => ({ api: { get: jest.fn() } }));
const mockedApi = api as jest.Mocked<typeof api>;
test("searches NAV and offers the existing reviewed save flow", async () => {
mockedApi.get.mockResolvedValue({ data: [{ id: "abc", title: "Backend Developer", company: "Acme", location: "OSLO", url: "https://arbeidsplassen.nav.no/stillinger/stilling/abc", source: "nav", countryCode: "NO" }] } as any);
test("shows honest source metadata and offers the existing reviewed save flow", async () => {
mockedApi.get.mockResolvedValue({ data: [{ id: "abc", title: "Backend Developer", company: "Acme", location: "OSLO", modifiedAt: "2026-08-01T10:00:00Z", deadline: "2026-08-15T23:59:59Z", url: "https://arbeidsplassen.nav.no/stillinger/stilling/abc", source: "nav", sourceName: "NAV Arbeidsplassen", acquisitionType: "searched", retrievedAt: "2026-08-10T10:00:00Z", countryCode: "NO" }] } as any);
render(<MemoryRouter future={{ v7_startTransition: true, v7_relativeSplatPath: true }}><JobDiscoveryPage /></MemoryRouter>);
fireEvent.change(screen.getByLabelText("Role or company"), { target: { value: "backend" } });
fireEvent.click(screen.getByRole("button", { name: "Search NAV" }));
expect(await screen.findByText("Backend Developer")).toBeInTheDocument();
expect(screen.getByText("NAV Arbeidsplassen")).toBeInTheDocument();
expect(screen.getByText(/Searched listing · Retrieved/)).toBeInTheDocument();
expect(screen.getByText(/Application deadline:/)).toBeInTheDocument();
await waitFor(() => expect(mockedApi.get).toHaveBeenCalledWith("/job-discovery/search", { params: { q: "backend", location: undefined } }));
expect(screen.getByRole("button", { name: "Save to tracker" })).toBeInTheDocument();
});
+3 -2
View File
@@ -72,7 +72,7 @@ test('does not auto-import when no initialUrl is given', async () => {
test('can generate a tailored CV after creating a job', async () => {
mockedApi.post.mockImplementation((url: string) => {
if (url === '/jobimport/preview') return Promise.resolve({ data: { success: true, title: 'Imported Backend Role', company: 'Acme', description: 'desc' } } as any);
if (url === '/jobimport/preview') return Promise.resolve({ data: { success: true, title: 'Imported Backend Role', company: 'Acme', description: 'desc', source: 'nav', countryCode: 'NO' } } as any);
if (url === '/companies') return Promise.resolve({ data: { id: 1, name: 'Acme' } } as any);
if (url === '/jobapplications') return Promise.resolve({ data: { id: 42 } } as any);
return Promise.resolve({ data: {} } as any);
@@ -85,5 +85,6 @@ test('can generate a tailored CV after creating a job', async () => {
for (let step = 0; step < 3; step += 1) fireEvent.click(screen.getByRole('button', { name: 'Skip and continue' }));
fireEvent.click(screen.getByRole('button', { name: /create job/i }));
await waitFor(() => expect(mockedApi.post).toHaveBeenCalledWith('/jobapplications/42/generate-tailored-cv-draft'));
await waitFor(() => expect(mockedApi.post).toHaveBeenCalledWith('/jobapplications', expect.objectContaining({ source: 'nav', countryCode: 'NO' })));
expect(mockedApi.post).toHaveBeenCalledWith('/jobapplications/42/generate-tailored-cv-draft');
});
+26 -3
View File
@@ -1,11 +1,26 @@
import { FormEvent, useState } from "react";
import { Alert, Box, Button, Card, CardActions, CardContent, CircularProgress, Stack, TextField, Typography } from "@mui/material";
import { Alert, Box, Button, Card, CardActions, CardContent, Chip, CircularProgress, Stack, TextField, Typography } from "@mui/material";
import SearchIcon from "@mui/icons-material/Search";
import AddIcon from "@mui/icons-material/Add";
import { useNavigate } from "react-router-dom";
import { api } from "../api";
type DiscoveredJob = { id: string; title: string; company?: string; location?: string; modifiedAt?: string; url: string; source: string; countryCode: string; };
type DiscoveredJob = {
id: string;
title: string;
company?: string;
location?: string;
modifiedAt?: string;
deadline?: string;
url: string;
source: string;
sourceName?: string;
acquisitionType?: string;
retrievedAt?: string;
countryCode: string;
};
const formatDate = (value?: string) => value ? new Date(value).toLocaleDateString() : null;
export default function JobDiscoveryPage() {
const navigate = useNavigate();
@@ -38,9 +53,17 @@ export default function JobDiscoveryPage() {
{jobs.map((job) => (
<Card key={job.id} variant="outlined">
<CardContent>
<Chip label={job.sourceName || job.source.toUpperCase()} size="small" color="primary" variant="outlined" sx={{ mb: 1 }} />
<Typography variant="h6" sx={{ fontWeight: 800 }}>{job.title}</Typography>
<Typography color="text.secondary">{[job.company, job.location].filter(Boolean).join(" · ")}</Typography>
<Typography variant="caption" color="text.secondary">NAV · Norway{job.modifiedAt ? " · Updated " + new Date(job.modifiedAt).toLocaleDateString() : ""}</Typography>
<Stack spacing={0.25} sx={{ mt: 1 }}>
<Typography variant="caption" color="text.secondary">
{job.acquisitionType === "searched" ? "Searched listing" : "Source type unavailable"}
{formatDate(job.retrievedAt) ? ` · Retrieved ${formatDate(job.retrievedAt)}` : ""}
</Typography>
{formatDate(job.modifiedAt) ? <Typography variant="caption" color="text.secondary">Listing updated {formatDate(job.modifiedAt)}</Typography> : null}
{formatDate(job.deadline) ? <Typography variant="body2" color="text.primary">Application deadline: {formatDate(job.deadline)}</Typography> : null}
</Stack>
</CardContent>
<CardActions>
<Button href={job.url} target="_blank" rel="noreferrer">View listing</Button>