|
| 1 | +import assert from "node:assert/strict"; |
| 2 | +import test from "node:test"; |
| 3 | +import { readFileSync } from "node:fs"; |
| 4 | +import { resolve } from "node:path"; |
| 5 | + |
| 6 | +const src = readFileSync( |
| 7 | + resolve(import.meta.dirname, "ProjectSettings.tsx"), |
| 8 | + "utf-8", |
| 9 | +); |
| 10 | + |
| 11 | +// --------------------------------------------------------------------------- |
| 12 | +// AC1: Clicking Save shows a visible success toast confirming the save |
| 13 | +// --------------------------------------------------------------------------- |
| 14 | + |
| 15 | +void test("handleSaveGeneral calls toast.success on successful save", () => { |
| 16 | + assert.ok( |
| 17 | + src.includes("toast.success"), |
| 18 | + "Save handler must call toast.success() to show a success notification", |
| 19 | + ); |
| 20 | +}); |
| 21 | + |
| 22 | +void test("Success toast message indicates settings were saved", () => { |
| 23 | + assert.ok( |
| 24 | + src.includes('toast.success("Settings saved'), |
| 25 | + "Success toast must display 'Settings saved' message", |
| 26 | + ); |
| 27 | +}); |
| 28 | + |
| 29 | +// --------------------------------------------------------------------------- |
| 30 | +// AC2: The toast auto-dismisses (Sonner default is ~4s, acceptable) |
| 31 | +// --------------------------------------------------------------------------- |
| 32 | + |
| 33 | +void test("Uses sonner toast which auto-dismisses by default", () => { |
| 34 | + assert.ok( |
| 35 | + src.includes('from "sonner"'), |
| 36 | + "Must import toast from sonner which provides auto-dismiss behavior", |
| 37 | + ); |
| 38 | +}); |
| 39 | + |
| 40 | +// --------------------------------------------------------------------------- |
| 41 | +// AC3: If the save fails, an error toast appears instead |
| 42 | +// --------------------------------------------------------------------------- |
| 43 | + |
| 44 | +void test("handleSaveGeneral calls toast.error on failed save", () => { |
| 45 | + assert.ok( |
| 46 | + src.includes("toast.error") && src.includes("Failed to save"), |
| 47 | + "Save handler must call toast.error() with a failure message on error", |
| 48 | + ); |
| 49 | +}); |
| 50 | + |
| 51 | +// --------------------------------------------------------------------------- |
| 52 | +// AC4: No inline saveMessage display — replaced by toast |
| 53 | +// --------------------------------------------------------------------------- |
| 54 | + |
| 55 | +void test("No inline saveMessage state for General save feedback", () => { |
| 56 | + assert.ok( |
| 57 | + !src.includes("setSaveMessage"), |
| 58 | + "Inline saveMessage state must be removed — feedback is via toast now", |
| 59 | + ); |
| 60 | +}); |
| 61 | + |
| 62 | +void test("No inline save message div rendering", () => { |
| 63 | + assert.ok( |
| 64 | + !src.includes("saveMessage.type"), |
| 65 | + "Inline saveMessage rendering must be removed — feedback is via toast now", |
| 66 | + ); |
| 67 | +}); |
| 68 | + |
| 69 | +// --------------------------------------------------------------------------- |
| 70 | +// AC5: Toast styling matches app's design language (uses existing Sonner config) |
| 71 | +// --------------------------------------------------------------------------- |
| 72 | + |
| 73 | +void test("Uses the existing Sonner toast infrastructure (not a custom component)", () => { |
| 74 | + const toastImport = src.includes('import { toast } from "sonner"'); |
| 75 | + assert.ok( |
| 76 | + toastImport, |
| 77 | + "Must use the existing sonner toast import for consistent styling", |
| 78 | + ); |
| 79 | +}); |
| 80 | + |
| 81 | +// --------------------------------------------------------------------------- |
| 82 | +// AC6: No console errors — clean imports |
| 83 | +// --------------------------------------------------------------------------- |
| 84 | + |
| 85 | +void test("CheckIcon import is removed if no longer used inline", () => { |
| 86 | + // CheckIcon was only used in the inline saveMessage success indicator. |
| 87 | + // If saveMessage is removed, CheckIcon should also be removed (unless used elsewhere). |
| 88 | + const checkIconUsages = src.match(/CheckIcon/g); |
| 89 | + // If CheckIcon is still imported, it must be used somewhere in JSX |
| 90 | + if (checkIconUsages) { |
| 91 | + const inJsx = src.includes("<CheckIcon"); |
| 92 | + assert.ok( |
| 93 | + inJsx, |
| 94 | + "If CheckIcon is imported, it must be used in JSX — otherwise remove the unused import", |
| 95 | + ); |
| 96 | + } |
| 97 | +}); |
0 commit comments