Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/serhalp/npm.report. Audit, visualize, share, and track your npm org's trust signals. npm.report
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121import { render, screen } from "@testing-library/svelte";import userEvent from "@testing-library/user-event";import { describe, expect, test, vi } from "vitest";import SharedReport from "./SharedReport.svelte";import { auditResult, trustReport } from "./test/fixtures";
describe("SharedReport", () => { test("loads and renders a read-only shared report", async () => { vi.stubGlobal( "fetch", vi.fn().mockResolvedValue({ ok: true, status: 200, json: async () => ({ id: "report-id", orgs: "netlify", scopeLabel: "last 12 months", payload: auditResult, createdAt: "2026-06-27T12:34:56.000Z", }), }), );
render(SharedReport, { props: { id: "report/id" } });
expect(screen.getByText("Loading report…")).toBeInTheDocument(); expect(await screen.findByText(/Audit of/)).toBeInTheDocument(); expect(screen.getByText("netlify")).toBeInTheDocument(); expect(screen.getByText(/generated 2026-06-27/)).toBeInTheDocument(); expect(fetch).toHaveBeenCalledWith("/api/reports/report%2Fid"); });
test("shows trust history for all-scope shared reports", async () => { const user = userEvent.setup(); vi.stubGlobal( "fetch", vi.fn(async (input: RequestInfo | URL) => { if (String(input) === "/api/reports/report-id") { return { ok: true, status: 200, json: async () => ({ id: "report-id", orgs: "netlify", scopeLabel: "ALL org packages", payload: { ...auditResult, trust: { ...trustReport, summary: { ...trustReport.summary, scopeLabel: "ALL org packages", }, }, }, createdAt: "2026-06-27T12:34:56.000Z", }), }; } if (String(input) === "/api/reports/report-id/schedule-daily") { return { ok: true, status: 201, json: async () => ({ orgs: ["netlify"], enabled: true, nextRunAt: "2026-06-28T12:34:56.000Z", lastRunAt: null, lastReportId: "report-id", consecutiveFailures: 0, }), }; } return { ok: true, status: 200, json: async () => ({ orgs: ["netlify"], points: [ { id: "report-id", url: "/report/report-id", capturedAt: "2026-06-27T12:34:56.000Z", total: 2, byLevel: trustReport.summary.byLevel, deprecated: 1, failureCount: 1, }, ], }), }; }), );
render(SharedReport, { props: { id: "report-id" } });
expect(await screen.findByRole("heading", { name: "Progress over time" })).toBeInTheDocument(); expect(await screen.findByRole("link", { name: "2026-06-27" })).toHaveAttribute( "href", "/report/report-id", ); await user.click(screen.getByRole("button", { name: "Track daily" })); expect(await screen.findByRole("button", { name: "Tracking daily" })).toBeDisabled(); });
test("shows the specific not-found error for 404s", async () => { vi.stubGlobal( "fetch", vi.fn().mockResolvedValue({ ok: false, status: 404, }), );
render(SharedReport, { props: { id: "missing" } });
expect(await screen.findByText("This report could not be found.")).toBeInTheDocument(); expect(screen.getByText(/Back to the audit tool/)).toBeInTheDocument(); });});