-
Notifications
You must be signed in to change notification settings - Fork 241
Expand file tree
/
Copy pathmetadata.test.ts
More file actions
411 lines (366 loc) · 13.9 KB
/
Copy pathmetadata.test.ts
File metadata and controls
411 lines (366 loc) · 13.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
import { describe, expect, it, vi } from "vitest";
import { readFileSync } from "fs";
import { resolve } from "path";
const { mockLocalFont, mockEnMessages } = vi.hoisted(() => {
// Footer references `messages` as a global without importing it.
// Set it here so the module can be evaluated in tests.
const msg = {
footer: {
description: "StelloPay footer",
socialLinks: {
twitter: "X",
linkedIn: "LinkedIn",
gitHub: "GitHub",
email: "Email",
},
categories: {
product: "Product",
company: "Company",
resources: "Resources",
legal: "Legal",
},
links: {
features: "Features",
pricing: "Pricing",
security: "Security",
api: "API",
integrations: "Integrations",
about: "About",
blog: "Blog",
careers: "Careers",
press: "Press",
partners: "Partners",
documentation: "Docs",
helpCenter: "Help Center",
tutorials: "Tutorials",
community: "Community",
errorPages: "Errors",
privacy: "Privacy",
terms: "Terms",
cookiePolicy: "Cookies",
licenses: "Licenses",
},
newsletter: {
heading: "Newsletter",
description: "Subscribe",
placeholder: "Enter email",
subscribe: "Subscribe",
subscribing: "Subscribing...",
},
bottomBar: {
copyright: "© StelloPay",
privacyPolicy: "Privacy",
termsOfService: "Terms",
cookiePolicy: "Cookies",
},
},
dashboard: {
quickActions: [],
},
};
globalThis.messages = msg;
return { mockLocalFont: vi.fn(() => ({ variable: "font-local" })), mockEnMessages: msg };
});
vi.mock("next/font/google", () => ({
Inter: () => ({ variable: "font-inter" }),
}));
vi.mock("next/font/local", () => ({
default: mockLocalFont,
}));
vi.mock("@/messages", () => ({
default: mockEnMessages,
messages: mockEnMessages,
}));
import {
metadata as rootMetadata,
viewport as rootViewport,
} from "@/app/layout";
import sitemap, { BASE_URL, PUBLIC_ROUTES } from "@/app/sitemap";
import robots, { DISALLOWED_PATHS } from "@/app/robots";
import { metadata as dashboardMetadata } from "@/app/dashboard/layout";
import { metadata as transactionsMetadata } from "@/app/transactions/layout";
import { metadata as settingsMetadata } from "@/app/settings/preferences/layout";
import { metadata as loginMetadata } from "@/app/auth/login/page";
import { metadata as signUpMetadata } from "@/app/auth/sign-up/page";
import { metadata as verifyEmailMetadata } from "@/app/verify-email/layout";
import { landingStructuredData } from "@/app/structured-data";
describe("Route Metadata Exports", () => {
it("defines standard metadata properties on the root layout", () => {
expect(rootMetadata).toBeDefined();
expect(rootMetadata.title).toBeDefined();
expect(rootMetadata.description).toBeDefined();
expect(rootMetadata.openGraph).toBeDefined();
expect(rootMetadata.twitter).toBeDefined();
expect(rootMetadata.manifest).toBe("/manifest.json");
});
it("exports a dedicated viewport object on the root layout", () => {
expect(rootViewport).toBeDefined();
expect(rootViewport.themeColor).toBeDefined();
expect(rootViewport.width).toBe("device-width");
});
it("preloads above-the-fold local fonts and uses swap to avoid FOIT", () => {
const localFonts = mockLocalFont.mock.calls.map(([options]) => options);
expect(localFonts).toEqual(
expect.arrayContaining([
expect.objectContaining({
src: "../public/font/clash-display-variable.ttf",
variable: "--font-clash",
display: "swap",
preload: true,
}),
expect.objectContaining({
src: "../public/font/general-sans-variable.ttf",
// Matches the body typography token in app/globals.css.
variable: "--font-general-sans",
display: "swap",
preload: true,
}),
]),
);
});
it("each route exports unique page titles and descriptions", () => {
const titles = [
typeof rootMetadata.title === "object" &&
rootMetadata.title !== null &&
"default" in rootMetadata.title
? rootMetadata.title.default
: rootMetadata.title,
dashboardMetadata.title,
transactionsMetadata.title,
settingsMetadata.title,
loginMetadata.title,
signUpMetadata.title,
verifyEmailMetadata.title,
];
const descriptions = [
rootMetadata.description,
dashboardMetadata.description,
transactionsMetadata.description,
settingsMetadata.description,
loginMetadata.description,
signUpMetadata.description,
verifyEmailMetadata.description,
];
// Assert titles are unique and defined
titles.forEach((title) => {
expect(title).toBeDefined();
expect(typeof title).toBe("string");
});
const uniqueTitles = new Set(titles);
expect(uniqueTitles.size).toBe(titles.length);
// Assert descriptions are unique and defined
descriptions.forEach((desc) => {
expect(desc).toBeDefined();
expect(typeof desc).toBe("string");
});
const uniqueDescriptions = new Set(descriptions);
expect(uniqueDescriptions.size).toBe(descriptions.length);
});
it("applies noindex robots tags to private or sensitive authenticated routes", () => {
// Dashboard, Transactions, Settings, and Verify Email routes should have robots noindex/nofollow
const privateMetadata = [
dashboardMetadata,
transactionsMetadata,
settingsMetadata,
verifyEmailMetadata,
];
privateMetadata.forEach((meta) => {
expect(meta.robots).toBeDefined();
expect(meta.robots).toEqual({
index: false,
follow: false,
});
});
});
it("ensures public route metadata does not place user or account data in titles or descriptions", () => {
const allMetadata = [
rootMetadata,
dashboardMetadata,
transactionsMetadata,
settingsMetadata,
loginMetadata,
signUpMetadata,
verifyEmailMetadata,
];
allMetadata.forEach((meta) => {
const titleStr =
typeof meta.title === "string"
? meta.title
: JSON.stringify(meta.title);
const descStr = meta.description || "";
// Ensure no dynamically interpolated session/user tags exist in static metadata text
expect(titleStr).not.toContain("${");
expect(descStr).not.toContain("${");
});
});
// ── Design Token Migration Matrix ────────────────────────────────────────────
it("design-token migration matrix document exists and is non-empty", () => {
const matrixPath = resolve(
__dirname,
"../design/token-migration-matrix.md",
);
const content = readFileSync(matrixPath, "utf-8");
expect(content.length).toBeGreaterThan(100);
expect(content).toContain("# Design Token Migration Matrix");
expect(content).toContain("Migration Status Overview");
});
it("design-token migration matrix covers all major component categories", () => {
const matrixPath = resolve(
__dirname,
"../design/token-migration-matrix.md",
);
const content = readFileSync(matrixPath, "utf-8");
// Verify each priority tier is represented
expect(content).toContain("High");
expect(content).toContain("Medium");
expect(content).toContain("Low");
// Verify status indicators are present
expect(content).toContain("Done");
expect(content).toContain("In Progress");
expect(content).toContain("Not Started");
});
it("design-token migration matrix prioritizes landing and dashboard surfaces", () => {
const matrixPath = resolve(
__dirname,
"../design/token-migration-matrix.md",
);
const content = readFileSync(matrixPath, "utf-8");
expect(content).toContain("Landing Hero");
expect(content).toContain("Dashboard Account Summary");
expect(content).toContain("Settings Preferences");
expect(content).toContain("https://github.com/stellopay/frontend/issues/");
});
it("design-token migration matrix inventories representative app and component surfaces", () => {
const matrixPath = resolve(
__dirname,
"../design/token-migration-matrix.md",
);
const content = readFileSync(matrixPath, "utf-8");
expect(content).toContain("app/account-summary/page.tsx");
expect(content).toContain("components/common/footer.tsx");
expect(content).toContain("components/common/navbar.tsx");
});
it("globals.css contains design token documentation comment", () => {
const cssPath = resolve(__dirname, "globals.css");
const content = readFileSync(cssPath, "utf-8");
expect(content).toContain("Design Token Migration Reference");
expect(content).toContain("token-migration-matrix.md");
describe("Landing Page JSON-LD Structured Data", () => {
it("exports a valid structured data object with @graph", () => {
expect(landingStructuredData).toBeDefined();
expect(landingStructuredData).toHaveProperty(
"@context",
"https://schema.org",
);
expect(landingStructuredData).toHaveProperty("@graph");
});
it("@graph contains exactly three schema.org entities", () => {
const { "@graph": graph } = landingStructuredData;
expect(Array.isArray(graph)).toBe(true);
expect(graph).toHaveLength(3);
});
it("includes an Organization entity with required properties", () => {
const org = landingStructuredData["@graph"].find(
(item: Record<string, unknown>) => item["@type"] === "Organization",
);
expect(org).toBeDefined();
expect(org).toHaveProperty("name", "StelloPay");
expect(org).toHaveProperty("url", "https://stellopay.com");
expect(org).toHaveProperty("logo");
expect(org).toHaveProperty("description");
expect(org).toHaveProperty("sameAs");
expect(Array.isArray(org!.sameAs)).toBe(true);
});
it("includes a WebSite entity with SearchAction", () => {
const site = landingStructuredData["@graph"].find(
(item: Record<string, unknown>) => item["@type"] === "WebSite",
);
expect(site).toBeDefined();
expect(site).toHaveProperty("name", "StelloPay");
expect(site).toHaveProperty("url", "https://stellopay.com");
expect(site).toHaveProperty("potentialAction");
expect(
(site!.potentialAction as Record<string, unknown>)["@type"],
).toBe("SearchAction");
});
it("includes a WebApplication entity with required SoftwareApplication properties", () => {
const app = landingStructuredData["@graph"].find(
(item: Record<string, unknown>) => {
const types = item["@type"];
return (
Array.isArray(types) &&
types.includes("WebApplication") &&
types.includes("SoftwareApplication")
);
},
);
expect(app).toBeDefined();
expect(app).toHaveProperty("name", "StelloPay");
expect(app).toHaveProperty("url", "https://stellopay.com");
expect(app).toHaveProperty("applicationCategory", "FinanceApplication");
expect(app).toHaveProperty("operatingSystem", "Web");
expect(app).toHaveProperty("description");
expect(app).toHaveProperty("offers");
expect(app).toHaveProperty("provider");
});
it("WebApplication offers freemium pricing data", () => {
const app = landingStructuredData["@graph"].find(
(item: Record<string, unknown>) =>
Array.isArray(item["@type"]) &&
item["@type"].includes("WebApplication"),
);
const offers = app!.offers as Record<string, unknown>;
expect(offers).toHaveProperty("@type", "Offer");
expect(offers).toHaveProperty("price", "0");
expect(offers).toHaveProperty("priceCurrency", "USD");
});
it("JSON-LD does not contain sensitive or PII data", () => {
const json = JSON.stringify(landingStructuredData);
// No Stellar secret keys (S-prefixed base32)
expect(json).not.toMatch(/\bS[A-Z2-7]{55}\b/);
// No template interpolation artifacts
expect(json).not.toContain("${");
});
it("all URLs in structured data use HTTPS", () => {
const json = JSON.stringify(landingStructuredData);
const urls = json.match(/"https?:\/\/[^"]+"/g) || [];
expect(urls.length).toBeGreaterThan(0);
urls.forEach((url: string) => {
expect(url).toMatch(/^"https:\/\//);
});
});
});
});
// ── Bundle Budget (scripts/bundle-budgets.json) ──────────────────────────────
import budgets from "@/scripts/bundle-budgets.json";
describe("Bundle Budget — scripts/bundle-budgets.json", () => {
it("defines a budget for the landing page", () => {
expect(budgets["/"]).toBeGreaterThan(0);
});
it("defines a budget for the dashboard", () => {
expect(budgets["/dashboard"]).toBeGreaterThan(0);
});
it("defines a budget for /auth/login", () => {
expect(budgets["/auth/login"]).toBeGreaterThan(0);
});
it("defines a budget for /auth/sign-up", () => {
expect(budgets["/auth/sign-up"]).toBeGreaterThan(0);
});
it("auth route budgets are at or below 200 kB for conversion-critical pages", () => {
expect(budgets["/auth/login"]).toBeLessThanOrEqual(200);
expect(budgets["/auth/sign-up"]).toBeLessThanOrEqual(200);
});
it("dashboard budget is leaner than landing budget", () => {
expect(budgets["/dashboard"]).toBeLessThan(budgets["/"]);
});
it("every budget entry is a positive integer", () => {
for (const [route, budget] of Object.entries(budgets)) {
expect(Number.isInteger(budget)).toBe(true);
expect(budget).toBeGreaterThan(0);
}
});
it("includes auth routes as budgeted entries", () => {
expect(budgets).toHaveProperty("/auth/login");
expect(budgets).toHaveProperty("/auth/sign-up");
});
});