create-ailk 0.46.6 → 0.47.0
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/dist/lib/env-catalog.js +4 -0
- package/package.json +3 -3
- package/templates/apps/api/.env.example +18 -0
- package/templates/apps/api/CLAUDE.md +1 -0
- package/templates/apps/api/src/__tests__/vercel-handler.test.ts +176 -2
- package/templates/apps/api/src/lib/__mocks__/prisma.ts +16 -0
- package/templates/apps/api/src/vercel-handler.ts +32 -2
- package/templates/apps/mcp/.env.example +8 -0
- package/templates/apps/mcp/CLAUDE.md +2 -2
- package/templates/apps/web/CLAUDE.md +19 -3
- package/templates/apps/web/app/[locale]/layout.tsx +98 -37
- package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +13 -3
- package/templates/apps/web/lib/__tests__/hub-site-config.test.ts +394 -10
- package/templates/apps/web/lib/__tests__/page-chrome-navigation.test.ts +194 -0
- package/templates/apps/web/lib/__tests__/site-identity-feature-list.test.ts +19 -1
- package/templates/apps/web/lib/__tests__/site-navigation.test.ts +288 -0
- package/templates/apps/web/lib/hub-site-config.ts +154 -29
- package/templates/apps/web/lib/page-chrome.ts +70 -3
- package/templates/apps/web/lib/site-navigation.ts +208 -0
- package/templates/apps/web/next.config.mjs +19 -6
- package/versions.json +51 -51
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment node
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The hub navigation record's styles over `_site.mdx`'s (#12401, spec
|
|
7
|
+
* docs/specs/12401-a-site-renders-its-header-spec.md D4; AC-6).
|
|
8
|
+
*
|
|
9
|
+
* `withNavigationStyles` is pure; `resolveHomeChrome` reads the record
|
|
10
|
+
* through the hub read, so `@working-theory/api-client`'s `siteConfig.get`
|
|
11
|
+
* (the HTTP call to the hub) is doubled and `next/cache` runs the read
|
|
12
|
+
* uncached. `_site.mdx` is a scratch content root (`AILK_CONTENT_ROOT`).
|
|
13
|
+
*/
|
|
14
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
15
|
+
import { tmpdir } from "node:os";
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
|
|
18
|
+
const mockGet = jest.fn();
|
|
19
|
+
jest.mock("@working-theory/api-client", () => ({
|
|
20
|
+
...jest.requireActual("@working-theory/api-client"),
|
|
21
|
+
siteConfig: { get: (...args: unknown[]) => mockGet(...args) },
|
|
22
|
+
}));
|
|
23
|
+
jest.mock("next/cache", () => ({
|
|
24
|
+
unstable_cache: (fn: () => Promise<unknown>) => fn,
|
|
25
|
+
}));
|
|
26
|
+
let mockPagePathThrows = false;
|
|
27
|
+
jest.mock("@working-theory/templates/routes", () => {
|
|
28
|
+
const actual = jest.requireActual("@working-theory/templates/routes");
|
|
29
|
+
return {
|
|
30
|
+
...actual,
|
|
31
|
+
pagePath: (...args: Parameters<typeof actual.pagePath>) => {
|
|
32
|
+
if (mockPagePathThrows) throw new RangeError("forced");
|
|
33
|
+
return actual.pagePath(...args);
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
import { siteNavigationSchema } from "@working-theory/validation";
|
|
39
|
+
|
|
40
|
+
import { __resetHubSiteForTests } from "../hub-site-config";
|
|
41
|
+
import {
|
|
42
|
+
resolveHomeChrome,
|
|
43
|
+
resolvePageChrome,
|
|
44
|
+
withNavigationStyles,
|
|
45
|
+
type SiteChromeSettings,
|
|
46
|
+
} from "../page-chrome";
|
|
47
|
+
|
|
48
|
+
// #10704 — a fixture suite: its content is shaped for the mdx source.
|
|
49
|
+
process.env.CONTENT_ADAPTER = "mdx";
|
|
50
|
+
|
|
51
|
+
const FILE: SiteChromeSettings = {
|
|
52
|
+
headerStyle: "full",
|
|
53
|
+
footerStyle: "columns",
|
|
54
|
+
// A renamed family's `path` rides beside its styles at runtime (#11385).
|
|
55
|
+
families: { portfolio: { footer: "none", path: "/writing-samples" } } as SiteChromeSettings["families"],
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const recordWith = (extra: { header?: object; families?: object }) =>
|
|
59
|
+
siteNavigationSchema.parse({
|
|
60
|
+
version: "1",
|
|
61
|
+
header: { items: [], ...extra.header },
|
|
62
|
+
footer: { columns: [] },
|
|
63
|
+
...(extra.families ? { families: extra.families } : {}),
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const STYLED = recordWith({ header: { style: "bare" }, families: { portfolio: { header: "none" } } });
|
|
67
|
+
const KNOBS = { home: "default" as const, footer: "columns" as const };
|
|
68
|
+
|
|
69
|
+
describe("withNavigationStyles (#12401 D4, AC-6)", () => {
|
|
70
|
+
it("lays the record's set styles over the file's, keeping the family's own path", () => {
|
|
71
|
+
const before = structuredClone(FILE);
|
|
72
|
+
expect(withNavigationStyles(FILE, STYLED)).toEqual({
|
|
73
|
+
headerStyle: "bare",
|
|
74
|
+
footerStyle: "columns",
|
|
75
|
+
families: { portfolio: { header: "none", footer: "none", path: "/writing-samples" } },
|
|
76
|
+
});
|
|
77
|
+
expect(FILE).toEqual(before);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("a record setting no style answers the file settings unchanged", () => {
|
|
81
|
+
const before = structuredClone(FILE);
|
|
82
|
+
expect(withNavigationStyles(FILE, recordWith({}))).toEqual(FILE);
|
|
83
|
+
expect(FILE).toEqual(before);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("a record style the file does not set is added; a style neither sets stays unset", () => {
|
|
87
|
+
const result = withNavigationStyles({ families: {} }, recordWith({ families: { blog: { footer: "closing" } } }));
|
|
88
|
+
expect(result).toEqual({ families: { blog: { footer: "closing" } } });
|
|
89
|
+
expect(result).not.toHaveProperty("headerStyle");
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("no record answers the file settings", () => {
|
|
93
|
+
expect(withNavigationStyles(FILE, null)).toEqual(FILE);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe("resolveHomeChrome with a hub-connected read (#12401 D4, AC-6)", () => {
|
|
98
|
+
const ENV = ["AILK_SPOKE_KEY", "AILK_API_URL", "AILK_CONTENT_ROOT"] as const;
|
|
99
|
+
const saved = new Map(ENV.map((k) => [k, process.env[k]]));
|
|
100
|
+
let root: string;
|
|
101
|
+
|
|
102
|
+
beforeEach(() => {
|
|
103
|
+
__resetHubSiteForTests();
|
|
104
|
+
mockGet.mockReset();
|
|
105
|
+
mockPagePathThrows = false;
|
|
106
|
+
root = mkdtempSync(join(tmpdir(), "page-chrome-nav-"));
|
|
107
|
+
writeFileSync(
|
|
108
|
+
join(root, "_site.mdx"),
|
|
109
|
+
"---\nsiteName: Acme\nheader:\n style: full\nfooter:\n style: columns\nportfolio:\n footer: none\n path: /writing-samples\n---\n",
|
|
110
|
+
);
|
|
111
|
+
process.env.AILK_CONTENT_ROOT = root;
|
|
112
|
+
jest.spyOn(console, "warn").mockImplementation(() => undefined);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
afterEach(() => {
|
|
116
|
+
jest.restoreAllMocks();
|
|
117
|
+
rmSync(root, { recursive: true, force: true });
|
|
118
|
+
for (const [k, v] of saved) {
|
|
119
|
+
if (v === undefined) delete process.env[k];
|
|
120
|
+
else process.env[k] = v;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("resolves the home's header from the record, and a page's own frontmatter still wins", async () => {
|
|
125
|
+
process.env.AILK_SPOKE_KEY = "ailk_spk_TESTKEYxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
|
|
126
|
+
process.env.AILK_API_URL = "https://hub.example";
|
|
127
|
+
mockGet.mockResolvedValue({
|
|
128
|
+
ok: true,
|
|
129
|
+
body: { identity: null, seo: null, navigation: { version: 2, record: STYLED } },
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const home = await resolveHomeChrome("en", KNOBS);
|
|
133
|
+
expect(home.chrome.header).toBe("bare");
|
|
134
|
+
expect(home.site.families.portfolio).toEqual({ header: "none", footer: "none", path: "/writing-samples" });
|
|
135
|
+
|
|
136
|
+
const page = (header?: "full") =>
|
|
137
|
+
resolvePageChrome({
|
|
138
|
+
isHome: false,
|
|
139
|
+
homeIsDeck: false,
|
|
140
|
+
family: "portfolio",
|
|
141
|
+
page: header ? { header } : {},
|
|
142
|
+
site: home.site,
|
|
143
|
+
chrome: KNOBS,
|
|
144
|
+
closingListed: false,
|
|
145
|
+
});
|
|
146
|
+
expect(page("full").header).toBe("full");
|
|
147
|
+
expect(page().header).toBe("none");
|
|
148
|
+
expect(page().footer).toBe("none");
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("with no hub read, the home resolves from the file", async () => {
|
|
152
|
+
const home = await resolveHomeChrome("en", KNOBS);
|
|
153
|
+
expect(home.chrome.header).toBe("full");
|
|
154
|
+
expect(home.navigation).toBeNull();
|
|
155
|
+
expect(mockGet).not.toHaveBeenCalled();
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("answers the rendered record with its version and translation", async () => {
|
|
159
|
+
process.env.AILK_SPOKE_KEY = "ailk_spk_TESTKEYxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
|
|
160
|
+
process.env.AILK_API_URL = "https://hub.example";
|
|
161
|
+
mockGet.mockResolvedValue({
|
|
162
|
+
ok: true,
|
|
163
|
+
body: { identity: null, seo: null, navigation: { version: 2, record: STYLED } },
|
|
164
|
+
});
|
|
165
|
+
const home = await resolveHomeChrome("en", KNOBS);
|
|
166
|
+
expect(home.navigation?.version).toBe(2);
|
|
167
|
+
expect(home.navigation?.chrome.navItems).toEqual([]);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("a record the translator refuses lays no style: the home resolves from the file, with no navigation", async () => {
|
|
171
|
+
process.env.AILK_SPOKE_KEY = "ailk_spk_TESTKEYxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
|
|
172
|
+
process.env.AILK_API_URL = "https://hub.example";
|
|
173
|
+
// A record the schema takes cannot fail the translator, so the refusal is
|
|
174
|
+
// forced through `pagePath`, the one call inside it a mock can reach.
|
|
175
|
+
mockPagePathThrows = true;
|
|
176
|
+
const refused = siteNavigationSchema.parse({
|
|
177
|
+
version: "1",
|
|
178
|
+
header: {
|
|
179
|
+
style: "bare",
|
|
180
|
+
items: [{ kind: "link", label: { text: "Audit" }, target: { kind: "page", address: { type: "Service", slug: "audit" } } }],
|
|
181
|
+
},
|
|
182
|
+
footer: { columns: [] },
|
|
183
|
+
families: { portfolio: { header: "none" } },
|
|
184
|
+
});
|
|
185
|
+
mockGet.mockResolvedValue({
|
|
186
|
+
ok: true,
|
|
187
|
+
body: { identity: null, seo: null, navigation: { version: 2, record: refused } },
|
|
188
|
+
});
|
|
189
|
+
const home = await resolveHomeChrome("en", KNOBS);
|
|
190
|
+
expect(home.navigation).toBeNull();
|
|
191
|
+
expect(home.chrome.header).toBe("full");
|
|
192
|
+
expect(home.site.families.portfolio).toEqual({ footer: "none", path: "/writing-samples" });
|
|
193
|
+
});
|
|
194
|
+
});
|
|
@@ -320,12 +320,30 @@ describe("the featureList registration with no content directory (#10644 AC-2)",
|
|
|
320
320
|
expect(mockSiteConfigGet).toHaveBeenCalledTimes(1);
|
|
321
321
|
});
|
|
322
322
|
|
|
323
|
+
// #12390 D2 — a single-tenant site (its own API's address, no key) reads
|
|
324
|
+
// its one workspace's identity through the same reader.
|
|
325
|
+
it("keyless with an API address: registers a reader carrying the workspace identity on the file's baseUrl", async () => {
|
|
326
|
+
hubConnect();
|
|
327
|
+
delete process.env.AILK_SPOKE_KEY;
|
|
328
|
+
delete process.env.NEXT_PUBLIC_SITE_URL;
|
|
329
|
+
load();
|
|
330
|
+
expect(calls("setSiteIdentityReader")).toHaveLength(1);
|
|
331
|
+
const reader = calls("setSiteIdentityReader")[0]![0] as () => Promise<unknown>;
|
|
332
|
+
await expect(reader()).resolves.toEqual({
|
|
333
|
+
siteName: "Hub Co",
|
|
334
|
+
baseUrl: ORIGIN,
|
|
335
|
+
identity: HUB_IDENTITY,
|
|
336
|
+
});
|
|
337
|
+
expect(mockSiteConfigGet).toHaveBeenCalledTimes(1);
|
|
338
|
+
});
|
|
339
|
+
|
|
323
340
|
it.each([
|
|
324
341
|
["CONTENT_ADAPTER unset", () => delete process.env.CONTENT_ADAPTER],
|
|
325
342
|
["CONTENT_ADAPTER=database", () => (process.env.CONTENT_ADAPTER = "database")],
|
|
326
|
-
])("not hub-connected (no AILK_SPOKE_KEY, %s): registers no reader, and setSiteIdentity receives the file registration", (_label, arrange) => {
|
|
343
|
+
])("not hub-connected (no AILK_SPOKE_KEY, no API address, %s): registers no reader, and setSiteIdentity receives the file registration", (_label, arrange) => {
|
|
327
344
|
hubConnect();
|
|
328
345
|
delete process.env.AILK_SPOKE_KEY;
|
|
346
|
+
delete process.env.AILK_API_URL;
|
|
329
347
|
arrange();
|
|
330
348
|
load();
|
|
331
349
|
expect(calls("setSiteIdentityReader")).toEqual([]);
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment node
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The navigation record's translator (#12401, spec
|
|
7
|
+
* docs/specs/12401-a-site-renders-its-header-spec.md D2, D3; AC-2).
|
|
8
|
+
*
|
|
9
|
+
* The translator reads the docs base and the services base at module load,
|
|
10
|
+
* so each setting loads it afresh (`jest.isolateModules`). The fixture is
|
|
11
|
+
* parsed by the real `siteNavigationSchema`, so every case is a record the
|
|
12
|
+
* hub could send.
|
|
13
|
+
*/
|
|
14
|
+
import { siteNavigationSchema, type SiteNavigation } from "@working-theory/validation";
|
|
15
|
+
|
|
16
|
+
import type * as SiteNavigationModule from "../site-navigation";
|
|
17
|
+
|
|
18
|
+
const ENV = ["NEXT_PUBLIC_AILK_SERVICES_PATH", "NEXT_PUBLIC_AILK_DOCS_PATH", "NEXT_PUBLIC_AILK_ROUTE_PATHS"] as const;
|
|
19
|
+
const saved = new Map(ENV.map((k) => [k, process.env[k]]));
|
|
20
|
+
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
jest.restoreAllMocks();
|
|
23
|
+
for (const [k, v] of saved) {
|
|
24
|
+
if (v === undefined) delete process.env[k];
|
|
25
|
+
else process.env[k] = v;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
/** The translator, loaded with `env` set and, optionally, `pagePath` answering `pagePathAnswer`. */
|
|
30
|
+
function load(env: Partial<Record<(typeof ENV)[number], string>> = {}, pagePathAnswer?: string): typeof SiteNavigationModule {
|
|
31
|
+
for (const k of ENV) delete process.env[k];
|
|
32
|
+
Object.assign(process.env, env);
|
|
33
|
+
let mod: typeof SiteNavigationModule | undefined;
|
|
34
|
+
jest.isolateModules(() => {
|
|
35
|
+
if (pagePathAnswer === undefined) jest.dontMock("@working-theory/templates/routes");
|
|
36
|
+
else {
|
|
37
|
+
jest.doMock("@working-theory/templates/routes", () => ({
|
|
38
|
+
...jest.requireActual("@working-theory/templates/routes"),
|
|
39
|
+
pagePath: () => pagePathAnswer,
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
mod = jest.requireActual("../site-navigation");
|
|
43
|
+
});
|
|
44
|
+
return mod!;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const label = (text: string, fr?: string) => (fr === undefined ? { text } : { text, byLocale: { fr } });
|
|
48
|
+
const path = (p: string) => ({ kind: "path" as const, path: p });
|
|
49
|
+
const link = (text: string, target: object, extra: object = {}) => ({
|
|
50
|
+
kind: "link" as const,
|
|
51
|
+
label: label(text),
|
|
52
|
+
target,
|
|
53
|
+
...extra,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
/** One record carrying every shape the translator handles. */
|
|
57
|
+
const RECORD: SiteNavigation = siteNavigationSchema.parse({
|
|
58
|
+
version: "1",
|
|
59
|
+
header: {
|
|
60
|
+
items: [
|
|
61
|
+
{ kind: "link", label: label("Pricing", "Tarifs"), target: path("/pricing-plans") },
|
|
62
|
+
{
|
|
63
|
+
kind: "menu",
|
|
64
|
+
label: label("Services"),
|
|
65
|
+
groups: [
|
|
66
|
+
{
|
|
67
|
+
links: [
|
|
68
|
+
link("Audit", { kind: "page", address: { type: "Service", slug: "audit" } }, {
|
|
69
|
+
description: label("Find the gaps", "Trouver les écarts"),
|
|
70
|
+
}),
|
|
71
|
+
link("Start here", path("/docs/start")),
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
kind: "menu",
|
|
78
|
+
label: label("Resources"),
|
|
79
|
+
groups: [
|
|
80
|
+
{ heading: label("Read", "Lire"), links: [link("Same", { kind: "url", href: "https://example.com/a" })] },
|
|
81
|
+
{ links: [link("Same", path("/services/x"))] },
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
button: link("Book a call", path("/contact")),
|
|
86
|
+
signIn: "hidden",
|
|
87
|
+
},
|
|
88
|
+
footer: {
|
|
89
|
+
columns: [
|
|
90
|
+
{ heading: label("Company", "Société"), links: [link("About", path("/about"))] },
|
|
91
|
+
{ heading: label("Help"), links: [link("FAQ", path("/faq")), link("Status", { kind: "url", href: "https://status.example" })] },
|
|
92
|
+
],
|
|
93
|
+
bottomBar: { links: [link("Privacy", path("/privacy")), link("Terms", path("/terms"))] },
|
|
94
|
+
closing: { location: "Paris", buttons: [link("Call us", path("/meet"))] },
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe("navigationChrome (#12401 D2, AC-2)", () => {
|
|
99
|
+
it("translates the whole record for locale fr, in the record's order", () => {
|
|
100
|
+
const { navigationChrome } = load();
|
|
101
|
+
expect(navigationChrome(RECORD, "fr")).toEqual({
|
|
102
|
+
navItems: [
|
|
103
|
+
{ labelKey: "rec.h0", path: "/pricing-plans" },
|
|
104
|
+
{
|
|
105
|
+
labelKey: "rec.h1",
|
|
106
|
+
flyout: {
|
|
107
|
+
features: [
|
|
108
|
+
{ labelKey: "rec.h1.g0.l0", path: "/services/audit", descKey: "rec.h1.g0.l0.d" },
|
|
109
|
+
{ labelKey: "rec.h1.g0.l1", path: "/docs/start" },
|
|
110
|
+
],
|
|
111
|
+
presentation: "grid",
|
|
112
|
+
width: "panel",
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
labelKey: "rec.h2",
|
|
117
|
+
flyout: {
|
|
118
|
+
features: [
|
|
119
|
+
{ labelKey: "rec.h2.g0.l0", path: "https://example.com/a" },
|
|
120
|
+
{ labelKey: "rec.h2.g1.l0", path: "/services/x" },
|
|
121
|
+
],
|
|
122
|
+
groups: [
|
|
123
|
+
{ headingKey: "rec.h2.g0", items: [{ labelKey: "rec.h2.g0.l0", path: "https://example.com/a" }] },
|
|
124
|
+
{ headingKey: "rec.h2.g1", items: [{ labelKey: "rec.h2.g1.l0", path: "/services/x" }] },
|
|
125
|
+
],
|
|
126
|
+
width: "panel",
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
columns: [
|
|
131
|
+
{
|
|
132
|
+
heading: "Société",
|
|
133
|
+
headingKey: "rec.f0",
|
|
134
|
+
items: [{ labelKey: "rec.f0.l0", path: "/about", label: "About" }],
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
heading: "Help",
|
|
138
|
+
headingKey: "rec.f1",
|
|
139
|
+
items: [
|
|
140
|
+
{ labelKey: "rec.f1.l0", path: "/faq", label: "FAQ" },
|
|
141
|
+
{ labelKey: "rec.f1.l1", path: "https://status.example", label: "Status" },
|
|
142
|
+
],
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
labels: {
|
|
146
|
+
"rec.h0": "Tarifs",
|
|
147
|
+
"rec.h1": "Services",
|
|
148
|
+
"rec.h1.g0.l0": "Audit",
|
|
149
|
+
"rec.h1.g0.l0.d": "Trouver les écarts",
|
|
150
|
+
"rec.h1.g0.l1": "Start here",
|
|
151
|
+
"rec.h2": "Resources",
|
|
152
|
+
"rec.h2.g0": "Lire",
|
|
153
|
+
"rec.h2.g0.l0": "Same",
|
|
154
|
+
"rec.h2.g1": "",
|
|
155
|
+
"rec.h2.g1.l0": "Same",
|
|
156
|
+
"rec.f0": "Société",
|
|
157
|
+
"rec.f0.l0": "About",
|
|
158
|
+
"rec.f1": "Help",
|
|
159
|
+
"rec.f1.l0": "FAQ",
|
|
160
|
+
"rec.f1.l1": "Status",
|
|
161
|
+
},
|
|
162
|
+
button: { label: "Book a call", href: "/contact" },
|
|
163
|
+
signIn: "hidden",
|
|
164
|
+
legalLinks: [
|
|
165
|
+
{ label: "Privacy", href: "/privacy" },
|
|
166
|
+
{ label: "Terms", href: "/terms" },
|
|
167
|
+
],
|
|
168
|
+
closing: { locality: "Paris", actions: [{ label: "Call us", href: "/meet" }] },
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("answers the default text for a locale the record has none for, and matches a locale case-insensitively", () => {
|
|
173
|
+
const { navigationChrome } = load();
|
|
174
|
+
expect(navigationChrome(RECORD, "de").labels["rec.h0"]).toBe("Pricing");
|
|
175
|
+
const record = siteNavigationSchema.parse({
|
|
176
|
+
...RECORD,
|
|
177
|
+
header: { items: [{ kind: "link", label: { text: "Plans", byLocale: { "pt-BR": "Planos" } }, target: path("/p") }] },
|
|
178
|
+
});
|
|
179
|
+
expect(navigationChrome(record, "pt-br").labels["rec.h0"]).toBe("Planos");
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("an ungrouped menu with no description is a list at the trigger's width", () => {
|
|
183
|
+
const { navigationChrome } = load();
|
|
184
|
+
const record = siteNavigationSchema.parse({
|
|
185
|
+
version: "1",
|
|
186
|
+
header: { items: [{ kind: "menu", label: label("More"), groups: [{ links: [link("A", path("/a"))] }] }] },
|
|
187
|
+
footer: { columns: [] },
|
|
188
|
+
});
|
|
189
|
+
expect(navigationChrome(record, "en").navItems[0]!.flyout).toEqual({
|
|
190
|
+
features: [{ labelKey: "rec.h0.g0.l0", path: "/a" }],
|
|
191
|
+
presentation: "list",
|
|
192
|
+
width: "trigger",
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it("every key contains a dot, and two links with the same label get two keys", () => {
|
|
197
|
+
const { navigationChrome } = load();
|
|
198
|
+
const { labels, navItems } = navigationChrome(RECORD, "en");
|
|
199
|
+
expect(Object.keys(labels).every((key) => key.includes("."))).toBe(true);
|
|
200
|
+
const same = navItems[2]!.flyout!.features.map((feature) => feature.labelKey);
|
|
201
|
+
expect(same).toEqual(["rec.h2.g0.l0", "rec.h2.g1.l0"]);
|
|
202
|
+
expect(labels[same[0]!]).toBe("Same");
|
|
203
|
+
expect(labels[same[1]!]).toBe("Same");
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("a record with no button, no Sign in, no bottom bar and no closing footer gives none of them", () => {
|
|
207
|
+
const { navigationChrome } = load();
|
|
208
|
+
const record = siteNavigationSchema.parse({ version: "1", header: { items: [] }, footer: { columns: [] } });
|
|
209
|
+
expect(navigationChrome(record, "en")).toEqual({
|
|
210
|
+
navItems: [],
|
|
211
|
+
columns: [],
|
|
212
|
+
labels: {},
|
|
213
|
+
legalLinks: [],
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
describe("navigationChrome — a target's address (#12401 D2, AC-2)", () => {
|
|
219
|
+
const recordOf = (target: object) =>
|
|
220
|
+
siteNavigationSchema.parse({
|
|
221
|
+
version: "1",
|
|
222
|
+
header: { items: [{ kind: "link", label: label("X"), target }] },
|
|
223
|
+
footer: { columns: [] },
|
|
224
|
+
});
|
|
225
|
+
const addressOf = (mod: typeof SiteNavigationModule, target: object) =>
|
|
226
|
+
mod.navigationChrome(recordOf(target), "en").navItems[0]!.path;
|
|
227
|
+
|
|
228
|
+
it("a Service page goes to the services base", () => {
|
|
229
|
+
const mod = load({ NEXT_PUBLIC_AILK_SERVICES_PATH: "/capabilities" });
|
|
230
|
+
expect(addressOf(mod, { kind: "page", address: { type: "Service", slug: "audit" } })).toBe("/capabilities/audit");
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it("a page at /docs goes to the docs path", () => {
|
|
234
|
+
const mod = load({ NEXT_PUBLIC_AILK_DOCS_PATH: "/help" }, "/docs/getting-started");
|
|
235
|
+
expect(addressOf(mod, { kind: "page", address: { type: "AboutPage", slug: "about" } })).toBe("/help/getting-started");
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it("a page of a renamed family goes to its served segment", () => {
|
|
239
|
+
const mod = load({ NEXT_PUBLIC_AILK_ROUTE_PATHS: '{"portfolio":"writing-samples"}' });
|
|
240
|
+
expect(addressOf(mod, { kind: "page", address: { type: "PortfolioItem", slug: "one" } })).toBe("/writing-samples/one");
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it.each(["/docs/start", "/services/x", "/portfolio/one"])("a path target %s comes back as stored, under every setting", (stored) => {
|
|
244
|
+
const mod = load({
|
|
245
|
+
NEXT_PUBLIC_AILK_SERVICES_PATH: "/capabilities",
|
|
246
|
+
NEXT_PUBLIC_AILK_DOCS_PATH: "/help",
|
|
247
|
+
NEXT_PUBLIC_AILK_ROUTE_PATHS: '{"portfolio":"writing-samples"}',
|
|
248
|
+
});
|
|
249
|
+
expect(addressOf(mod, path(stored))).toBe(stored);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
it("a url target comes back as stored, with no locale prefix added to any address", () => {
|
|
253
|
+
const mod = load();
|
|
254
|
+
expect(addressOf(mod, { kind: "url", href: "https://example.com/x?y=1" })).toBe("https://example.com/x?y=1");
|
|
255
|
+
expect(mod.navigationChrome(RECORD, "fr").navItems[0]!.path).toBe("/pricing-plans");
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
describe("every emitted address is checked (#12401 D2, D3, AC-2)", () => {
|
|
260
|
+
const pageRecord = siteNavigationSchema.parse({
|
|
261
|
+
version: "1",
|
|
262
|
+
header: { items: [] },
|
|
263
|
+
footer: {
|
|
264
|
+
columns: [],
|
|
265
|
+
bottomBar: { links: [link("Legal", { kind: "page", address: { type: "AboutPage", slug: "about" } })] },
|
|
266
|
+
},
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it.each(["//x", "/\\x", "/a b", "/a\\b", "https://user:pw@host.example", "javascript:alert(1)", "relative"])(
|
|
270
|
+
"with pagePath answering %s, navigationChrome throws and safeNavigationChrome answers null with one warning",
|
|
271
|
+
(answer) => {
|
|
272
|
+
const warn = jest.spyOn(console, "warn").mockImplementation(() => undefined);
|
|
273
|
+
const mod = load({}, answer);
|
|
274
|
+
expect(() => mod.navigationChrome(pageRecord, "en")).toThrow();
|
|
275
|
+
expect(mod.safeNavigationChrome(pageRecord, "en")).toBeNull();
|
|
276
|
+
expect(warn).toHaveBeenCalledTimes(1);
|
|
277
|
+
expect(String(warn.mock.calls[0]![0])).toBe("[site-navigation] record not rendered (TypeError)");
|
|
278
|
+
expect(String(warn.mock.calls[0]![0])).not.toContain(answer);
|
|
279
|
+
},
|
|
280
|
+
);
|
|
281
|
+
|
|
282
|
+
it("safeNavigationChrome answers the translation for a record it can render, with no warning", () => {
|
|
283
|
+
const warn = jest.spyOn(console, "warn").mockImplementation(() => undefined);
|
|
284
|
+
const mod = load();
|
|
285
|
+
expect(mod.safeNavigationChrome(RECORD, "en")).toEqual(mod.navigationChrome(RECORD, "en"));
|
|
286
|
+
expect(warn).not.toHaveBeenCalled();
|
|
287
|
+
});
|
|
288
|
+
});
|