@octarq/plugin-links 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/pages/index.tsx CHANGED
@@ -1,32 +1,36 @@
1
1
  import {
2
2
  Alert,
3
- Badge,
4
3
  Empty,
5
- ScreenWrap,
6
- PageHeader,
4
+ Field,
5
+ PageShell,
6
+ PageCard,
7
7
  Panel,
8
- GlassCard,
9
8
  Button,
10
9
  Input,
10
+ Skeleton,
11
+ StatCard,
12
+ StatusBadge,
11
13
  Table,
12
14
  THead,
13
15
  TBody,
14
16
  TR,
15
17
  TH,
18
+ TD,
16
19
  TabBar,
17
20
  TableError,
21
+ TableSkeleton,
22
+ Textarea,
18
23
  confirmDialog,
19
24
  toast,
20
25
  useTranslation,
21
26
  roleSatisfies,
22
27
  useCurrentRole,
23
28
  usePluginGate,
24
- ListSkeleton,
25
29
  } from "@octarq/plugin-sdk";
26
- import { useEffect, useMemo, useState } from "react";
27
- import { useSearchParams, NavLink } from "react-router-dom";
30
+ import { useCallback, useEffect, useMemo, useState } from "react";
31
+ import { useSearchParams } from "react-router-dom";
28
32
  import { api, linksApi, Link, Domain, effectiveLinkHosts } from "../api";
29
- import { AlertCircle, Link2, Search, Settings, Plus, Activity, ShieldCheck, AlertTriangle, Blocks } from "lucide-react";
33
+ import { AlertCircle, Download, Link2, Search, Settings, Plus, Activity, ShieldCheck, AlertTriangle } from "lucide-react";
30
34
  import { parseLinksFilter, buildLinksFilterQuery } from "../filters";
31
35
  import { LinkTableRow } from "./LinkTableRow";
32
36
  import { LinkModals } from "./LinkModals";
