88 lines
2.5 KiB
TypeScript
88 lines
2.5 KiB
TypeScript
import {
|
|
getFeaturedProjects,
|
|
type PortfolioProjectView,
|
|
} from "@/lib/portfolio-data";
|
|
import { selectNotebookProjects } from "./notebookProjects";
|
|
|
|
const projectsFixture = getFeaturedProjects(null);
|
|
|
|
describe("selectNotebookProjects", () => {
|
|
it("returns the four ordered projects with local screenshots", () => {
|
|
const result = selectNotebookProjects(projectsFixture);
|
|
|
|
expect(result.map((project) => project.id)).toEqual([
|
|
"nutriscan",
|
|
"sc-plus",
|
|
"sev-modaintima",
|
|
"as-servicos",
|
|
]);
|
|
expect(
|
|
result.every((project) =>
|
|
project.screenshotSrc.startsWith("/assets/prints/"),
|
|
),
|
|
).toBe(true);
|
|
});
|
|
|
|
it("omits a project when its screenshot mapping is missing", () => {
|
|
const result = selectNotebookProjects([
|
|
...projectsFixture,
|
|
{ ...projectsFixture[0], id: "unknown-live-project" },
|
|
]);
|
|
|
|
expect(
|
|
result.some((project) => project.id === "unknown-live-project"),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("omits a project with an unapproved demo URL", () => {
|
|
const projectsWithUnsafeUrl = projectsFixture.map((project) =>
|
|
project.id === "nutriscan"
|
|
? { ...project, demoUrl: "javascript:alert(1)" }
|
|
: project,
|
|
);
|
|
const result = selectNotebookProjects(projectsWithUnsafeUrl);
|
|
|
|
expect(result.some((project) => project.id === "nutriscan")).toBe(false);
|
|
});
|
|
|
|
it("keeps a project without a demo so its local evidence remains visible", () => {
|
|
const projectsWithoutDemo = projectsFixture.map((project) =>
|
|
project.id === "nutriscan"
|
|
? {
|
|
...project,
|
|
demoUrl: null,
|
|
demoAvailability: "none" as const,
|
|
demoCheckedAt: null,
|
|
}
|
|
: project,
|
|
) as unknown as PortfolioProjectView[];
|
|
|
|
expect(
|
|
selectNotebookProjects(projectsWithoutDemo).some(
|
|
(project) => project.id === "nutriscan",
|
|
),
|
|
).toBe(true);
|
|
});
|
|
|
|
it("keeps an unavailable project when its local evidence and URL exist", () => {
|
|
const projectsWithUnavailableDemo = projectsFixture.map((project) =>
|
|
project.id === "nutriscan"
|
|
? {
|
|
...project,
|
|
demoAvailability: "unavailable" as const,
|
|
demoCheckedAt: "2026-09-04T12:00:00.000Z",
|
|
}
|
|
: project,
|
|
);
|
|
|
|
expect(
|
|
selectNotebookProjects(projectsWithUnavailableDemo).find(
|
|
(project) => project.id === "nutriscan",
|
|
),
|
|
).toMatchObject({
|
|
demoAvailability: "unavailable",
|
|
demoCheckedAt: "2026-09-04T12:00:00.000Z",
|
|
});
|
|
});
|
|
});
|