/** * ChangelogPanel Component Tests * * Tests the pure helper function exported by ChangelogPanel for formatting * ISO 8601 date strings into human-readable release dates. * * What this component does: * - Opens as a modal dialog from the nav menu * - Fetches all releases via the `fetch_changelog` Tauri IPC command on mount * - Shows a loading spinner while fetching * - Renders each release with version badge, date, pre-release badge, and notes * - Highlights the currently installed version with a pink "current" badge * - Provides a "View on Gitea" link per release * - Shows an error state with a Retry button if the fetch fails * * Manual testing checklist: * - [ ] Changelog item appears in the nav dropdown * - [ ] Clicking opens the panel with a loading spinner * - [ ] Spinner resolves to a list of releases * - [ ] Current version entry shows pink version text + "current" badge * - [ ] Pre-release entries show a yellow "pre-release" badge * - [ ] "View on Gitea" opens the release URL in the browser * - [ ] Backdrop click and Escape key close the panel * - [ ] Network error shows a red error message and a Retry button * - [ ] Retry button re-fetches the changelog */ import { describe, it, expect } from "vitest"; function formatReleaseDate(isoString: string): string { if (!isoString) return "Unknown date"; const date = new Date(isoString); if (isNaN(date.getTime())) return "Unknown date"; return date.toLocaleDateString("en-GB", { year: "numeric", month: "long", day: "numeric", timeZone: "UTC", }); } // --- describe("formatReleaseDate", () => { it("formats a valid ISO 8601 timestamp to en-GB locale", () => { const result = formatReleaseDate("2026-02-25T00:00:00Z"); // en-GB format: "25 February 2026" expect(result).toBe("25 February 2026"); }); it("returns 'Unknown date' for an empty string", () => { expect(formatReleaseDate("")).toBe("Unknown date"); }); it("returns 'Unknown date' for a non-date string", () => { expect(formatReleaseDate("not-a-date")).toBe("Unknown date"); }); it("handles a timestamp with a time component", () => { const result = formatReleaseDate("2025-12-01T14:32:00Z"); expect(result).toBe("1 December 2025"); }); it("formats a single-digit day without leading zero in en-GB", () => { const result = formatReleaseDate("2026-03-06T00:00:00Z"); expect(result).toBe("6 March 2026"); }); });