@@ -88,9 +92,51 @@ export default function LinksPage() {
88
92
  const [loading, setLoading] = useState(false);
89
93
  const [error, setError] = useState<{ detail?: string } | null>(null);
90
94
  const [copiedId, setCopiedId] = useState<number | null>(null);
95
+ const [exporting, setExporting] = useState(false);
91
96
  const { t } = useTranslation();
92
97
  const pluginGate = usePluginGate();
93
98
 
99
+ const [reservedSlugs, setReservedSlugs] = useState("");
100
+ const [savingReserved, setSavingReserved] = useState(false);
101
+
102
+ const loadReserved = useCallback(async () => {
103
+ try {
104
+ const data = await linksApi.getSettings();
105
+ setReservedSlugs(data.reservedSlugs || "");
106
+ } catch {
107
+ }
108
+ }, []);
109
+
110
+ useEffect(() => {
111
+ if (tab === "reserved") {
112
+ void loadReserved();
113
+ }
114
+ }, [tab, loadReserved]);
115
+
116
+ const handleSaveReserved = async () => {
117
+ setSavingReserved(true);
118
+ try {
119
+ const res = await linksApi.updateSettings({ reservedSlugs });
120
+ setReservedSlugs(res.reservedSlugs || "");
121
+ toast.success(t("links.settingsSaved", "Settings saved"));
122
+ } catch (e: any) {
123
+ toast.error(e?.message || t("links.saveFailed", "Could not save settings; retry the request"));
124
+ } finally {
125
+ setSavingReserved(false);
126
+ }
127
+ };
128
+
129
+ const customReservedList = useMemo(() => {
130
+ return reservedSlugs
131
+ .split(/[\n,]/)
132
+ .map((s) => s.trim().toLowerCase())
133
+ .filter((s) => s.length > 0 && !SYSTEM_RESERVED_SLUGS.includes(s));
134
+ }, [reservedSlugs]);
135
+
136
+ const allReservedSlugs = useMemo(() => {
137
+ return [...SYSTEM_RESERVED_SLUGS, ...customReservedList];
138
+ }, [customReservedList]);
139
+
94
140
  useEffect(() => {
95
141
  if (searchParams.get("create") === "1") {
96
142
  setCreateOpen(true);
@@ -127,9 +173,6 @@ export default function LinksPage() {
127
173
  pluginGate.degrade(err.status);
128
174
  return;
129
175
  }
130
- // Everything else used to be swallowed: the first page rendered the
131
- // "no links yet" empty state over a 500, and a failed next page looked
132
- // like the end of the list.
133
176
  setError({ detail: err.status ? `HTTP ${err.status}` : err.message });
134
177
  } finally {
135
178
  setLoading(false);
@@ -166,8 +209,6 @@ export default function LinksPage() {
166
209
  await linksApi.updateLink(l.id, { archived: !l.archived });
167
210
  loadMore(true);
168
211
  } catch {
169
- // A rejected mutation used to bubble out of the click handler as an
170
- // unhandled rejection, leaving the row unchanged with no feedback.
171
212
  toast.error(t("links.actionFailed"));
172
213
  }
173
214
  };
@@ -182,26 +223,41 @@ export default function LinksPage() {
182
223
  }
183
224
  };
184
225
 
185
- // The empty state below carries the same action. Two primary buttons that do
186
- // the same thing on one screen split attention, so the header keeps it only
187
- // when the empty state cannot show it: another tab, a load failure, a search
188
- // with no hits, or a list still loading.
226
+ const handleExportCsv = async () => {
227
+ if (exporting) return;
228
+ setExporting(true);
229
+ try {
230
+ const blob = await linksApi.exportCsv();
231
+ const url = URL.createObjectURL(blob);
232
+ const a = document.createElement("a");
233
+ a.href = url;
234
+ a.download = "links.csv";
235
+ document.body.appendChild(a);
236
+ a.click();
237
+ a.remove();
238
+ URL.revokeObjectURL(url);
239
+ } catch {
240
+ toast.error(t("links.actionFailed"));
241
+ } finally {
242
+ setExporting(false);
243
+ }
244
+ };
245
+
189
246
  const emptyStateOwnsCreate = tab === "links" && !error && !loading && links.length === 0 && !q;
190
247
 
191
248
  return (
192
- <ScreenWrap>
193
- <PageHeader
194
- title={t("links.pageTitle")}
195
- description={t("links.pageDescription")}
196
- action={
197
- emptyStateOwnsCreate ? undefined : (
198
- <Button variant="primary" size="sm" onClick={() => setCreateOpen(true)}>
199
- <Plus className="h-3.5 w-3.5" />
200
- {t("links.newLink")}
201
- </Button>
202
- )
203
- }
204
- />
249
+ <PageShell
250
+ title={t("links.pageTitle")}
251
+ description={t("links.pageDescription")}
252
+ action={
253
+ emptyStateOwnsCreate ? undefined : (
254
+ <Button variant="primary" size="sm" onClick={() => setCreateOpen(true)}>
255
+ <Plus className="h-3.5 w-3.5" />
256
+ {t("links.newLink")}
257
+ </Button>
258
+ )
259
+ }
260
+ >
205
261
 
206
262
  <TabBar
207
263
  className="mb-6"
@@ -216,7 +272,6 @@ export default function LinksPage() {
216
272
 
217
273
  {tab === "links" && (
218
274
  <div className="space-y-4" data-testid="links-projection-view">
219
- {/* Search, Filter Tabs & Batch Toolbar */}
220
275
  <div className="flex flex-wrap items-center justify-between gap-3">
221
276
  <div className="flex max-w-sm flex-1 items-center gap-2">
222
277
  <div className="relative w-full">
@@ -237,6 +292,10 @@ export default function LinksPage() {
237
292
  </div>
238
293
 
239
294
  <div className="flex items-center gap-2">
295
+ <Button variant="outline" size="sm" onClick={handleExportCsv} disabled={exporting}>
296
+ <Download className="h-3.5 w-3.5" />
297
+ {t("links.exportCsv")}
298
+ </Button>
240
299
  <TabBar
241
300
  size="sm"
242
301
  value={archived ? "archived" : "active"}
@@ -251,14 +310,15 @@ export default function LinksPage() {
251
310
  </div>
252
311
  </div>
253
312
 
254
- {/* Links Data Table / Empty Views */}
255
313
  {error && links.length === 0 ? (
256
314
  <TableError errorText={error.detail} onRetry={() => loadMore(true)} />
257
315
  ) : loading && links.length === 0 ? (
258
- <ListSkeleton rows={8} ariaLabel={t("links.loading")} />
316
+ <PageCard className="mt-0 overflow-hidden p-0">
317
+ <TableSkeleton columnsCount={5} rowsCount={8} ariaLabel={t("links.loading")} />
318
+ </PageCard>
259
319
  ) : links.length === 0 ? (
260
320
  q ? (
261
- <GlassCard className="flex flex-col items-center gap-3 px-4 py-12 text-center">
321
+ <PageCard className="mt-0 flex flex-col items-center gap-3 px-4 py-12 text-center">
262
322
  <p className="text-sm text-muted-foreground">
263
323
  {t("links.emptyFilteredReason")} <span className="font-mono text-foreground">{`“${q}”`}</span>
264
324
  </p>
@@ -269,7 +329,7 @@ export default function LinksPage() {
269
329
  >
270
330
  {t("links.emptyFilteredAction")}
271
331
  </Button>
272
- </GlassCard>
332
+ </PageCard>
273
333
  ) : (
274
334
  <Empty
275
335
  reason={t("links.emptyNoLinksReason")}
@@ -295,7 +355,7 @@ export default function LinksPage() {
295
355
  )
296
356
  ) : (
297
357
  <>
298
- <GlassCard className="overflow-hidden border border-border">
358
+ <PageCard className="mt-0 overflow-hidden p-0">
299
359
  <div className="overflow-x-auto max-h-[700px] overflow-y-auto" onScroll={handleScroll}>
300
360
  <Table>
301
361
  <THead className="border-b border-border bg-well">
@@ -323,11 +383,32 @@ export default function LinksPage() {
323
383
  linkURL={linkURL}
324
384
  />
325
385
  ))}
386
+ {loading && (
387
+ <TR className="h-14" role="status" aria-busy="true" aria-label={t("links.loading")}>
388
+ <TD>
389
+ <div className="space-y-1.5">
390
+ <Skeleton className="h-4 w-36" />
391
+ <Skeleton className="h-3 w-24" />
392
+ </div>
393
+ </TD>
394
+ <TD>
395
+ <Skeleton className="h-3.5 w-48" />
396
+ </TD>
397
+ <TD className="text-center">
398
+ <Skeleton className="mx-auto h-5 w-10 rounded-full" />
399
+ </TD>
400
+ <TD className="text-center">
401
+ <Skeleton className="mx-auto h-5 w-16 rounded-full" />
402
+ </TD>
403
+ <TD className="text-right">
404
+ <Skeleton className="ml-auto h-4 w-28" />
405
+ </TD>
406
+ </TR>
407
+ )}
326
408
  </TBody>
327
409
  </Table>
328
- {loading && <div className="p-3 text-center text-xs text-muted-foreground">{t("links.loading")}</div>}
329
410
  </div>
330
- </GlassCard>
411
+ </PageCard>
331
412
  {error && (
332
413
  <Alert
333
414
  variant="danger"
@@ -349,50 +430,46 @@ export default function LinksPage() {
349
430
 
350
431
  {tab === "anomalies" && (
351
432
  <div className="space-y-6" data-testid="anomalies-projection-view">
352
- {/* Overview Stat Cards */}
353
433
  <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
354
- <GlassCard className="p-4 space-y-1.5">
355
- <div className="flex items-center justify-between">
356
- <span className="text-xs text-muted-foreground">{t("links.anomalyTraffic", "Traffic Anomalies")}</span>
357
- <Activity className="h-4 w-4 text-success-fg" />
358
- </div>
359
- <div className="text-xl font-semibold text-foreground">0</div>
360
- <div className="text-[11px] text-success-fg font-medium">{t("links.anomalyHealthySpikes", "Healthy · No spikes")}</div>
361
- </GlassCard>
362
-
363
- <GlassCard className="p-4 space-y-1.5">
364
- <div className="flex items-center justify-between">
365
- <span className="text-xs text-muted-foreground">{t("links.anomalyBot", "Bot Filtering")}</span>
366
- <ShieldCheck className="h-4 w-4 text-accent-fg" />
367
- </div>
368
- <div className="text-xl font-semibold text-foreground">{t("links.anomalyActive", "Active")}</div>
369
- <div className="text-[11px] text-muted-foreground">{t("links.anomalyRateLimitActive", "Rate limiting active")}</div>
370
- </GlassCard>
371
-
372
- <GlassCard className="p-4 space-y-1.5">
373
- <div className="flex items-center justify-between">
374
- <span className="text-xs text-muted-foreground">{t("links.anomalyLatency", "Redirect Latency")}</span>
375
- <Activity className="h-4 w-4 text-info-fg" />
376
- </div>
377
- <div className="text-xl font-semibold text-foreground">{t("links.anomalyLatencyValue", "< 35ms")}</div>
378
- <div className="text-[11px] text-success-fg font-medium">{t("links.anomalyP99Latency", "p99 edge redirect")}</div>
379
- </GlassCard>
380
-
381
- <GlassCard className="p-4 space-y-1.5">
382
- <div className="flex items-center justify-between">
383
- <span className="text-xs text-muted-foreground">{t("links.anomalyLoops", "Redirect Loops")}</span>
384
- <AlertTriangle className="h-4 w-4 text-warning-fg" />
385
- </div>
386
- <div className="text-xl font-semibold text-foreground">0</div>
387
- <div className="text-[11px] text-muted-foreground">{t("links.anomalyLoopClear", "Loop detector clear")}</div>
388
- </GlassCard>
434
+ <StatCard
435
+ label={t("links.anomalyTraffic", "Traffic Anomalies")}
436
+ value={0}
437
+ delta={t("links.anomalyHealthySpikes", "Healthy · No spikes")}
438
+ positive
439
+ icon={<Activity className="h-4 w-4 text-success-fg" />}
440
+ index={0}
441
+ />
442
+
443
+ <StatCard
444
+ label={t("links.anomalyBot", "Bot Filtering")}
445
+ value={t("links.anomalyActive", "Active")}
446
+ delta={t("links.anomalyRateLimitActive", "Rate limiting active")}
447
+ icon={<ShieldCheck className="h-4 w-4 text-accent-fg" />}
448
+ index={1}
449
+ />
450
+
451
+ <StatCard
452
+ label={t("links.anomalyLatency", "Redirect Latency")}
453
+ value={t("links.anomalyLatencyValue", "< 35ms")}
454
+ delta={t("links.anomalyP99Latency", "p99 edge redirect")}
455
+ positive
456
+ icon={<Activity className="h-4 w-4 text-info-fg" />}
457
+ index={2}
458
+ />
459
+
460
+ <StatCard
461
+ label={t("links.anomalyLoops", "Redirect Loops")}
462
+ value={0}
463
+ delta={t("links.anomalyLoopClear", "Loop detector clear")}
464
+ icon={<AlertTriangle className="h-4 w-4 text-warning-fg" />}
465
+ index={3}
466
+ />
389
467
  </div>
390
468
 
391
- {/* Anomaly Real-Time Monitor Card */}
392
469
  <Panel
393
470
  title={t("links.tabAnomalies", "Anomaly Monitoring")}
394
471
  description={t("links.anomalyDesc", "Real-time monitors track 404 floods, redirect loops, and abnormal traffic spikes.")}
395
- action={<Badge variant="success" className="text-xs">{t("links.anomalyOperational", "Operational")}</Badge>}
472
+ action={<StatusBadge tone="success" className="text-xs">{t("links.anomalyOperational", "Operational")}</StatusBadge>}
396
473
  >
397
474
 
398
475
  <div className="py-8 text-center space-y-2">
@@ -408,28 +485,41 @@ export default function LinksPage() {
408
485
 
409
486
  {tab === "reserved" && (
410
487
  <div className="space-y-6" data-testid="reserved-projection-view">
411
- {/* Guidance Banner */}
412
- <div className="flex items-center justify-between p-3 rounded-lg border border-primary/20 bg-accent-soft text-xs text-foreground">
413
- <div className="flex items-center gap-2">
414
- <Blocks className="h-4 w-4 text-accent-fg shrink-0" />
415
- <span>{t("links.reservedInstanceNotice", "Configure custom instance-level reserved slugs in Instance Settings.")}</span>
416
- </div>
417
- <NavLink
418
- to="/instance/settings"
419
- className="text-accent-fg hover:underline font-medium text-xs whitespace-nowrap ml-3"
488
+ <PageCard className="space-y-4">
489
+ <Field
490
+ label={t("links.customReservedLabel", "Custom Reserved Words")}
491
+ hint={t("links.customReservedHint", "Enter one reserved word per line. Short links cannot use these words.")}
420
492
  >
421
- {t("links.reservedInstanceAction", "Configure Instance Settings →")}
422
- </NavLink>
423
- </div>
493
+ <Textarea
494
+ className="font-mono text-xs"
495
+ rows={4}
496
+ value={reservedSlugs}
497
+ onChange={(e) => setReservedSlugs(e.target.value)}
498
+ placeholder={"preview\ninternal\nstatus"}
499
+ disabled={!isInstanceAdmin || savingReserved}
500
+ aria-label={t("links.customReservedLabel", "Custom Reserved Words")}
501
+ />
502
+ </Field>
503
+ {isInstanceAdmin && (
504
+ <div className="flex justify-end">
505
+ <Button
506
+ variant="primary"
507
+ className="text-xs"
508
+ onClick={handleSaveReserved}
509
+ disabled={savingReserved}
510
+ >
511
+ {savingReserved ? t("links.saving", "Saving…") : t("links.saveReserved", "Save reserved words")}
512
+ </Button>
513
+ </div>
514
+ )}
515
+ </PageCard>
424
516
 
425
- {/* Reserved Words GlassCard */}
426
517
  <Panel
427
518
  title={t("links.reservedTitle", "System Reserved Words")}
428
519
  description={t("links.reservedDesc", "Reserved words prevent short links from colliding with system routes and administrative endpoints.")}
429
520
  >
430
-
431
521
  <div className="flex flex-wrap gap-2 pt-2">
432
- {SYSTEM_RESERVED_SLUGS.map((slug) => (
522
+ {allReservedSlugs.map((slug) => (
433
523
  <span
434
524
  key={slug}
435
525
  className="inline-flex items-center px-2.5 py-1 rounded-md text-xs font-mono bg-well border border-border text-foreground"
@@ -457,6 +547,6 @@ export default function LinksPage() {
457
547
  onCopyQrLink={copy}
458
548
  linkURL={linkURL}
459
549
  />
460
- </ScreenWrap>
550
+ </PageShell>
461
551
  );
462
552
  }
@@ -22,7 +22,6 @@ const mockLinksWithPassword: Link[] = [
22
22
  archived: false,
23
23
  enabled: true,
24
24
  clicks: 5,
25
- password: "SecretCode123",
26
25
  hasPassword: true,
27
26
  routingRules: [],
28
27
  createdAt: "2026-06-01T00:00:00Z",
@@ -38,7 +37,7 @@ function jsonResponse(body: unknown, status = 200) {
38
37
  };
39
38
  }
40
39
 
41
- describe("Link password plaintext display and edit form", () => {
40
+ describe("Link password redaction and edit preservation", () => {
42
41
  let updatedPayload: any = null;
43
42
 
44
43
  beforeEach(() => {
@@ -54,6 +53,8 @@ describe("Link password plaintext display and edit form", () => {
54
53
  const path = urlObj.pathname;
55
54
  if (method === "GET" && path === "/api/links") return jsonResponse(mockLinksWithPassword);
56
55
  if (method === "GET" && path === "/api/domains") return jsonResponse([]);
56
+ if (method === "GET" && path === "/api/links/ai/status") return jsonResponse({ configured: false, provider: "" });
57
+ if (method === "GET" && path === "/api/links/capabilities") return jsonResponse({ geoReady: false, mode: "unavailable" });
57
58
  if (method === "PUT" && path === "/api/links/1") {
58
59
  updatedPayload = JSON.parse((init?.body as string) || "{}");
59
60
  return jsonResponse({ ...mockLinksWithPassword[0], ...updatedPayload });
@@ -63,7 +64,7 @@ describe("Link password plaintext display and edit form", () => {
63
64
  vi.stubGlobal("fetch", fetchMock);
64
65
  });
65
66
 
66
- it("displays password in plaintext on the link badge and pre-fills the plaintext input in edit form", async () => {
67
+ it("hides plaintext password in table, uses type=password with blank value on edit, and omits password when left blank", async () => {
67
68
  render(
68
69
  <MemoryRouter initialEntries={["/links"]}>
69
70
  <I18nProvider>
@@ -72,12 +73,12 @@ describe("Link password plaintext display and edit form", () => {
72
73
  </MemoryRouter>
73
74
  );
74
75
 
75
- // 1. Password should be visible in plain text on the badge in the list
76
76
  await waitFor(() => {
77
- expect(screen.getByText("SecretCode123")).toBeDefined();
77
+ const lockBadge = screen.getByTitle("Access protection password");
78
+ expect(lockBadge).toBeDefined();
79
+ expect(lockBadge.textContent?.trim()).toBe("");
78
80
  });
79
81
 
80
- // 2. Click Edit Link to open the editor modal
81
82
  const editBtn = screen.getByTitle("Edit link");
82
83
  fireEvent.click(editBtn);
83
84
 
@@ -85,18 +86,44 @@ describe("Link password plaintext display and edit form", () => {
85
86
  expect(screen.getByText("Edit link — Protected Link")).toBeDefined();
86
87
  });
87
88
 
88
- // 3. The password input field should be type="text" and contain "SecretCode123"
89
- const passwordInput = screen.getByDisplayValue("SecretCode123") as HTMLInputElement;
90
- expect(passwordInput).toBeDefined();
91
- expect(passwordInput.type).toBe("text");
89
+ expect(screen.getByText("Key set. Fill to overwrite, blank to keep")).toBeDefined();
90
+ const passwordInput = screen.getByPlaceholderText("e.g. 123456") as HTMLInputElement;
91
+ expect(passwordInput.type).toBe("password");
92
+ expect(passwordInput.value).toBe("");
92
93
 
93
- // 4. Save without touching password -> payload should retain the password and not silently clear it
94
- const saveBtn = screen.getByText("Save link");
95
- fireEvent.click(saveBtn);
94
+ fireEvent.click(screen.getByText("Save link"));
96
95
 
97
96
  await waitFor(() => {
98
97
  expect(updatedPayload).not.toBeNull();
99
98
  });
100
- expect(updatedPayload.password).toBe("SecretCode123");
99
+ expect("password" in updatedPayload).toBe(false);
100
+ });
101
+
102
+ it("sends new password when filled on edit", async () => {
103
+ render(
104
+ <MemoryRouter initialEntries={["/links"]}>
105
+ <I18nProvider>
106
+ <LinksPage />
107
+ </I18nProvider>
108
+ </MemoryRouter>
109
+ );
110
+
111
+ await waitFor(() => {
112
+ expect(screen.getByTitle("Edit link")).toBeDefined();
113
+ });
114
+
115
+ fireEvent.click(screen.getByTitle("Edit link"));
116
+ await waitFor(() => {
117
+ expect(screen.getByText("Edit link — Protected Link")).toBeDefined();
118
+ });
119
+
120
+ const passwordInput = screen.getByPlaceholderText("e.g. 123456") as HTMLInputElement;
121
+ fireEvent.change(passwordInput, { target: { value: "NewSecret456" } });
122
+ fireEvent.click(screen.getByText("Save link"));
123
+
124
+ await waitFor(() => {
125
+ expect(updatedPayload).not.toBeNull();
126
+ });
127
+ expect(updatedPayload.password).toBe("NewSecret456");
101
128
  });
102
129
  });
@@ -102,21 +102,17 @@ describe("LinksPage title priority and tag badges", () => {
102
102
  </MemoryRouter>
103
103
  );
104
104
 
105
- // Wait for links to load
106
105
  await waitFor(() => {
107
106
  expect(screen.getByText("Summer Sale 2026")).toBeDefined();
108
107
  });
109
108
 
110
- // Primary title has font-medium and text-foreground
111
109
  const title = screen.getByText("Summer Sale 2026");
112
110
  expect(title.className).toContain("font-medium");
113
111
  expect(title.className).toContain("text-foreground");
114
112
 
115
- // Secondary short slug
116
113
  expect(screen.getByText("link.acme.com/")).toBeDefined();
117
114
  expect(screen.getByText("summer-sale")).toBeDefined();
118
115
 
119
- // Tags are rendered as separate badges, not one single concatenated string
120
116
  const tagEcommerce = screen.getByTitle("ecommerce");
121
117
  const tagPromo = screen.getByTitle("promo");
122
118
  const tagVip = screen.getByTitle("vip");
@@ -127,7 +123,6 @@ describe("LinksPage title priority and tag badges", () => {
127
123
  expect(tagPromo.textContent).toContain("promo");
128
124
  expect(tagVip.textContent).toContain("vip");
129
125
 
130
- // Link without title falls back to slug in primary title and secondary slug
131
126
  const untitledMatches = screen.getAllByText("random-slug-without-title");
132
127
  expect(untitledMatches.length).toBe(2);
133
128
  });
@@ -145,7 +140,6 @@ describe("LinksPage title priority and tag badges", () => {
145
140
  expect(screen.getByText("Summer Sale 2026")).toBeDefined();
146
141
  });
147
142
 
148
- // Test Analytics modal title for link with title
149
143
  const analyticsButtons = screen.getAllByTitle("Analytics");
150
144
  fireEvent.click(analyticsButtons[0]);
151
145
 
@@ -153,10 +147,8 @@ describe("LinksPage title priority and tag badges", () => {
153
147
  expect(screen.getByText("Click performance analytics — Summer Sale 2026")).toBeDefined();
154
148
  });
155
149
 
156
- // Close Analytics modal
157
150
  fireEvent.click(screen.getByRole("button", { name: "Close" }));
158
151
 
159
- // Test QR modal title for link with title
160
152
  const qrButtons = screen.getAllByTitle("QR code");
161
153
  fireEvent.click(qrButtons[0]);
162
154
 
@@ -164,10 +156,8 @@ describe("LinksPage title priority and tag badges", () => {
164
156
  expect(screen.getByText("Link QR code — Summer Sale 2026")).toBeDefined();
165
157
  });
166
158
 
167
- // Close QR modal
168
159
  fireEvent.click(screen.getByRole("button", { name: "Close" }));
169
160
 
170
- // Test Edit modal title for link with title
171
161
  const editButtons = screen.getAllByTitle("Edit link");
172
162
  fireEvent.click(editButtons[0]);
173
163
 
@@ -175,10 +165,8 @@ describe("LinksPage title priority and tag badges", () => {
175
165
  expect(screen.getByText("Edit link — Summer Sale 2026")).toBeDefined();
176
166
  });
177
167
 
178
- // Close Edit modal
179
168
  fireEvent.click(screen.getByRole("button", { name: "Close" }));
180
169
 
181
- // Test Edit modal title for link without title (fallback to /slug)
182
170
  fireEvent.click(editButtons[1]);
183
171
 
184
172
  await waitFor(() => {
@@ -12,12 +12,18 @@ vi.mock("../api", () => ({
12
12
  updateLink: vi.fn(),
13
13
  deleteLink: vi.fn(),
14
14
  domains: vi.fn(),
15
+ exportCsv: vi.fn(),
16
+ getSettings: vi.fn(),
17
+ updateSettings: vi.fn(),
15
18
  },
16
19
  api: {
17
20
  links: vi.fn(),
18
21
  updateLink: vi.fn(),
19
22
  deleteLink: vi.fn(),
20
23
  domains: vi.fn(),
24
+ exportCsv: vi.fn(),
25
+ getSettings: vi.fn(),
26
+ updateSettings: vi.fn(),
21
27
  },
22
28
  effectiveLinkHosts: (d: any) => [d.domain || d.name],
23
29
  }));
@@ -39,6 +45,10 @@ describe("LinksPage — 3 Horizontal Projection Tabs", () => {
39
45
  vi.clearAllMocks();
40
46
  (api.domains as any).mockResolvedValue([{ id: 1, domain: "go.link" }]);
41
47
  (linksApi.domains as any).mockResolvedValue([{ id: 1, domain: "go.link" }]);
48
+ (linksApi.getSettings as any).mockResolvedValue({ reservedSlugs: "customone\ncustomtwo" });
49
+ (api.getSettings as any).mockResolvedValue({ reservedSlugs: "customone\ncustomtwo" });
50
+ (linksApi.updateSettings as any).mockImplementation(async (s: any) => s);
51
+ (api.updateSettings as any).mockImplementation(async (s: any) => s);
42
52
  (linksApi.links as any).mockResolvedValue([
43
53
  {
44
54
  id: 1,
@@ -60,24 +70,20 @@ describe("LinksPage — 3 Horizontal Projection Tabs", () => {
60
70
  it("renders 3 horizontal projection tabs and switches between them cleanly", async () => {
61
71
  renderPage();
62
72
 
63
- // Verify all 3 tabs are present
64
73
  expect(screen.getByTestId("tab-links")).toBeDefined();
65
74
  expect(screen.getByTestId("tab-anomalies")).toBeDefined();
66
75
  expect(screen.getByTestId("tab-reserved")).toBeDefined();
67
76
 
68
- // Default projection: Links view
69
77
  await waitFor(() => {
70
78
  expect(screen.getByTestId("links-projection-view")).toBeDefined();
71
79
  });
72
80
 
73
- // Switch to Anomaly Monitoring projection
74
81
  fireEvent.click(screen.getByTestId("tab-anomalies"));
75
82
  expect(screen.getByTestId("anomalies-projection-view")).toBeDefined();
76
83
  expect(screen.queryByTestId("links-projection-view")).toBeNull();
77
84
  expect(screen.getByText("Traffic Anomalies")).toBeDefined();
78
85
  expect(screen.getByText("Bot Filtering")).toBeDefined();
79
86
 
80
- // Switch to Reserved Words projection
81
87
  fireEvent.click(screen.getByTestId("tab-reserved"));
82
88
  expect(screen.getByTestId("reserved-projection-view")).toBeDefined();
83
89
  expect(screen.queryByTestId("anomalies-projection-view")).toBeNull();
@@ -85,7 +91,23 @@ describe("LinksPage — 3 Horizontal Projection Tabs", () => {
85
91
  expect(screen.getByText("/api")).toBeDefined();
86
92
  expect(screen.getByText("/instance")).toBeDefined();
87
93
 
88
- // Switch back to Links projection
94
+ await waitFor(() => {
95
+ expect(screen.getByText("/customone")).toBeDefined();
96
+ expect(screen.getByText("/customtwo")).toBeDefined();
97
+ });
98
+
99
+ const textarea = screen.getByRole("textbox", { name: /Custom Reserved Words/i });
100
+ expect((textarea as HTMLTextAreaElement).value).toBe("customone\ncustomtwo");
101
+
102
+ fireEvent.change(textarea, { target: { value: "customone\ncustomtwo\nbrandnew" } });
103
+ const saveBtn = screen.getByRole("button", { name: /Save reserved words/i });
104
+ fireEvent.click(saveBtn);
105
+
106
+ await waitFor(() => {
107
+ expect(linksApi.updateSettings).toHaveBeenCalledWith({ reservedSlugs: "customone\ncustomtwo\nbrandnew" });
108
+ expect(screen.getByText("/brandnew")).toBeDefined();
109
+ });
110
+
89
111
  fireEvent.click(screen.getByTestId("tab-links"));
90
112
  expect(screen.getByTestId("links-projection-view")).toBeDefined();
91
113
  });