@griddo/ax 12.15.0-astro-rc.0 → 12.15.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.
Files changed (28) hide show
  1. package/package.json +4 -4
  2. package/src/__tests__/components/Fields/Wysiwyg/Wysiwyg.caption.test.tsx +328 -39
  3. package/src/__tests__/components/Fields/Wysiwyg/Wysiwyg.test.tsx +1 -0
  4. package/src/__tests__/modules/GlobalSettings/Llms/Llms.uc.test.tsx +2861 -0
  5. package/src/api/domains.tsx +98 -2
  6. package/src/components/Fields/Wysiwyg/helpers.tsx +188 -0
  7. package/src/components/Fields/Wysiwyg/index.tsx +75 -39
  8. package/src/components/Fields/Wysiwyg/style.tsx +5 -0
  9. package/src/modules/GlobalSettings/Llms/AutomaticSelection/index.tsx +317 -0
  10. package/src/modules/GlobalSettings/Llms/DomainList/index.tsx +65 -0
  11. package/src/modules/GlobalSettings/Llms/IndexModelEditor/index.tsx +325 -0
  12. package/src/modules/GlobalSettings/Llms/MirrorExample/index.tsx +61 -0
  13. package/src/modules/GlobalSettings/Llms/MirrorOptions/index.tsx +82 -0
  14. package/src/modules/GlobalSettings/Llms/Outline/index.tsx +183 -0
  15. package/src/modules/GlobalSettings/Llms/PagePicker/index.tsx +105 -0
  16. package/src/modules/GlobalSettings/Llms/Preview/index.tsx +65 -0
  17. package/src/modules/GlobalSettings/Llms/ResolvedPages/index.tsx +191 -0
  18. package/src/modules/GlobalSettings/Llms/SectionEditor/index.tsx +262 -0
  19. package/src/modules/GlobalSettings/Llms/atoms.tsx +37 -0
  20. package/src/modules/GlobalSettings/Llms/index.tsx +383 -0
  21. package/src/modules/GlobalSettings/Llms/style.tsx +541 -0
  22. package/src/modules/GlobalSettings/Llms/utils.tsx +307 -0
  23. package/src/modules/GlobalSettings/index.tsx +7 -0
  24. package/src/routes/multisite.tsx +8 -1
  25. package/src/schemas/pages/GlobalPage.ts +2 -2
  26. package/src/schemas/pages/Page.ts +2 -2
  27. package/src/types/index.tsx +80 -12
  28. package/src/types/llms.tsx +315 -0
@@ -0,0 +1,2861 @@
1
+ import { Router } from "react-router-dom";
2
+
3
+ import { SET_GLOBAL_LANGUAGES } from "@ax/containers/App/constants";
4
+ import { appReducer, type IAppState } from "@ax/containers/App/reducer";
5
+ import { parseTheme } from "@ax/helpers";
6
+ import PrivateRoute from "@ax/modules/App/Routing/PrivateRoute";
7
+ import GlobalSettings from "@ax/modules/GlobalSettings";
8
+ import Llms from "@ax/modules/GlobalSettings/Llms";
9
+ import history from "@ax/routes/history";
10
+ import routes from "@ax/routes/multisite";
11
+ import globalTheme from "@ax/themes/theme.json";
12
+ import type {
13
+ ILanguage,
14
+ IUser,
15
+ LlmsAutomaticSection,
16
+ LlmsDomain,
17
+ LlmsDomainPage,
18
+ LlmsIndexResolved,
19
+ LlmsIndexSectionResolved,
20
+ LlmsIndexSite,
21
+ LlmsManualSection,
22
+ LlmsSectionFilter,
23
+ LlmsSectionPagesQuery,
24
+ LlmsSettings,
25
+ } from "@ax/types";
26
+
27
+ import axios from "axios";
28
+ import { applyMiddleware, combineReducers, createStore, type Reducer } from "redux";
29
+ import thunk from "redux-thunk";
30
+ import { ThemeProvider } from "styled-components";
31
+ import type { MockedFunction } from "vitest";
32
+
33
+ import { act, cleanup, fireEvent, render, screen, waitFor, within } from "../../../../../config/tests/test-utils";
34
+
35
+ /**
36
+ * The LLM surface settings screen end to end: the real screen on a real store,
37
+ * with only axios mocked. The mock answers by URL instead of as a queue because
38
+ * the screen fires several requests of its own —the domains, the settings of
39
+ * each one, the chosen pages by id, the page search, the slices of the lists and
40
+ * the resolution of the preview—, and the assertions read what the screen shows
41
+ * and the documents it sends, which is what the acceptance criteria claim.
42
+ */
43
+ vi.mock("axios");
44
+ const mockedAxios = axios as MockedFunction<typeof axios>;
45
+
46
+ // The Templates the Instance declares, which the Template filter offers by their
47
+ // display name. The global mock also carries a `default` entry that is no template.
48
+ vi.mock("components", async (importOriginal) => {
49
+ const actual = (await importOriginal()) as any;
50
+ const source = actual.config ? actual : actual.default;
51
+ const { default: _notATemplate, ...templates } = source.config.schemas.ui.templates;
52
+
53
+ return {
54
+ ...source,
55
+ config: {
56
+ ...source.config,
57
+ schemas: {
58
+ ...source.config.schemas,
59
+ ui: {
60
+ ...source.config.schemas.ui,
61
+ templates: {
62
+ ...templates,
63
+ ProgramDetail: { component: "ProgramDetail", displayName: "Program detail" },
64
+ NewsDetail: { component: "NewsDetail", displayName: "News detail" },
65
+ },
66
+ },
67
+ },
68
+ },
69
+ };
70
+ });
71
+
72
+ const PERMISSION = "global.seoAnalytics.editSeoAnalyticsInGlobalPages";
73
+ /** A global permission that is not this one: the user without it is not a user without any. */
74
+ const OTHER_PERMISSION = "global.usersRoles.accessToUsersRoles";
75
+
76
+ /** The Languages of the Instance: English and Spanish, and French, which no site of the domain is served in. */
77
+ const LANGUAGES: ILanguage[] = [
78
+ { id: 1, locale: "en_GB", label: "English", language: "en", isDefault: true },
79
+ { id: 2, locale: "es_ES", label: "Español", language: "es", isDefault: false },
80
+ { id: 3, locale: "fr_FR", label: "Français", language: "fr", isDefault: false },
81
+ ];
82
+
83
+ const DOMAIN: LlmsDomain = { id: 7, name: "www.example.edu", url: "https://www.example.edu" };
84
+ const OTHER_DOMAIN: LlmsDomain = { id: 8, name: "postgrado.example.edu", url: "https://postgrado.example.edu" };
85
+
86
+ /**
87
+ * Options other than Griddo's defaults, so a document that loses them shows. The images
88
+ * and the absolute links are the values the screen always sends: it does not show them.
89
+ */
90
+ const MIRROR: LlmsSettings["markdown"] = {
91
+ enabled: true,
92
+ images: "dedupe",
93
+ includeNav: true,
94
+ linkToMarkdown: false,
95
+ absoluteLinks: true,
96
+ frontMatter: false,
97
+ discoveryLinks: true,
98
+ mainOnly: false,
99
+ };
100
+
101
+ const manual = (name: string, pages: number[] = []): LlmsManualSection => ({
102
+ type: "manual",
103
+ name,
104
+ pages,
105
+ });
106
+
107
+ /** An automatic Optional Section, which carries no name, with the values a new one starts with unless told otherwise. */
108
+ const optionalAutomatic = (selection: Partial<Omit<LlmsAutomaticSection, "type" | "name">> = {}) => {
109
+ const { name: _name, ...optional } = automatic("Optional", selection);
110
+ return optional;
111
+ };
112
+
113
+ /** An automatic section with the values a new one starts with, unless told otherwise. */
114
+ const automatic = (
115
+ name: string,
116
+ selection: Partial<Omit<LlmsAutomaticSection, "type" | "name">> = {},
117
+ ): LlmsAutomaticSection => ({
118
+ type: "automatic",
119
+ name,
120
+ filters: [],
121
+ globalOperator: "AND",
122
+ order: "recent",
123
+ orderDirection: "DESC",
124
+ quantity: null,
125
+ ...selection,
126
+ });
127
+
128
+ const makeSettings = (
129
+ index: Partial<LlmsSettings["index"]> = {},
130
+ markdown: Partial<LlmsSettings["markdown"]> = {},
131
+ ): LlmsSettings => ({
132
+ index: {
133
+ enabled: true,
134
+ texts: {},
135
+ includeGeneratedAt: false,
136
+ sections: [],
137
+ optionalSection: { type: "manual", pages: [] },
138
+ footer: {},
139
+ ...index,
140
+ },
141
+ markdown: { ...MIRROR, ...markdown },
142
+ });
143
+
144
+ const makePage = (id: number, overrides: Partial<LlmsDomainPage> = {}): LlmsDomainPage => ({
145
+ id,
146
+ title: `Page ${id}`,
147
+ url: `https://www.example.edu/page-${id}/`,
148
+ site: { id: 3, name: "Degrees" },
149
+ language: { id: 1, locale: "en_GB" },
150
+ eligible: true,
151
+ reasons: [],
152
+ ...overrides,
153
+ });
154
+
155
+ const indexPage = (id: number) => ({
156
+ id,
157
+ title: `Page ${id}`,
158
+ link: `https://www.example.edu/page-${id}/index.md`,
159
+ description: null,
160
+ });
161
+
162
+ const resolvedIndex = (sections: LlmsIndexSectionResolved[], content = "# Example\n"): LlmsIndexResolved => ({
163
+ text: { title: "Example", summary: null, detail: null, generatedAt: null },
164
+ sections,
165
+ content,
166
+ });
167
+
168
+ /** The whole numbers from `first` to `last`, both included. */
169
+ const range = (first: number, last: number) => Array.from({ length: last - first + 1 }, (_, index) => first + index);
170
+
171
+ /**
172
+ * The sites that count for the domain, as a resolution gives them: Degrees in English
173
+ * and Spanish, Research only in English, and Masters only in Spanish.
174
+ */
175
+ const SITES: LlmsIndexSite[] = [
176
+ {
177
+ id: 3,
178
+ name: "Degrees",
179
+ languages: [
180
+ { id: 1, locale: "en_GB" },
181
+ { id: 2, locale: "es_ES" },
182
+ ],
183
+ },
184
+ { id: 4, name: "Research", languages: [{ id: 1, locale: "en_GB" }] },
185
+ { id: 5, name: "Masters", languages: [{ id: 2, locale: "es_ES" }] },
186
+ ];
187
+
188
+ interface IApi {
189
+ domains?: LlmsDomain[];
190
+ /** The settings of the domain 7. */
191
+ settings?: LlmsSettings;
192
+ /** The settings of each domain by its id, when there are several. */
193
+ settingsOf?: Record<number, LlmsSettings>;
194
+ /** How many times reading the settings of a domain fails before it answers. */
195
+ failures?: Record<number, number>;
196
+ /** The domains whose settings never arrive. */
197
+ pending?: number[];
198
+ /** The domains whose settings fail to save. */
199
+ saveFailures?: number[];
200
+ /** The pages the list gives when asked by id; any other id is one it does not give. */
201
+ known?: LlmsDomainPage[];
202
+ /** What the list gives to the page search. */
203
+ search?: LlmsDomainPage[];
204
+ /** The list fails when asked for the chosen Pages by id. */
205
+ pagesByIdFail?: boolean;
206
+ /** The list fails when the search asks for the Domain's Pages. */
207
+ searchFails?: boolean;
208
+ /** The answer to a resolution, from the settings it was asked with. */
209
+ resolve?(settings: LlmsSettings): ReturnType<typeof ok> | Promise<ReturnType<typeof ok>>;
210
+ /** The answer to a slice of what a section takes, from what it was asked with. */
211
+ sectionPages?(asked: LlmsSectionPagesQuery): ReturnType<typeof ok> | Promise<ReturnType<typeof ok>>;
212
+ }
213
+
214
+ interface IRequest {
215
+ url: string;
216
+ method: string;
217
+ data?: unknown;
218
+ }
219
+
220
+ /** `structuredClone`: the screen must never share an object with the fixtures. */
221
+ const ok = (data: unknown) => ({
222
+ status: 200,
223
+ data: structuredClone(data),
224
+ statusText: "OK",
225
+ headers: {},
226
+ config: {} as never,
227
+ });
228
+
229
+ const failure = (status: number) => ({
230
+ status,
231
+ data: { code: status, message: "The server could not do it" },
232
+ statusText: "Error",
233
+ headers: {},
234
+ config: {} as never,
235
+ });
236
+
237
+ const serveApi = (api: IApi = {}) => {
238
+ const failures = { ...api.failures };
239
+
240
+ mockedAxios.mockImplementation((async (config: IRequest) => {
241
+ const [path, query = ""] = config.url.split("?");
242
+ const params = new URLSearchParams(query);
243
+ const method = config.method.toUpperCase();
244
+
245
+ if (method === "GET" && /\/domains$/.test(path)) return ok(api.domains ?? [DOMAIN]);
246
+ const settingsOf = path.match(/\/domains\/(\d+)\/llms-settings$/);
247
+ if (settingsOf) {
248
+ const id = Number(settingsOf[1]);
249
+ if (method === "PUT") return api.saveFailures?.includes(id) ? failure(400) : ok(config.data);
250
+ if (api.pending?.includes(id)) return new Promise(() => {});
251
+ if ((failures[id] ?? 0) > 0) {
252
+ failures[id]--;
253
+ return failure(500);
254
+ }
255
+ return ok(api.settingsOf?.[id] ?? (id === DOMAIN.id ? api.settings : undefined) ?? makeSettings());
256
+ }
257
+ if (method === "GET" && /\/domains\/\d+\/llms-pages$/.test(path)) {
258
+ const ids = params.get("ids");
259
+ if (ids ? api.pagesByIdFail : api.searchFails) return failure(500);
260
+ const items = ids
261
+ ? (api.known ?? []).filter((page) => ids.split(",").map(Number).includes(page.id))
262
+ : (api.search ?? []);
263
+ return ok({ totalItems: items.length, items });
264
+ }
265
+ if (method === "POST" && /\/domains\/\d+\/llms-index$/.test(path)) {
266
+ const sent = config.data as LlmsSettings;
267
+ // Like the API: a domain that does not publish its LLM Index gets none.
268
+ return api.resolve ? api.resolve(sent) : ok({ enabled: sent.index.enabled, index: null, sites: SITES });
269
+ }
270
+ if (method === "POST" && /\/domains\/\d+\/llms-section-pages$/.test(path)) {
271
+ const asked = config.data as LlmsSectionPagesQuery;
272
+ // Like the API: a domain that does not publish its LLM Index gets no pages.
273
+ return api.sectionPages
274
+ ? api.sectionPages(asked)
275
+ : ok({ enabled: asked.settings.index.enabled, pages: null, sites: SITES });
276
+ }
277
+
278
+ return failure(404);
279
+ }) as never);
280
+ };
281
+
282
+ /** A slice of what a section takes, as the API gives it: its Pages, and how many the section takes in all. */
283
+ const sectionSlice = (pageIds: number[], totalItems = pageIds.length) =>
284
+ ok({ enabled: true, pages: { totalItems, items: pageIds.map(indexPage) }, sites: SITES });
285
+
286
+ /** A section that takes `total` Pages, numbered from 1, answered in the slices the screen asks for. */
287
+ const takes = (total: number) => (asked: LlmsSectionPagesQuery) => {
288
+ const size = asked.itemsPerPage ?? 50;
289
+ const first = ((asked.page ?? 1) - 1) * size + 1;
290
+
291
+ return sectionSlice(range(first, Math.min(total, first + size - 1)), total);
292
+ };
293
+
294
+ const requests = (method: string, pattern: RegExp): IRequest[] =>
295
+ mockedAxios.mock.calls
296
+ .map(([config]) => config as unknown as IRequest)
297
+ .filter((config) => config.method.toUpperCase() === method && pattern.test(config.url.split("?")[0]));
298
+
299
+ const puts = () => requests("PUT", /\/domains\/7\/llms-settings$/);
300
+
301
+ /** The documents sent to each domain, by its id. */
302
+ const putsTo = (id: number): LlmsSettings[] =>
303
+ requests("PUT", new RegExp(`/domains/${id}/llms-settings$`)).map((request) => request.data as LlmsSettings);
304
+
305
+ const resolutions = () => requests("POST", /\/domains\/7\/llms-index$/);
306
+
307
+ /** The settings the last resolution was asked with. */
308
+ const lastResolved = (): LlmsSettings => resolutions().at(-1)?.data as LlmsSettings;
309
+
310
+ /** The slices of what a section takes that the screen asked for. */
311
+ const listings = () => requests("POST", /\/domains\/7\/llms-section-pages$/);
312
+
313
+ /** What the last slice was asked with: the settings, the section and the slice. */
314
+ const lastListed = (): LlmsSectionPagesQuery => listings().at(-1)?.data as LlmsSectionPagesQuery;
315
+
316
+ const makeStore = (permissions: string[] = [PERMISSION]) => {
317
+ const users = {
318
+ currentUser: { id: 1, isSuperAdmin: false, roles: [] },
319
+ currentPermissions: permissions,
320
+ globalPermissions: permissions,
321
+ roles: [],
322
+ };
323
+ const store = createStore(
324
+ combineReducers({
325
+ app: appReducer as Reducer<IAppState>,
326
+ users: (() => users) as Reducer<typeof users>,
327
+ }),
328
+ applyMiddleware(thunk),
329
+ );
330
+ // The raw action and not `appActions.setGlobalLanguages`: entering the graph
331
+ // through the `@ax/containers/App` barrel trips an import cycle
332
+ // (docs/IMPORT-CYCLES.md) that leaves `appActions` undefined at load time.
333
+ store.dispatch({ type: SET_GLOBAL_LANGUAGES, payload: { globalLangs: LANGUAGES } });
334
+
335
+ return store;
336
+ };
337
+
338
+ const navItems = [
339
+ { title: "Robots.txt Editor", path: "/settings/robots", component: () => null, permission: PERMISSION },
340
+ { title: "LLMs.txt Editor", path: "/settings/llms", component: () => null, permission: PERMISSION },
341
+ ];
342
+
343
+ const theme = parseTheme(globalTheme);
344
+
345
+ /** The store of the screen last rendered, to read what it reported. */
346
+ let store: ReturnType<typeof makeStore>;
347
+
348
+ /** Renders the screen and waits for every domain of the list to have its settings, or to say it has none. */
349
+ const renderList = async (api: IApi = {}) => {
350
+ serveApi(api);
351
+ store = makeStore();
352
+ await act(async () => {
353
+ render(
354
+ <Router history={history}>
355
+ <ThemeProvider theme={theme}>
356
+ <Llms navItems={navItems} currentNavItem={navItems[1]} />
357
+ </ThemeProvider>
358
+ </Router>,
359
+ { store },
360
+ );
361
+ });
362
+ await waitFor(() => {
363
+ expect(screen.getAllByTestId("llms-domain")).toHaveLength((api.domains ?? [DOMAIN]).length);
364
+ expect(screen.queryAllByText("Loading its settings…")).toHaveLength(api.pending?.length ?? 0);
365
+ });
366
+ };
367
+
368
+ const domainRow = (name: string) => {
369
+ const row = screen.getAllByTestId("llms-domain").find((item) => within(item).queryByText(name));
370
+ if (!row) throw new Error(`No domain of the list reads «${name}»`);
371
+ return row;
372
+ };
373
+
374
+ const click = async (element: HTMLElement) => {
375
+ await act(async () => {
376
+ fireEvent.click(element);
377
+ });
378
+ };
379
+
380
+ const openDomain = async (name = DOMAIN.name as string) => {
381
+ await click(domainRow(name));
382
+ await screen.findByText("LLM index");
383
+ };
384
+
385
+ const renderScreen = async (api: IApi = {}) => {
386
+ await renderList(api);
387
+ await openDomain();
388
+ };
389
+
390
+ const field = (name: string): HTMLInputElement => {
391
+ const element = document.querySelector<HTMLInputElement>(`[name="${name}"]`);
392
+ if (!element) throw new Error(`There is no field named ${name}`);
393
+ return element;
394
+ };
395
+
396
+ /** Types into a TextField or a TextArea and waits out their 300 ms debounce. */
397
+ const write = async (element: HTMLElement, value: string) => {
398
+ fireEvent.change(element, { target: { value } });
399
+ await act(async () => {
400
+ await new Promise((resolve) => setTimeout(resolve, 350));
401
+ });
402
+ };
403
+
404
+ /** Waits out the delay with which the lists of what a section takes are asked again. */
405
+ const settle = async () => {
406
+ await act(async () => {
407
+ await new Promise((resolve) => setTimeout(resolve, 350));
408
+ });
409
+ };
410
+
411
+ const toggle = (name: string) => click(field(name));
412
+
413
+ const chooseRadio = (name: string, value: string) => {
414
+ const radio = document.querySelector<HTMLElement>(`[name="${name}"][value="${value}"]`);
415
+ if (!radio) throw new Error(`There is no ${value} option in ${name}`);
416
+ return click(radio);
417
+ };
418
+
419
+ /** Opens one of the screen's selects and picks the option that reads so. */
420
+ const choose = async (name: string, label: string) => {
421
+ const select = document
422
+ .querySelector(`input[name="${name}"]`)
423
+ ?.closest<HTMLElement>('[data-testid="select-component"]');
424
+ if (!select) throw new Error(`There is no select named ${name}`);
425
+ await act(async () => {
426
+ fireEvent.keyDown(select.querySelector(".react-select__control") as HTMLElement, { key: "ArrowDown" });
427
+ });
428
+ await click(within(select).getByText(label, { selector: ".react-select__option" }));
429
+ };
430
+
431
+ /** Saves and returns the document the screen sent. */
432
+ const save = async (): Promise<LlmsSettings> => {
433
+ const before = puts().length;
434
+ await click(screen.getByRole("button", { name: "Save" }));
435
+ await waitFor(() => expect(puts()).toHaveLength(before + 1));
436
+
437
+ return puts()[before].data as LlmsSettings;
438
+ };
439
+
440
+ const outline = () => screen.getByRole("navigation", { name: "Index outline" });
441
+
442
+ /** Opens the preview from the eye in the corner of the outline. */
443
+ const openPreview = () => click(within(outline()).getByTestId("icon-action-view"));
444
+
445
+ /** The modal the preview opens in. */
446
+ const previewModal = () => screen.getByTestId("modal-component");
447
+
448
+ const outlineSections = () => screen.getAllByTestId("llms-outline-section");
449
+
450
+ const outlineSection = (title: string) => {
451
+ const item = outlineSections().find((section) => within(section).queryByText(title));
452
+ if (!item) throw new Error(`No section of the outline reads «${title}»`);
453
+ return item;
454
+ };
455
+
456
+ /** Opens an element of the outline beside it; the only button of an element is the one that opens it. */
457
+ const openItem = (item: HTMLElement) => click(item.querySelector("button") as HTMLElement);
458
+
459
+ const openSection = (title: string) => openItem(outlineSection(title));
460
+
461
+ const openOptional = () => openItem(screen.getByTestId("llms-outline-optional"));
462
+
463
+ /** The Optional Section open beside the outline. */
464
+ const optionalPanel = () => screen.getByRole("region", { name: "Optional section" });
465
+
466
+ const openHeader = () => openItem(screen.getByTestId("llms-outline-header"));
467
+
468
+ /**
469
+ * Drags a sortable row —an outline section or a chosen page— one place up with the
470
+ * keyboard, as its handle allows: pick up, move, drop. jsdom lays nothing out, and the
471
+ * drag needs to know where each row is to tell which one it is dropped on, so the rows of
472
+ * its list are stacked as the screen shows them.
473
+ */
474
+ const dragUp = async (item: HTMLElement) => {
475
+ const rows = item.getAttribute("data-testid") ?? "";
476
+ const layout = Element.prototype.getBoundingClientRect;
477
+ vi.spyOn(Element.prototype, "getBoundingClientRect").mockImplementation(function (this: Element) {
478
+ const position = screen.queryAllByTestId(rows).indexOf(this as HTMLElement);
479
+ if (position < 0) return layout.call(this);
480
+ const top = position * 60;
481
+ return { x: 0, y: top, top, left: 0, right: 320, bottom: top + 56, width: 320, height: 56 } as DOMRect;
482
+ });
483
+ const handle = within(item).getByLabelText(/^Reorder /);
484
+ await act(async () => {
485
+ fireEvent.keyDown(handle, { code: "Space", key: " " });
486
+ });
487
+ await act(async () => {
488
+ await new Promise((resolve) => setTimeout(resolve, 0));
489
+ });
490
+ await act(async () => {
491
+ fireEvent.keyDown(handle, { code: "ArrowUp", key: "ArrowUp" });
492
+ });
493
+ await act(async () => {
494
+ fireEvent.keyDown(handle, { code: "Space", key: " " });
495
+ });
496
+ };
497
+
498
+ /** A Page title too long for its row. */
499
+ const LONG_TITLE = "Bachelor's Degree in Business Administration and Management with a Minor in Data Analytics";
500
+
501
+ /**
502
+ * Lays the titles out as if each row fitted 200 px of text, at 8 px a character: jsdom lays
503
+ * nothing out, so without this every title fits. «Page 2» fits; `LONG_TITLE` does not.
504
+ */
505
+ const layOutTitles = () => {
506
+ vi.spyOn(Element.prototype, "clientWidth", "get").mockReturnValue(200);
507
+ vi.spyOn(Element.prototype, "scrollWidth", "get").mockImplementation(function (this: Element) {
508
+ return (this.textContent?.length ?? 0) * 8;
509
+ });
510
+ };
511
+
512
+ /** A row of the page search. */
513
+ const pickerRow = (title: string) => {
514
+ const row = screen.getAllByTestId("llms-picker-page").find((item) => within(item).queryByText(title));
515
+ if (!row) throw new Error(`No page of the search reads «${title}»`);
516
+ return row;
517
+ };
518
+
519
+ /** The section open beside the outline. */
520
+ const inspector = () => screen.getByTestId("llms-section");
521
+
522
+ const pageRow = (title: string) => {
523
+ const row = screen.getAllByTestId("llms-section-page").find((item) => within(item).queryByText(title));
524
+ if (!row) throw new Error(`No chosen page reads «${title}»`);
525
+ return row;
526
+ };
527
+
528
+ const filterRow = (axis: LlmsSectionFilter["axis"]) => screen.getByTestId(`llms-filter-${axis}`);
529
+
530
+ /** Opens the menu of the «Add filter» button and returns it. */
531
+ const openAddFilter = async () => {
532
+ const menu = screen.getByRole("button", { name: "Add filter" }).closest<HTMLElement>('[data-testid="floating-menu"]');
533
+ if (!menu) throw new Error("There is no «Add filter» menu");
534
+ await click(within(menu).getByRole("button", { name: "Add filter" }));
535
+ return within(menu).getByTestId("floating-menu-wrapper");
536
+ };
537
+
538
+ const addFilter = async (axis: "Template" | "Site" | "Language") =>
539
+ click(within(await openAddFilter()).getByText(axis));
540
+
541
+ /** Opens the menu of values of the Site or the Language filter and returns it. */
542
+ const openValues = async (axis: "site" | "language") => {
543
+ await click(within(filterRow(axis)).getByTestId("icon-action-add"));
544
+ return within(filterRow(axis)).getByTestId("floating-menu-wrapper");
545
+ };
546
+
547
+ /** What the menu of values of a filter offers, by the name each value is shown with. */
548
+ const offered = async (axis: "site" | "language") =>
549
+ within(await openValues(axis))
550
+ .getAllByRole("button")
551
+ .map((option) => option.textContent);
552
+
553
+ /** Opens the menu of Templates of the Template filter and returns it. */
554
+ const openTemplates = async () => {
555
+ await click(within(filterRow("template")).getByTestId("icon-action-add"));
556
+ return within(filterRow("template")).getByTestId("floating-menu-wrapper");
557
+ };
558
+
559
+ const addTemplate = async (name: string) => click(within(await openTemplates()).getByText(name));
560
+
561
+ /** The pages a list of what a section takes shows. */
562
+ const resolvedPages = () => screen.queryAllByTestId("llms-resolved-page").map((row) => row.textContent);
563
+
564
+ /** The Pages a list of what a section takes shows, by the number in their title. */
565
+ const shownIds = () => resolvedPages().map((row) => Number(row?.match(/^Page (\d+)/)?.[1]));
566
+
567
+ /** The paginator of the list open beside the outline, if it has one. */
568
+ const paginator = () => screen.queryByTestId("pagination-wrapper");
569
+
570
+ /** What the paginator of the open list says, as it reads: «Page 2 of 3». */
571
+ const paginatorSays = () => {
572
+ const wrapper = paginator() as HTMLElement;
573
+ const current = (within(wrapper).getByTestId("pagination-text-input") as HTMLInputElement).value;
574
+ const last = within(wrapper)
575
+ .getByTestId("pagination-label")
576
+ .textContent?.match(/of (\d+)/)?.[1];
577
+
578
+ return `Page ${current} of ${last}`;
579
+ };
580
+
581
+ /** Moves the paginator of the open list on to the next slice. */
582
+ const nextSlice = () => click(within(paginator() as HTMLElement).getByTestId("icon-action-right-arrow"));
583
+
584
+ /** Where the screen remembers whether the lists of pages are folded, in this browser. */
585
+ const FOLDED_KEY = "llmsPagesFolded";
586
+
587
+ beforeEach(() => {
588
+ history.replace("/settings/llms");
589
+ mockedAxios.mockReset();
590
+ localStorage.removeItem(FOLDED_KEY);
591
+ });
592
+
593
+ afterEach(() => {
594
+ vi.restoreAllMocks();
595
+ cleanup();
596
+ });
597
+
598
+ describe("[UC-AX-model-llms-index] the LLM index model of a domain, end to end", () => {
599
+ it("AC1 · the model's own text is written once and sent as a single text, not per Language", async () => {
600
+ await renderScreen();
601
+
602
+ // There is nothing to choose a Language with: the text is one for the whole file.
603
+ expect(screen.queryByText("Español")).toBeNull();
604
+ await write(field("llmsTitle"), "Example University");
605
+ await write(field("llmsSummary"), "A university");
606
+ await write(field("llmsDetail"), "Founded in 1900.");
607
+
608
+ const sent = await save();
609
+
610
+ expect(sent.index.texts).toEqual({
611
+ title: "Example University",
612
+ summary: "A university",
613
+ detail: "Founded in 1900.",
614
+ });
615
+ });
616
+
617
+ it("AC2 · the model sent carries one list of LLM Index Sections for the Domain, not one per Language or URL Prefix", async () => {
618
+ await renderScreen({ settings: makeSettings({ sections: [manual("Programs")] }) });
619
+ await openSection("Programs");
620
+
621
+ await write(field("llmsSectionName"), "Programas");
622
+
623
+ const sent = await save();
624
+
625
+ expect(Object.keys(sent.index).sort()).toEqual([
626
+ "enabled",
627
+ "footer",
628
+ "includeGeneratedAt",
629
+ "optionalSection",
630
+ "sections",
631
+ "texts",
632
+ ]);
633
+ expect(sent.index.sections).toEqual([manual("Programas")]);
634
+ });
635
+
636
+ it("AC3 · a piece of the text not written does not travel in the text of the model sent", async () => {
637
+ await renderScreen({ settings: makeSettings({ texts: { title: "Example", summary: "A university" } }) });
638
+
639
+ await write(field("llmsSummary"), "");
640
+
641
+ const sent = await save();
642
+
643
+ // Absent, not an empty string.
644
+ expect(sent.index.texts).toEqual({ title: "Example" });
645
+ });
646
+
647
+ it("AC5 · the search of a manual LLM Index Section goes through the Domain's Pages and marks the ones that will not reach the LLM Index, each with its reason", async () => {
648
+ await renderScreen({
649
+ settings: makeSettings({ sections: [manual("Programs")] }),
650
+ search: [
651
+ makePage(1, { title: "Admissions" }),
652
+ makePage(2, { title: "Old campus", eligible: false, reasons: ["page-status", "noindex"] }),
653
+ makePage(3, { title: "Alumni", eligible: false, reasons: ["llm-opt-out"] }),
654
+ ],
655
+ });
656
+ await openSection("Programs");
657
+
658
+ await click(screen.getByRole("button", { name: "Add pages" }));
659
+ await screen.findByText("Old campus");
660
+
661
+ expect(within(pickerRow("Old campus")).getByText("Not published")).toBeInTheDocument();
662
+ expect(within(pickerRow("Old campus")).getByText("Noindex")).toBeInTheDocument();
663
+ expect(within(pickerRow("Alumni")).getByText("LLM opt-out")).toBeInTheDocument();
664
+ expect(within(pickerRow("Admissions")).queryByText("Not published")).toBeNull();
665
+ expect(within(pickerRow("Admissions")).queryByText("Noindex")).toBeNull();
666
+ expect(within(pickerRow("Admissions")).queryByText("LLM opt-out")).toBeNull();
667
+ // The search asks for the Domain's Pages, not for some ids.
668
+ const [searchRequest] = requests("GET", /\/domains\/7\/llms-pages$/);
669
+ expect(new URLSearchParams(searchRequest.url.split("?")[1]).get("ids")).toBeNull();
670
+ });
671
+
672
+ it("AC6 · the search lets the editor choose a marked Page", async () => {
673
+ await renderScreen({
674
+ settings: makeSettings({ sections: [manual("Programs")] }),
675
+ search: [makePage(2, { title: "Old campus", eligible: false, reasons: ["llm-opt-out"] })],
676
+ });
677
+ await openSection("Programs");
678
+
679
+ await click(screen.getByRole("button", { name: "Add pages" }));
680
+ await screen.findByText("Old campus");
681
+ await click(within(screen.getByTestId("llms-picker-page")).getByRole("button", { name: "Add" }));
682
+
683
+ expect(within(inspector()).getByText("Old campus")).toBeInTheDocument();
684
+ const sent = await save();
685
+ expect(sent.index.sections[0]).toEqual(manual("Programs", [2]));
686
+ });
687
+
688
+ it("AC7 · a chosen Page that stops being eligible stays in its LLM Index Section, marked", async () => {
689
+ await renderScreen({
690
+ settings: makeSettings({ sections: [manual("Programs", [10])] }),
691
+ known: [makePage(10, { title: "Law degree", eligible: false, reasons: ["llm-opt-out"] })],
692
+ });
693
+ await openSection("Programs");
694
+
695
+ await screen.findByText("Law degree");
696
+ expect(within(pageRow("Law degree")).getByText("LLM opt-out")).toBeInTheDocument();
697
+ });
698
+
699
+ it("AC8 · that same Page gets its eligible mark back the next time the model is opened after it is eligible again, without the editor choosing it again", async () => {
700
+ const settings = makeSettings({ sections: [manual("Programs", [10])] });
701
+ await renderScreen({
702
+ settings,
703
+ known: [makePage(10, { title: "Law degree", eligible: false, reasons: ["noindex"] })],
704
+ });
705
+ await openSection("Programs");
706
+ await screen.findByText("Law degree");
707
+ expect(within(pageRow("Law degree")).getByText("Noindex")).toBeInTheDocument();
708
+ cleanup();
709
+
710
+ // Nobody touched the model: the Page is eligible again on the server.
711
+ await renderScreen({ settings, known: [makePage(10, { title: "Law degree" })] });
712
+ await openSection("Programs");
713
+
714
+ await screen.findByText("Law degree");
715
+ expect(within(pageRow("Law degree")).queryByText("Noindex")).toBeNull();
716
+ });
717
+
718
+ it("AC9 · the model sent carries the Pages of each manual LLM Index Section in the order the editor set", async () => {
719
+ await renderScreen({
720
+ settings: makeSettings({ sections: [manual("Programs", [1, 2, 3])] }),
721
+ known: [makePage(1), makePage(2), makePage(3)],
722
+ });
723
+ await openSection("Programs");
724
+ await screen.findByText("Page 3");
725
+
726
+ await dragUp(pageRow("Page 2"));
727
+
728
+ const sent = await save();
729
+ expect(sent.index.sections[0]).toEqual(manual("Programs", [2, 1, 3]));
730
+ });
731
+
732
+ it("AC10 · the model sent carries the LLM Index Sections in the order the editor set", async () => {
733
+ await renderScreen({
734
+ settings: makeSettings({ sections: [manual("Programs"), manual("Research")] }),
735
+ });
736
+
737
+ await dragUp(outlineSection("Research"));
738
+
739
+ expect(outlineSections().map((section) => section.textContent)).toEqual([
740
+ expect.stringContaining("Research"),
741
+ expect.stringContaining("Programs"),
742
+ ]);
743
+ const sent = await save();
744
+ expect(sent.index.sections.map((section) => section.name)).toEqual(["Research", "Programs"]);
745
+ });
746
+
747
+ it("AC13 · the editor switches the publication of the LLM Index on or off and the LLM Surface Settings sent reflect it", async () => {
748
+ await renderScreen();
749
+ await toggle("llmsEnabled");
750
+ expect((await save()).index.enabled).toBe(false);
751
+ cleanup();
752
+ mockedAxios.mockReset();
753
+
754
+ await renderScreen({ settings: makeSettings({ enabled: false }) });
755
+ await toggle("llmsEnabled");
756
+ expect((await save()).index.enabled).toBe(true);
757
+ });
758
+
759
+ it("AC14 · with the publication off, the model keeps its text and its LLM Index Sections", async () => {
760
+ const texts = { title: "Example", summary: "A university" };
761
+ const sections = [manual("Programs", [10]), automatic("News", { quantity: 5 })];
762
+ await renderScreen({ settings: makeSettings({ texts, sections }), known: [makePage(10)] });
763
+
764
+ await toggle("llmsEnabled");
765
+
766
+ const sent = await save();
767
+ expect(sent.index.enabled).toBe(false);
768
+ expect(sent.index.texts).toEqual(texts);
769
+ expect(sent.index.sections).toEqual(sections);
770
+ });
771
+
772
+ it("AC15 · the preview shows the Domain's LLM Index as the source the Render asks resolves and composes it", async () => {
773
+ await renderScreen({
774
+ resolve: () => ok({ enabled: true, index: resolvedIndex([], "# Example\n\n> A university\n"), sites: SITES }),
775
+ });
776
+
777
+ await openPreview();
778
+
779
+ expect((await screen.findByTestId("llms-preview-content")).textContent).toBe("# Example\n\n> A university\n");
780
+ // One file, with nothing to choose between.
781
+ expect(screen.getAllByTestId("llms-preview-content")).toHaveLength(1);
782
+ });
783
+
784
+ it("AC16 · a preview that fails is reported", async () => {
785
+ await renderScreen({ resolve: () => failure(500) });
786
+
787
+ await openPreview();
788
+
789
+ expect(await screen.findByText(/The preview could not be generated/)).toBeInTheDocument();
790
+ });
791
+
792
+ it("AC19 · the name of an LLM Index Section is written once and sent as a single text, not per Language", async () => {
793
+ await renderScreen({ settings: makeSettings({ sections: [manual("Programs")] }) });
794
+ await openSection("Programs");
795
+
796
+ expect(within(inspector()).queryByText("Español")).toBeNull();
797
+ await write(field("llmsSectionName"), "Degrees and masters");
798
+
799
+ const sent = await save();
800
+ expect(sent.index.sections[0].name).toBe("Degrees and masters");
801
+ });
802
+
803
+ it("AC20 · saving sends the Domain's whole LLM Surface Settings, including what the editor did not touch", async () => {
804
+ // Values other than Griddo's defaults all over, so that a document that loses one shows.
805
+ const settings = makeSettings({
806
+ enabled: false,
807
+ texts: { title: "Example" },
808
+ sections: [automatic("News")],
809
+ optionalSection: optionalAutomatic({ quantity: 5 }),
810
+ });
811
+ await renderScreen({ settings });
812
+
813
+ await toggle("llmsEnabled");
814
+
815
+ expect(await save()).toEqual({ ...settings, index: { ...settings.index, enabled: true } });
816
+ });
817
+ it("AC21 · the preview is asked with the LLM Surface Settings the editor has on screen, even unsaved", async () => {
818
+ await renderScreen();
819
+ await write(field("llmsTitle"), "Not saved yet");
820
+
821
+ await openPreview();
822
+
823
+ await waitFor(() => expect(resolutions()).toHaveLength(1));
824
+ expect(lastResolved().index.texts.title).toBe("Not saved yet");
825
+ expect(lastResolved().markdown).toEqual(MIRROR);
826
+ expect(puts()).toHaveLength(0);
827
+ });
828
+
829
+ it("AC22 · without the permission to edit global SEO, the screen does not appear among the Global settings", async () => {
830
+ serveApi();
831
+ history.replace("/settings/llms");
832
+ const renderWith = async (permissions: string[]) =>
833
+ act(async () => {
834
+ render(
835
+ <Router history={history}>
836
+ <ThemeProvider theme={theme}>
837
+ <GlobalSettings />
838
+ </ThemeProvider>
839
+ </Router>,
840
+ { store: makeStore(permissions) },
841
+ );
842
+ });
843
+
844
+ await renderWith([PERMISSION]);
845
+ expect(screen.getByText("LLMs.txt Editor")).toBeInTheDocument();
846
+ cleanup();
847
+
848
+ await renderWith([OTHER_PERMISSION]);
849
+ expect(screen.queryByText("LLMs.txt Editor")).toBeNull();
850
+ // Every entry of the Global settings hangs from this same permission, so there is
851
+ // no other one to show: what says the render is not empty is the screen itself.
852
+ expect(screen.getByText("SEO Settings")).toBeInTheDocument();
853
+ });
854
+
855
+ it("AC23 · without the permission to edit global SEO, the screen's address does not open it", async () => {
856
+ serveApi();
857
+ const route = routes.find((item) => item.path === "/settings/llms");
858
+ expect(route).toBeDefined();
859
+ const currentUser = { id: 1, isSuperAdmin: false } as unknown as IUser;
860
+ const renderWith = async (permissions: string[]) =>
861
+ act(async () => {
862
+ render(
863
+ <Router history={history}>
864
+ <ThemeProvider theme={theme}>
865
+ <PrivateRoute
866
+ token="token"
867
+ path="/settings/llms"
868
+ component={route?.component}
869
+ permission={route?.permission}
870
+ currentUser={currentUser}
871
+ exact
872
+ />
873
+ </ThemeProvider>
874
+ </Router>,
875
+ { store: makeStore(permissions) },
876
+ );
877
+ });
878
+
879
+ await renderWith([OTHER_PERMISSION]);
880
+ expect(screen.getByText("Access Denied")).toBeInTheDocument();
881
+ expect(screen.queryByText("LLMs.txt editor")).toBeNull();
882
+ cleanup();
883
+
884
+ await renderWith([PERMISSION]);
885
+ expect(await screen.findByText("LLMs.txt editor")).toBeInTheDocument();
886
+ });
887
+
888
+ it("AC24 · on opening a manual LLM Index Section, each of its Pages shows its title and whether it will reach the LLM Index", async () => {
889
+ await renderScreen({
890
+ settings: makeSettings({ sections: [manual("Programs", [10, 11])] }),
891
+ known: [
892
+ makePage(10, { title: "Admissions" }),
893
+ makePage(11, { title: "Old campus", eligible: false, reasons: ["noindex"] }),
894
+ ],
895
+ });
896
+
897
+ await openSection("Programs");
898
+
899
+ await screen.findByText("Old campus");
900
+ expect(within(pageRow("Admissions")).queryByText("Noindex")).toBeNull();
901
+ expect(within(pageRow("Old campus")).getByText("Noindex")).toBeInTheDocument();
902
+ // Asked by id, in a slice where all of them fit.
903
+ const [byId] = requests("GET", /\/domains\/7\/llms-pages$/);
904
+ const params = new URLSearchParams(byId.url.split("?")[1]);
905
+ expect(params.get("ids")).toBe("10,11");
906
+ expect(params.get("itemsPerPage")).toBe("2");
907
+ });
908
+
909
+ it("AC25 · a chosen Page that is no longer among the Domain's stays in its LLM Index Section, flagged as not found", async () => {
910
+ await renderScreen({
911
+ settings: makeSettings({ sections: [manual("Programs", [10, 99])] }),
912
+ known: [makePage(10, { title: "Admissions" })],
913
+ });
914
+ await openSection("Programs");
915
+ await screen.findByText("Admissions");
916
+
917
+ const missing = pageRow("ID 99");
918
+ expect(within(missing).getByText("Page not found")).toBeInTheDocument();
919
+ expect(within(missing).getByText("Not found")).toBeInTheDocument();
920
+ // It stays in the model: a save that edits something else still carries it.
921
+ await toggle("llmsEnabled");
922
+ expect((await save()).index.sections[0]).toEqual(manual("Programs", [10, 99]));
923
+ });
924
+
925
+ it("AC26 · that same Page gets its title and its mark back the next time the model is opened after it is among the Domain's again, without the editor choosing it again", async () => {
926
+ const settings = makeSettings({ sections: [manual("Programs", [99])] });
927
+ await renderScreen({ settings, known: [] });
928
+ await openSection("Programs");
929
+ await waitFor(() => expect(within(pageRow("ID 99")).getByText("Not found")).toBeInTheDocument());
930
+ cleanup();
931
+
932
+ // Its Site was published again; nobody touched the model.
933
+ await renderScreen({ settings, known: [makePage(99, { title: "Back again" })] });
934
+ await openSection("Programs");
935
+
936
+ await screen.findByText("Back again");
937
+ expect(within(pageRow("Back again")).queryByText("Not found")).toBeNull();
938
+ });
939
+
940
+ it("AC27 · the editor removes a Page from its LLM Index Section, found or not, and the model sent no longer carries it", async () => {
941
+ await renderScreen({
942
+ settings: makeSettings({ sections: [manual("Programs", [10, 99])] }),
943
+ known: [makePage(10, { title: "Admissions" })],
944
+ });
945
+ await openSection("Programs");
946
+ await screen.findByText("Admissions");
947
+
948
+ await click(within(pageRow("ID 99")).getByTestId("icon-action-delete"));
949
+ expect((await save()).index.sections[0]).toEqual(manual("Programs", [10]));
950
+
951
+ await click(within(pageRow("Admissions")).getByTestId("icon-action-delete"));
952
+ expect((await save()).index.sections[0]).toEqual(manual("Programs", []));
953
+ });
954
+
955
+ it("AC28 · the editor removes an LLM Index Section and the model sent no longer carries it", async () => {
956
+ await renderScreen({
957
+ settings: makeSettings({ sections: [manual("Programs"), manual("Research")] }),
958
+ });
959
+ await openSection("Programs");
960
+
961
+ await click(within(screen.getByTestId("llms-section-actions")).getByTestId("icon-action-delete"));
962
+
963
+ expect(outlineSections()).toHaveLength(1);
964
+ expect((await save()).index.sections).toEqual([manual("Research")]);
965
+ });
966
+
967
+ it("AC30 · the list of Domains says of each one whether it publishes its LLM Index", async () => {
968
+ await renderList({
969
+ domains: [DOMAIN, OTHER_DOMAIN],
970
+ settingsOf: { 7: makeSettings({ enabled: true }), 8: makeSettings({ enabled: false }) },
971
+ });
972
+
973
+ expect(within(domainRow("www.example.edu")).getByTestId("llms-domain-index").textContent).toBe("Published");
974
+ expect(within(domainRow("postgrado.example.edu")).getByTestId("llms-domain-index").textContent).toBe(
975
+ "Not published",
976
+ );
977
+ });
978
+
979
+ it("AC31 · the list of Domains says of each one whether it writes Markdown Mirrors", async () => {
980
+ await renderList({
981
+ domains: [DOMAIN, OTHER_DOMAIN],
982
+ settingsOf: { 7: makeSettings({}, { enabled: true }), 8: makeSettings({}, { enabled: false }) },
983
+ });
984
+
985
+ expect(within(domainRow("www.example.edu")).getByTestId("llms-domain-mirror").textContent).toBe("On");
986
+ expect(within(domainRow("postgrado.example.edu")).getByTestId("llms-domain-mirror").textContent).toBe("Off");
987
+ });
988
+
989
+ it("AC32 · the list of Domains says of each one how many LLM Index Sections it has, not counting the Optional Section", async () => {
990
+ await renderList({
991
+ domains: [DOMAIN, OTHER_DOMAIN],
992
+ settingsOf: {
993
+ 7: makeSettings({
994
+ sections: [manual("A"), automatic("B"), manual("C")],
995
+ optionalSection: optionalAutomatic(),
996
+ }),
997
+ 8: makeSettings({ sections: [] }),
998
+ },
999
+ });
1000
+
1001
+ // Three and not four: every model has its Optional Section.
1002
+ expect(within(domainRow("www.example.edu")).getByTestId("llms-domain-sections").textContent).toBe("3");
1003
+ expect(within(domainRow("postgrado.example.edu")).getByTestId("llms-domain-sections").textContent).toBe("0");
1004
+ });
1005
+
1006
+ it("AC33 · a Domain whose settings cannot be read shows in the list without its state, and the others with theirs", async () => {
1007
+ await renderList({ domains: [DOMAIN, OTHER_DOMAIN], failures: { 8: Number.POSITIVE_INFINITY } });
1008
+
1009
+ const unreadable = domainRow("postgrado.example.edu");
1010
+ expect(within(unreadable).getByText("Its settings could not be read.")).toBeInTheDocument();
1011
+ expect(within(unreadable).queryByTestId("llms-domain-index")).toBeNull();
1012
+ expect(within(unreadable).queryByTestId("llms-domain-mirror")).toBeNull();
1013
+ expect(within(unreadable).queryByTestId("llms-domain-sections")).toBeNull();
1014
+ expect(within(domainRow("www.example.edu")).getByTestId("llms-domain-index").textContent).toBe("Published");
1015
+ });
1016
+
1017
+ it("AC34 · choosing a Domain whose settings could be read opens its LLM Index Model", async () => {
1018
+ await renderList({
1019
+ settings: makeSettings({ texts: { title: "Example" }, sections: [manual("Programs")] }),
1020
+ });
1021
+ expect(screen.queryByRole("navigation", { name: "Index outline" })).toBeNull();
1022
+
1023
+ await openDomain();
1024
+
1025
+ expect(within(outline()).getByText("Programs")).toBeInTheDocument();
1026
+ expect(field("llmsTitle").value).toBe("Example");
1027
+ });
1028
+
1029
+ it("AC35 · the breadcrumb leads from the open LLM Index Model back to the list of Domains", async () => {
1030
+ await renderScreen();
1031
+ const breadcrumb = screen.getByRole("navigation", { name: "Breadcrumb" });
1032
+ expect(within(breadcrumb).getByText("www.example.edu")).toBeInTheDocument();
1033
+
1034
+ await click(within(breadcrumb).getByRole("button", { name: "LLMs.txt editor" }));
1035
+
1036
+ expect(screen.queryByRole("navigation", { name: "Index outline" })).toBeNull();
1037
+ expect(domainRow("www.example.edu")).toBeInTheDocument();
1038
+ });
1039
+
1040
+ it("AC36 · with unsaved changes, going back to the list asks for confirmation before discarding them", async () => {
1041
+ await renderScreen();
1042
+ await write(field("llmsTitle"), "Not saved yet");
1043
+
1044
+ await click(screen.getByRole("button", { name: "LLMs.txt editor" }));
1045
+
1046
+ expect(screen.getByTestId("guard-modal-content")).toBeInTheDocument();
1047
+ // Still in the Domain, with its changes.
1048
+ expect(outline()).toBeInTheDocument();
1049
+ expect(field("llmsTitle").value).toBe("Not saved yet");
1050
+ });
1051
+
1052
+ it("AC37 · discarding the changes goes back to the list without sending anything", async () => {
1053
+ await renderScreen();
1054
+ await write(field("llmsTitle"), "Not saved yet");
1055
+ await click(screen.getByRole("button", { name: "LLMs.txt editor" }));
1056
+
1057
+ await click(screen.getByRole("button", { name: "Yes, discard changes" }));
1058
+
1059
+ expect(screen.queryByRole("navigation", { name: "Index outline" })).toBeNull();
1060
+ expect(domainRow("www.example.edu")).toBeInTheDocument();
1061
+ expect(puts()).toHaveLength(0);
1062
+ });
1063
+
1064
+ it("AC38 · after saving, the list shows the state of the Domain with what was saved", async () => {
1065
+ await renderScreen({ settings: makeSettings({ sections: [manual("Programs")] }) });
1066
+ await toggle("llmsEnabled");
1067
+ await save();
1068
+
1069
+ await click(screen.getByRole("button", { name: "LLMs.txt editor" }));
1070
+
1071
+ const row = domainRow("www.example.edu");
1072
+ expect(within(row).getByTestId("llms-domain-index").textContent).toBe("Not published");
1073
+ expect(within(row).getByTestId("llms-domain-sections").textContent).toBe("1");
1074
+ });
1075
+
1076
+ it("AC39 · the outline sums up each LLM Index Section with its Section Selection: how many Pages it chooses by hand, or how many filters it has and its limit", async () => {
1077
+ await renderScreen({
1078
+ settings: makeSettings({
1079
+ sections: [
1080
+ manual("Programs", [10, 11]),
1081
+ automatic("News", {
1082
+ filters: [{ axis: "template", operator: "isAnyOf", values: ["NewsDetail"] }],
1083
+ quantity: 10,
1084
+ }),
1085
+ automatic("Degrees", {
1086
+ filters: [
1087
+ { axis: "template", operator: "isAnyOf", values: ["ProgramDetail"] },
1088
+ { axis: "branch", operator: "isUnder", values: [5] },
1089
+ ],
1090
+ }),
1091
+ ],
1092
+ }),
1093
+ });
1094
+
1095
+ expect(within(outlineSection("Programs")).getByText("Manual · 2 pages")).toBeInTheDocument();
1096
+ expect(within(outlineSection("News")).getByText("Automatic · 1 filter · up to 10 pages")).toBeInTheDocument();
1097
+ expect(within(outlineSection("Degrees")).getByText("Automatic · 2 filters")).toBeInTheDocument();
1098
+ });
1099
+
1100
+ it("AC40 · choosing an element of the outline opens it beside it to edit it", async () => {
1101
+ await renderScreen({
1102
+ settings: makeSettings({ sections: [manual("Programs"), manual("Research")] }),
1103
+ });
1104
+
1105
+ await openSection("Research");
1106
+ expect(field("llmsSectionName").value).toBe("Research");
1107
+ expect(document.querySelector('[name="llmsTitle"]')).toBeNull();
1108
+
1109
+ await openHeader();
1110
+ expect(field("llmsTitle")).toBeInTheDocument();
1111
+ expect(document.querySelector('[name="llmsSectionName"]')).toBeNull();
1112
+ });
1113
+
1114
+ it("AC41 · the editor switches an LLM Index Section to automatic, and the model sent carries it automatic", async () => {
1115
+ await renderScreen({ settings: makeSettings({ sections: [manual("Programs", [10])] }) });
1116
+ await openSection("Programs");
1117
+
1118
+ await chooseRadio("llmsSectionSelection", "automatic");
1119
+
1120
+ expect((await save()).index.sections[0].type).toBe("automatic");
1121
+ });
1122
+
1123
+ it("AC42 · an LLM Index Section that turns automatic without having been so since the model was opened starts with no filters, the relation «all», by date descending and without limit", async () => {
1124
+ await renderScreen({ settings: makeSettings({ sections: [manual("Programs", [10])] }) });
1125
+ await openSection("Programs");
1126
+
1127
+ await chooseRadio("llmsSectionSelection", "automatic");
1128
+
1129
+ expect((await save()).index.sections[0]).toEqual({
1130
+ type: "automatic",
1131
+ name: "Programs",
1132
+ filters: [],
1133
+ globalOperator: "AND",
1134
+ order: "recent",
1135
+ orderDirection: "DESC",
1136
+ quantity: null,
1137
+ });
1138
+ });
1139
+
1140
+ it("AC43 · the Template filter offers every Template of the Instance, by the name it is shown with", async () => {
1141
+ await renderScreen({ settings: makeSettings({ sections: [automatic("News")] }) });
1142
+ await openSection("News");
1143
+ await addFilter("Template");
1144
+
1145
+ const menu = await openTemplates();
1146
+
1147
+ const offered = within(menu)
1148
+ .getAllByRole("button")
1149
+ .map((option) => option.textContent);
1150
+ expect(offered.sort()).toEqual(["Basic Template", "News detail", "Program detail"]);
1151
+ });
1152
+
1153
+ it("AC44 · the model sent carries, in the Template filter, the Templates the editor chose", async () => {
1154
+ await renderScreen({ settings: makeSettings({ sections: [automatic("Degrees")] }) });
1155
+ await openSection("Degrees");
1156
+ await addFilter("Template");
1157
+
1158
+ await addTemplate("Program detail");
1159
+ await addTemplate("News detail");
1160
+
1161
+ expect(within(filterRow("template")).getByText("Program detail")).toBeInTheDocument();
1162
+ expect((await save()).index.sections[0]).toEqual(
1163
+ automatic("Degrees", {
1164
+ filters: [{ axis: "template", operator: "isAnyOf", values: ["ProgramDetail", "NewsDetail"] }],
1165
+ }),
1166
+ );
1167
+ });
1168
+
1169
+ it("AC45 · the model sent carries, in the Branch filter, the Pages the editor chose in the search of the Domain's", async () => {
1170
+ // The section already filters by Branch: the menu no longer offers adding that filter (AC122).
1171
+ const branch = { axis: "branch" as const, operator: "isUnder" as const, values: [5] };
1172
+ await renderScreen({
1173
+ settings: makeSettings({ sections: [automatic("Degrees", { filters: [branch] })] }),
1174
+ known: [makePage(5, { title: "Degrees", url: "https://www.example.edu/degrees/" })],
1175
+ search: [makePage(6, { title: "Masters", url: "https://www.example.edu/masters/" })],
1176
+ });
1177
+ await openSection("Degrees");
1178
+
1179
+ await click(within(filterRow("branch")).getByTestId("icon-action-add"));
1180
+ await screen.findByTestId("llms-picker-page");
1181
+ await click(within(screen.getByTestId("llms-picker-page")).getByRole("button", { name: "Add" }));
1182
+
1183
+ expect(within(filterRow("branch")).getByText("Masters · /masters/")).toBeInTheDocument();
1184
+ // The search asks for the Domain's Pages, after the request by id of the chosen ones.
1185
+ const searchRequest = requests("GET", /\/domains\/7\/llms-pages$/).at(-1) as IRequest;
1186
+ expect(new URLSearchParams(searchRequest.url.split("?")[1]).get("ids")).toBeNull();
1187
+ expect((await save()).index.sections[0]).toEqual(
1188
+ automatic("Degrees", { filters: [{ ...branch, values: [5, 6] }] }),
1189
+ );
1190
+ });
1191
+
1192
+ it("AC46 · the model sent carries the relation between filters the editor chose: «all» or «any»", async () => {
1193
+ await renderScreen({ settings: makeSettings({ sections: [automatic("News")] }) });
1194
+ await openSection("News");
1195
+
1196
+ await choose("llmsGlobalOperator", "OR");
1197
+ expect((await save()).index.sections[0]).toEqual(automatic("News", { globalOperator: "OR" }));
1198
+
1199
+ await choose("llmsGlobalOperator", "AND");
1200
+ expect((await save()).index.sections[0]).toEqual(automatic("News", { globalOperator: "AND" }));
1201
+ });
1202
+
1203
+ it("AC47 · the model sent carries the order the editor chose: by date or by title, ascending or descending", async () => {
1204
+ await renderScreen({ settings: makeSettings({ sections: [automatic("News")] }) });
1205
+ await openSection("News");
1206
+
1207
+ await chooseRadio("llmsSectionOrder", "alpha");
1208
+ await choose("llmsOrderDirection", "Ascendent");
1209
+ expect((await save()).index.sections[0]).toEqual(automatic("News", { order: "alpha", orderDirection: "ASC" }));
1210
+
1211
+ await chooseRadio("llmsSectionOrder", "recent");
1212
+ await choose("llmsOrderDirection", "Descendent");
1213
+ expect((await save()).index.sections[0]).toEqual(automatic("News", { order: "recent", orderDirection: "DESC" }));
1214
+ });
1215
+
1216
+ it("AC48 · the model sent carries the limit the editor chose, or none if it chose all", async () => {
1217
+ await renderScreen({ settings: makeSettings({ sections: [automatic("News")] }) });
1218
+ await openSection("News");
1219
+
1220
+ await chooseRadio("llmsSectionQuantity", "number");
1221
+ await act(async () => {
1222
+ fireEvent.change(field("llmsQuantity"), { target: { value: "5" } });
1223
+ });
1224
+ expect((await save()).index.sections[0]).toEqual(automatic("News", { quantity: 5 }));
1225
+
1226
+ await chooseRadio("llmsSectionQuantity", "all");
1227
+ expect((await save()).index.sections[0]).toEqual(automatic("News", { quantity: null }));
1228
+ });
1229
+
1230
+ it("AC49 · the editor removes a filter, and the model sent no longer carries it", async () => {
1231
+ const branch = { axis: "branch" as const, operator: "isUnder" as const, values: [5] };
1232
+ await renderScreen({
1233
+ settings: makeSettings({
1234
+ sections: [
1235
+ automatic("Degrees", {
1236
+ filters: [{ axis: "template", operator: "isAnyOf", values: ["ProgramDetail"] }, branch],
1237
+ }),
1238
+ ],
1239
+ }),
1240
+ known: [makePage(5, { title: "Degrees" })],
1241
+ });
1242
+ await openSection("Degrees");
1243
+
1244
+ await click(within(filterRow("template")).getByTestId("icon-action-delete"));
1245
+
1246
+ expect(screen.queryByTestId("llms-filter-template")).toBeNull();
1247
+ expect((await save()).index.sections[0]).toEqual(automatic("Degrees", { filters: [branch] }));
1248
+ });
1249
+
1250
+ it("AC50 · an automatic LLM Index Section does not offer adding a filter of an axis it already has", async () => {
1251
+ await renderScreen({
1252
+ settings: makeSettings({
1253
+ sections: [
1254
+ automatic("Degrees", { filters: [{ axis: "template", operator: "isAnyOf", values: ["ProgramDetail"] }] }),
1255
+ ],
1256
+ }),
1257
+ });
1258
+ await openSection("Degrees");
1259
+
1260
+ const menu = await openAddFilter();
1261
+ expect(
1262
+ within(menu)
1263
+ .getAllByRole("button")
1264
+ .map((option) => option.textContent),
1265
+ ).toEqual(["Site", "Language"]);
1266
+
1267
+ await click(within(menu).getByText("Site"));
1268
+ await click(within(await openAddFilter()).getByText("Language"));
1269
+ expect(screen.queryByRole("button", { name: "Add filter" })).toBeNull();
1270
+ });
1271
+
1272
+ it("AC51 · a filter without values does not travel in the LLM Surface Settings the screen sends", async () => {
1273
+ await renderScreen({
1274
+ settings: makeSettings({
1275
+ sections: [
1276
+ automatic("Degrees", { filters: [{ axis: "template", operator: "isAnyOf", values: ["ProgramDetail"] }] }),
1277
+ ],
1278
+ }),
1279
+ });
1280
+ await openSection("Degrees");
1281
+
1282
+ // One filter left without values, and another one added without any.
1283
+ await click(within(filterRow("template")).getByTestId("delete-icon-wrapper"));
1284
+ await addFilter("Site");
1285
+ await settle();
1286
+
1287
+ expect(lastListed().settings.index.sections[0]).toEqual(automatic("Degrees"));
1288
+ const before = resolutions().length;
1289
+ await openPreview();
1290
+ await waitFor(() => expect(resolutions()).toHaveLength(before + 1));
1291
+ expect(lastResolved().index.sections[0]).toEqual(automatic("Degrees"));
1292
+ expect((await save()).index.sections[0]).toEqual(automatic("Degrees"));
1293
+ });
1294
+
1295
+ it("AC52 · an LLM Index Section that goes back to manual before saving gets back the Pages it had chosen", async () => {
1296
+ await renderScreen({
1297
+ settings: makeSettings({ sections: [manual("Programs", [10, 11])] }),
1298
+ known: [makePage(10, { title: "Admissions" }), makePage(11, { title: "Law degree" })],
1299
+ });
1300
+ await openSection("Programs");
1301
+ await screen.findByText("Admissions");
1302
+
1303
+ await chooseRadio("llmsSectionSelection", "automatic");
1304
+ expect(screen.queryAllByTestId("llms-section-page")).toHaveLength(0);
1305
+ await chooseRadio("llmsSectionSelection", "manual");
1306
+
1307
+ expect(screen.getAllByTestId("llms-section-page")).toHaveLength(2);
1308
+ await write(field("llmsSectionName"), "Programmes");
1309
+ expect((await save()).index.sections[0]).toEqual(manual("Programmes", [10, 11]));
1310
+ });
1311
+
1312
+ it("AC53 · the model sent carries of each LLM Index Section only what belongs to its Section Selection", async () => {
1313
+ await renderScreen({
1314
+ settings: makeSettings({
1315
+ sections: [manual("Programs", [10]), automatic("News", { quantity: 5 })],
1316
+ }),
1317
+ });
1318
+
1319
+ await openSection("Programs");
1320
+ await chooseRadio("llmsSectionSelection", "automatic");
1321
+ await openSection("News");
1322
+ await chooseRadio("llmsSectionSelection", "manual");
1323
+
1324
+ const [programs, news] = (await save()).index.sections;
1325
+ expect(Object.keys(programs).sort()).toEqual([
1326
+ "filters",
1327
+ "globalOperator",
1328
+ "name",
1329
+ "order",
1330
+ "orderDirection",
1331
+ "quantity",
1332
+ "type",
1333
+ ]);
1334
+ expect(Object.keys(news).sort()).toEqual(["name", "pages", "type"]);
1335
+ });
1336
+
1337
+ it("AC54 · an automatic LLM Index Section shows the Pages it takes, as the source the Render asks resolves them", async () => {
1338
+ await renderScreen({
1339
+ settings: makeSettings({ sections: [manual("Programs"), automatic("Degrees")] }),
1340
+ sectionPages: (asked) => sectionSlice(asked.section === 1 ? [1, 2] : []),
1341
+ });
1342
+
1343
+ await openSection("Degrees");
1344
+ await settle();
1345
+
1346
+ await waitFor(() => expect(resolvedPages()).toHaveLength(2));
1347
+ expect(resolvedPages()[0]).toContain("Page 1");
1348
+ expect(resolvedPages()[1]).toContain("Page 2");
1349
+ // Asked for this section, by its position in the model.
1350
+ expect(lastListed().section).toBe(1);
1351
+ });
1352
+
1353
+ it("AC55 · that list is asked with the LLM Surface Settings the editor has on screen, even unsaved", async () => {
1354
+ await renderScreen({ settings: makeSettings({ sections: [automatic("News")] }) });
1355
+ await openSection("News");
1356
+ await settle();
1357
+
1358
+ await choose("llmsGlobalOperator", "OR");
1359
+ await settle();
1360
+
1361
+ expect(lastListed().settings.index.sections[0]).toEqual(automatic("News", { globalOperator: "OR" }));
1362
+ expect(lastListed().settings.markdown).toEqual(MIRROR);
1363
+ expect(puts()).toHaveLength(0);
1364
+ });
1365
+
1366
+ it("AC56 · changing the filters, the relation, the order or the limit of the LLM Index Section asks for the list again", async () => {
1367
+ await renderScreen({ settings: makeSettings({ sections: [automatic("News")] }) });
1368
+ await openSection("News");
1369
+ await settle();
1370
+ await waitFor(() => expect(listings()).toHaveLength(1));
1371
+
1372
+ const change = async (edit: () => Promise<void>, expected: (sent: LlmsSettings) => unknown) => {
1373
+ const before = listings().length;
1374
+ await edit();
1375
+ await settle();
1376
+ await waitFor(() => expect(listings()).toHaveLength(before + 1));
1377
+ expect(expected(lastListed().settings)).toBeTruthy();
1378
+ };
1379
+
1380
+ await change(
1381
+ async () => {
1382
+ await addFilter("Template");
1383
+ await addTemplate("News detail");
1384
+ },
1385
+ (sent) => sent.index.sections[0].type === "automatic" && sent.index.sections[0].filters.length === 1,
1386
+ );
1387
+ await change(
1388
+ () => choose("llmsGlobalOperator", "OR"),
1389
+ (sent) => sent.index.sections[0].type === "automatic" && sent.index.sections[0].globalOperator === "OR",
1390
+ );
1391
+ await change(
1392
+ () => chooseRadio("llmsSectionOrder", "alpha"),
1393
+ (sent) => sent.index.sections[0].type === "automatic" && sent.index.sections[0].order === "alpha",
1394
+ );
1395
+ await change(
1396
+ () => choose("llmsOrderDirection", "Ascendent"),
1397
+ (sent) => sent.index.sections[0].type === "automatic" && sent.index.sections[0].orderDirection === "ASC",
1398
+ );
1399
+ await change(
1400
+ async () => {
1401
+ await chooseRadio("llmsSectionQuantity", "number");
1402
+ fireEvent.change(field("llmsQuantity"), { target: { value: "3" } });
1403
+ },
1404
+ (sent) => sent.index.sections[0].type === "automatic" && sent.index.sections[0].quantity === 3,
1405
+ );
1406
+ });
1407
+
1408
+ it("AC57 · several changes in a row ask for the list only once, when the editor stops changing it", async () => {
1409
+ await renderScreen({ settings: makeSettings({ sections: [automatic("News")] }) });
1410
+ await openSection("News");
1411
+ await settle();
1412
+ await waitFor(() => expect(listings()).toHaveLength(1));
1413
+
1414
+ await choose("llmsGlobalOperator", "OR");
1415
+ await chooseRadio("llmsSectionOrder", "alpha");
1416
+ await choose("llmsOrderDirection", "Ascendent");
1417
+ await settle();
1418
+ await settle();
1419
+
1420
+ expect(listings()).toHaveLength(2);
1421
+ expect(lastListed().settings.index.sections[0]).toEqual(
1422
+ automatic("News", { globalOperator: "OR", order: "alpha", orderDirection: "ASC" }),
1423
+ );
1424
+ });
1425
+
1426
+ it("AC58 · if the answer to an earlier request arrives after the answer to a later one, the list keeps the later one", async () => {
1427
+ let answerFirst: () => void = () => {};
1428
+ const answer = (asked: LlmsSectionPagesQuery) => {
1429
+ const section = asked.settings.index.sections[0];
1430
+ return sectionSlice(section.type === "automatic" && section.globalOperator === "OR" ? [2] : [1]);
1431
+ };
1432
+ await renderScreen({
1433
+ settings: makeSettings({ sections: [automatic("News")] }),
1434
+ sectionPages: (asked) =>
1435
+ listings().length === 1
1436
+ ? new Promise((resolve) => {
1437
+ answerFirst = () => resolve(answer(asked));
1438
+ })
1439
+ : answer(asked),
1440
+ });
1441
+ await openSection("News");
1442
+ await settle();
1443
+ await waitFor(() => expect(listings()).toHaveLength(1));
1444
+
1445
+ await choose("llmsGlobalOperator", "OR");
1446
+ await settle();
1447
+ await waitFor(() => expect(resolvedPages()).toEqual([expect.stringContaining("Page 2")]));
1448
+ await act(async () => {
1449
+ answerFirst();
1450
+ });
1451
+ await settle();
1452
+
1453
+ expect(resolvedPages()).toEqual([expect.stringContaining("Page 2")]);
1454
+ });
1455
+
1456
+ it("AC59 · the list shows the Pages of the open LLM Index Section even if another one of the model has the same name", async () => {
1457
+ let isHolding = false;
1458
+ let release: () => void = () => {};
1459
+ // Each section takes its own Page, told apart by its order, from the section at the position asked for.
1460
+ const answer = (asked: LlmsSectionPagesQuery) => {
1461
+ const section = asked.settings.index.sections[asked.section as number];
1462
+ return sectionSlice(section.type === "automatic" && section.order === "alpha" ? [2] : [1]);
1463
+ };
1464
+ await renderScreen({
1465
+ settings: makeSettings({
1466
+ sections: [automatic("Programs"), automatic("Programs", { order: "alpha" })],
1467
+ }),
1468
+ sectionPages: (asked) =>
1469
+ isHolding
1470
+ ? new Promise((resolve) => {
1471
+ release = () => resolve(answer(asked));
1472
+ })
1473
+ : answer(asked),
1474
+ });
1475
+
1476
+ await openItem(outlineSections()[1]);
1477
+ await settle();
1478
+ await waitFor(() => expect(resolvedPages()).toEqual([expect.stringContaining("Page 2")]));
1479
+
1480
+ // Moved above the other one: until its list arrives again, it does not show what
1481
+ // the section that had its new position took.
1482
+ isHolding = true;
1483
+ const asked = listings().length;
1484
+ await dragUp(outlineSections()[1]);
1485
+ await settle();
1486
+ await waitFor(() => expect(listings()).toHaveLength(asked + 1));
1487
+ expect(lastListed().section).toBe(0);
1488
+ expect(resolvedPages()).toHaveLength(0);
1489
+ expect(within(inspector()).getByText("Loading the pages…")).toBeInTheDocument();
1490
+
1491
+ await act(async () => {
1492
+ release();
1493
+ });
1494
+ await waitFor(() => expect(resolvedPages()).toEqual([expect.stringContaining("Page 2")]));
1495
+ });
1496
+
1497
+ it("AC61 · if the LLM Index Section takes no Page, with a name or without one, the list says no Page matches the selected filters", async () => {
1498
+ await renderScreen({
1499
+ settings: makeSettings({ sections: [automatic("Degrees"), automatic("")] }),
1500
+ sectionPages: () => sectionSlice([]),
1501
+ });
1502
+
1503
+ for (const title of ["Degrees", "Untitled section"]) {
1504
+ await openSection(title);
1505
+ await settle();
1506
+
1507
+ expect(await within(inspector()).findByText("No pages match the selected filters.")).toBeInTheDocument();
1508
+ expect(resolvedPages()).toHaveLength(0);
1509
+ }
1510
+ });
1511
+
1512
+ it("AC62 · if the list of what an automatic LLM Index Section takes cannot be asked for, it is reported", async () => {
1513
+ const reported = "The pages could not be loaded. You can still save your changes.";
1514
+ await renderScreen({
1515
+ settings: makeSettings({ sections: [automatic("News")] }),
1516
+ sectionPages: () => failure(500),
1517
+ });
1518
+
1519
+ await openSection("News");
1520
+ await settle();
1521
+
1522
+ expect(await within(inspector()).findByText(reported)).toBeInTheDocument();
1523
+
1524
+ // Nor one of its slices: the first one arrives, and the second one cannot be asked for.
1525
+ cleanup();
1526
+ mockedAxios.mockReset();
1527
+ await renderScreen({
1528
+ settings: makeSettings({ sections: [automatic("News")] }),
1529
+ sectionPages: (asked) => (asked.page === 2 ? failure(500) : takes(120)(asked)),
1530
+ });
1531
+ await openSection("News");
1532
+ await settle();
1533
+ await waitFor(() => expect(resolvedPages()).toHaveLength(50));
1534
+
1535
+ await nextSlice();
1536
+
1537
+ expect(await within(inspector()).findByText(reported)).toBeInTheDocument();
1538
+ });
1539
+
1540
+ it("AC63 · on opening it, the automatic Optional Section shows the Pages it takes, as the source the Render asks resolves them with the LLM Surface Settings on screen", async () => {
1541
+ await renderScreen({
1542
+ settings: makeSettings({ optionalSection: optionalAutomatic() }),
1543
+ sectionPages: (asked) => sectionSlice(asked.section === "optional" ? [4] : []),
1544
+ });
1545
+ await write(field("llmsTitle"), "Not saved yet");
1546
+
1547
+ await openOptional();
1548
+ await settle();
1549
+
1550
+ await waitFor(() => expect(resolvedPages()).toEqual([expect.stringContaining("Page 4")]));
1551
+ expect(lastListed().section).toBe("optional");
1552
+ expect(lastListed().settings.index.texts.title).toBe("Not saved yet");
1553
+ expect(puts()).toHaveLength(0);
1554
+ });
1555
+
1556
+ it("AC64 · an LLM Index Section that goes back to automatic before saving gets back its filters, its relation, its order and its limit", async () => {
1557
+ const selection = {
1558
+ filters: [{ axis: "template" as const, operator: "isAnyOf" as const, values: ["ProgramDetail"] }],
1559
+ globalOperator: "OR" as const,
1560
+ order: "alpha" as const,
1561
+ orderDirection: "ASC" as const,
1562
+ quantity: 5,
1563
+ };
1564
+ await renderScreen({ settings: makeSettings({ sections: [automatic("Degrees", selection)] }) });
1565
+ await openSection("Degrees");
1566
+
1567
+ await chooseRadio("llmsSectionSelection", "manual");
1568
+ expect(screen.queryByTestId("llms-filter-template")).toBeNull();
1569
+ await chooseRadio("llmsSectionSelection", "automatic");
1570
+
1571
+ expect(within(filterRow("template")).getByText("Program detail")).toBeInTheDocument();
1572
+ await write(field("llmsSectionName"), "Programmes");
1573
+ expect((await save()).index.sections[0]).toEqual(automatic("Programmes", selection));
1574
+ });
1575
+
1576
+ it("AC66 · a preview that fails does not prevent saving", async () => {
1577
+ await renderScreen({ resolve: () => failure(500) });
1578
+ await write(field("llmsTitle"), "Example");
1579
+
1580
+ await openPreview();
1581
+ await screen.findByText(/The preview could not be generated/);
1582
+
1583
+ expect(screen.getByRole("button", { name: "Save" })).toBeEnabled();
1584
+ expect((await save()).index.texts).toEqual({ title: "Example" });
1585
+ });
1586
+
1587
+ it("AC67 · if the list of what an automatic LLM Index Section takes cannot be asked for, it does not prevent saving", async () => {
1588
+ await renderScreen({
1589
+ settings: makeSettings({ sections: [automatic("News")] }),
1590
+ sectionPages: () => failure(500),
1591
+ });
1592
+ await openSection("News");
1593
+ await settle();
1594
+ await within(inspector()).findByText("The pages could not be loaded. You can still save your changes.");
1595
+
1596
+ await choose("llmsGlobalOperator", "OR");
1597
+
1598
+ expect(screen.getByRole("button", { name: "Save" })).toBeEnabled();
1599
+ expect((await save()).index.sections[0]).toEqual(automatic("News", { globalOperator: "OR" }));
1600
+ });
1601
+
1602
+ it("AC68 · choosing a Domain whose settings could not be read asks for them again", async () => {
1603
+ await renderList({
1604
+ settings: makeSettings({ sections: [manual("Programs")] }),
1605
+ failures: { 7: 1 },
1606
+ });
1607
+ expect(within(domainRow("www.example.edu")).getByText("Its settings could not be read.")).toBeInTheDocument();
1608
+
1609
+ await openDomain();
1610
+
1611
+ expect(requests("GET", /\/domains\/7\/llms-settings$/)).toHaveLength(2);
1612
+ expect(within(outline()).getByText("Programs")).toBeInTheDocument();
1613
+ });
1614
+
1615
+ it("AC69 · if they fail again, the screen says so and does not show its LLM Index Model", async () => {
1616
+ await renderList({ failures: { 7: Number.POSITIVE_INFINITY } });
1617
+
1618
+ await click(domainRow("www.example.edu"));
1619
+
1620
+ expect(
1621
+ await screen.findByText("The LLM settings of www.example.edu could not be read. Try again later."),
1622
+ ).toBeInTheDocument();
1623
+ expect(requests("GET", /\/domains\/7\/llms-settings$/)).toHaveLength(2);
1624
+ expect(screen.queryByRole("navigation", { name: "Index outline" })).toBeNull();
1625
+ expect(screen.queryByRole("button", { name: "Save" })).toBeNull();
1626
+ });
1627
+
1628
+ it("AC70 · with the publication off on screen, the preview says the Domain does not publish its LLM Index", async () => {
1629
+ await renderScreen({
1630
+ resolve: (sent) =>
1631
+ ok(
1632
+ sent.index.enabled
1633
+ ? { enabled: true, index: resolvedIndex([]), sites: SITES }
1634
+ : { enabled: false, index: null, sites: SITES },
1635
+ ),
1636
+ });
1637
+
1638
+ await toggle("llmsEnabled");
1639
+ await openPreview();
1640
+
1641
+ const panel = previewModal();
1642
+ expect(await within(panel).findByText("This domain does not publish its llms.txt.")).toBeInTheDocument();
1643
+ expect(within(panel).queryByTestId("llms-preview-content")).toBeNull();
1644
+ });
1645
+
1646
+ it("AC71 · with the publication off on screen, the list of an automatic LLM Index Section says the Domain does not publish its LLM Index", async () => {
1647
+ await renderScreen({
1648
+ settings: makeSettings({ sections: [automatic("News")] }),
1649
+ sectionPages: (asked) =>
1650
+ asked.settings.index.enabled ? sectionSlice([1]) : ok({ enabled: false, pages: null, sites: SITES }),
1651
+ });
1652
+ await openSection("News");
1653
+ await settle();
1654
+ await waitFor(() => expect(resolvedPages()).toHaveLength(1));
1655
+ expect(within(inspector()).queryByText(/does not publish its llms.txt/)).toBeNull();
1656
+
1657
+ await toggle("llmsEnabled");
1658
+ await settle();
1659
+
1660
+ expect(await within(inspector()).findByText(/does not publish its llms.txt/)).toBeInTheDocument();
1661
+ expect(resolvedPages()).toHaveLength(0);
1662
+ });
1663
+
1664
+ it("AC72 · with the publication off on screen, the list of the automatic Optional Section says the Domain does not publish its LLM Index", async () => {
1665
+ await renderScreen({
1666
+ settings: makeSettings({ optionalSection: optionalAutomatic() }),
1667
+ sectionPages: (asked) =>
1668
+ asked.settings.index.enabled ? sectionSlice([4]) : ok({ enabled: false, pages: null, sites: SITES }),
1669
+ });
1670
+ await openOptional();
1671
+ await settle();
1672
+ await waitFor(() => expect(resolvedPages()).toHaveLength(1));
1673
+ expect(within(optionalPanel()).queryByText(/does not publish its llms.txt/)).toBeNull();
1674
+
1675
+ await toggle("llmsEnabled");
1676
+ await settle();
1677
+
1678
+ expect(await within(optionalPanel()).findByText(/does not publish its llms.txt/)).toBeInTheDocument();
1679
+ expect(resolvedPages()).toHaveLength(0);
1680
+ });
1681
+
1682
+ it("AC73 · with unsaved changes, leaving the screen asks for confirmation before discarding them", async () => {
1683
+ await renderScreen();
1684
+ await write(field("llmsTitle"), "Not saved yet");
1685
+
1686
+ await act(async () => {
1687
+ history.push("/settings/robots");
1688
+ });
1689
+
1690
+ expect(screen.getByText(/Some LLM settings/)).toBeInTheDocument();
1691
+ expect(history.location.pathname).toBe("/settings/llms");
1692
+ });
1693
+
1694
+ it("AC74 · if the list of what the automatic Optional Section takes cannot be asked for, it is reported", async () => {
1695
+ await renderScreen({
1696
+ settings: makeSettings({ optionalSection: optionalAutomatic() }),
1697
+ sectionPages: () => failure(500),
1698
+ });
1699
+
1700
+ await openOptional();
1701
+ await settle();
1702
+
1703
+ expect(
1704
+ await within(optionalPanel()).findByText("The pages could not be loaded. You can still save your changes."),
1705
+ ).toBeInTheDocument();
1706
+ });
1707
+ it("AC75 · if the list of what the automatic Optional Section takes cannot be asked for, it does not prevent saving", async () => {
1708
+ await renderScreen({
1709
+ settings: makeSettings({ optionalSection: optionalAutomatic() }),
1710
+ sectionPages: () => failure(500),
1711
+ });
1712
+ await openOptional();
1713
+ await settle();
1714
+ await screen.findByText("The pages could not be loaded. You can still save your changes.");
1715
+
1716
+ await addFilter("Template");
1717
+ await addTemplate("News detail");
1718
+
1719
+ expect(screen.getByRole("button", { name: "Save" })).toBeEnabled();
1720
+ expect((await save()).index.optionalSection).toEqual(
1721
+ optionalAutomatic({ filters: [{ axis: "template", operator: "isAnyOf", values: ["NewsDetail"] }] }),
1722
+ );
1723
+ });
1724
+ it("AC76 · if the chosen Pages cannot be asked for, the screen says so", async () => {
1725
+ await renderScreen({
1726
+ settings: makeSettings({ sections: [manual("Programs", [10])] }),
1727
+ known: [makePage(10, { title: "Admissions" })],
1728
+ pagesByIdFail: true,
1729
+ });
1730
+
1731
+ expect(await screen.findByText(/The chosen pages could not be loaded/)).toBeInTheDocument();
1732
+ });
1733
+
1734
+ it("AC77 · if the chosen Pages cannot be asked for, the screen does not flag them as not found", async () => {
1735
+ const branch = { axis: "branch" as const, operator: "isUnder" as const, values: [5] };
1736
+ await renderScreen({
1737
+ settings: makeSettings({
1738
+ sections: [manual("Programs", [10]), automatic("Degrees", { filters: [branch] })],
1739
+ }),
1740
+ pagesByIdFail: true,
1741
+ });
1742
+ await screen.findByText(/The chosen pages could not be loaded/);
1743
+
1744
+ await openSection("Programs");
1745
+ // Still there, by its id —the half that says the list is not just empty—, and unflagged.
1746
+ const row = pageRow("ID 10");
1747
+ expect(within(row).getByText("Page 10")).toBeInTheDocument();
1748
+ expect(within(row).queryByText("Page not found")).toBeNull();
1749
+ expect(within(row).queryByText("Not found")).toBeNull();
1750
+
1751
+ await openSection("Degrees");
1752
+ expect(within(filterRow("branch")).getByText("Page 5")).toBeInTheDocument();
1753
+ expect(within(filterRow("branch")).queryByText(/not found/i)).toBeNull();
1754
+ });
1755
+
1756
+ it("AC78 · if the editor chooses to limit an automatic LLM Index Section without writing a positive whole number, the model sent carries it without limit", async () => {
1757
+ await renderScreen({ settings: makeSettings({ sections: [automatic("News")] }) });
1758
+ await openSection("News");
1759
+
1760
+ await chooseRadio("llmsSectionQuantity", "number");
1761
+ await act(async () => {
1762
+ fireEvent.change(field("llmsQuantity"), { target: { value: "0" } });
1763
+ });
1764
+ // Something else as well, so that there is a change to save.
1765
+ await write(field("llmsSectionName"), "Latest news");
1766
+
1767
+ expect(document.querySelector<HTMLInputElement>('[name="llmsSectionQuantity"][value="number"]')?.checked).toBe(
1768
+ true,
1769
+ );
1770
+ expect((await save()).index.sections[0]).toEqual(automatic("Latest news", { quantity: null }));
1771
+
1772
+ await act(async () => {
1773
+ fireEvent.change(field("llmsQuantity"), { target: { value: "2.5" } });
1774
+ });
1775
+ await write(field("llmsSectionName"), "News");
1776
+
1777
+ expect((await save()).index.sections[0]).toEqual(automatic("News", { quantity: null }));
1778
+ });
1779
+
1780
+ it("AC79 · an LLM Index Section with no name shows in the outline as nameless", async () => {
1781
+ await renderScreen({ settings: makeSettings({ sections: [manual("Programs")] }) });
1782
+ await openSection("Programs");
1783
+
1784
+ await write(field("llmsSectionName"), "");
1785
+
1786
+ const [section] = outlineSections();
1787
+ expect(within(section).getByText("Untitled section")).toBeInTheDocument();
1788
+ expect(within(section).queryByText("Programs")).toBeNull();
1789
+ });
1790
+
1791
+ it("AC81 · with the automatic Optional Section taking no Page, its list says no Page matches the selected filters", async () => {
1792
+ await renderScreen({
1793
+ settings: makeSettings({ optionalSection: optionalAutomatic() }),
1794
+ sectionPages: () => sectionSlice([]),
1795
+ });
1796
+ await openOptional();
1797
+ await settle();
1798
+
1799
+ expect(await within(optionalPanel()).findByText("No pages match the selected filters.")).toBeInTheDocument();
1800
+ expect(resolvedPages()).toHaveLength(0);
1801
+ });
1802
+ it("AC82 · if the Domain has no URL Prefix, the preview says so", async () => {
1803
+ await renderScreen({ resolve: () => ok({ enabled: true, index: null, sites: SITES }) });
1804
+
1805
+ await openPreview();
1806
+
1807
+ const panel = previewModal();
1808
+ expect(
1809
+ await within(panel).findByText("This domain has no URL prefix to publish an llms.txt for."),
1810
+ ).toBeInTheDocument();
1811
+ });
1812
+
1813
+ it("AC83 · if the Domain has no URL Prefix, the list of an automatic LLM Index Section says so", async () => {
1814
+ await renderScreen({
1815
+ settings: makeSettings({ sections: [automatic("News")] }),
1816
+ sectionPages: () => ok({ enabled: true, pages: null, sites: SITES }),
1817
+ });
1818
+
1819
+ await openSection("News");
1820
+ await settle();
1821
+
1822
+ expect(
1823
+ await within(inspector()).findByText("This domain has no URL prefix to publish an llms.txt for."),
1824
+ ).toBeInTheDocument();
1825
+ });
1826
+
1827
+ it("AC84 · if the Domain has no URL Prefix, the list of the automatic Optional Section says so", async () => {
1828
+ await renderScreen({
1829
+ settings: makeSettings({ optionalSection: optionalAutomatic() }),
1830
+ sectionPages: () => ok({ enabled: true, pages: null, sites: SITES }),
1831
+ });
1832
+
1833
+ await openOptional();
1834
+ await settle();
1835
+
1836
+ expect(
1837
+ await within(optionalPanel()).findByText("This domain has no URL prefix to publish an llms.txt for."),
1838
+ ).toBeInTheDocument();
1839
+ });
1840
+ it("AC85 · if the search cannot ask for the Domain's Pages, it says so", async () => {
1841
+ await renderScreen({ settings: makeSettings({ sections: [manual("Programs")] }), searchFails: true });
1842
+ await openSection("Programs");
1843
+
1844
+ await click(screen.getByRole("button", { name: "Add pages" }));
1845
+
1846
+ expect(await screen.findByText("The pages of this domain could not be loaded.")).toBeInTheDocument();
1847
+ });
1848
+
1849
+ it("AC86 · the search marks the Pages the selection it is opened for already carries: those chosen by hand of a manual LLM Index Section, or those that root the Branches of an automatic one", async () => {
1850
+ const branch = { axis: "branch" as const, operator: "isUnder" as const, values: [5] };
1851
+ await renderScreen({
1852
+ settings: makeSettings({
1853
+ sections: [manual("Programs", [10]), automatic("Degrees", { filters: [branch] })],
1854
+ }),
1855
+ known: [makePage(10, { title: "Admissions" }), makePage(5, { title: "Grados" })],
1856
+ search: [makePage(10, { title: "Admissions" }), makePage(5, { title: "Grados" }), makePage(11, { title: "Law" })],
1857
+ });
1858
+
1859
+ await openSection("Programs");
1860
+ await click(screen.getByRole("button", { name: "Add pages" }));
1861
+ await screen.findByText("Law");
1862
+ expect(within(pickerRow("Admissions")).getByRole("button", { name: "Added" })).toBeInTheDocument();
1863
+ expect(within(pickerRow("Grados")).getByRole("button", { name: "Add" })).toBeInTheDocument();
1864
+ await click(within(screen.getByTestId("floating-panel")).getByTestId("icon-action-close"));
1865
+
1866
+ await openSection("Degrees");
1867
+ await click(within(filterRow("branch")).getByTestId("icon-action-add"));
1868
+ await screen.findByText("Law");
1869
+ expect(within(pickerRow("Grados")).getByRole("button", { name: "Added" })).toBeInTheDocument();
1870
+ expect(within(pickerRow("Admissions")).getByRole("button", { name: "Add" })).toBeInTheDocument();
1871
+ });
1872
+
1873
+ it("AC87 · the search does not let the editor choose again a Page the selection already carries", async () => {
1874
+ await renderScreen({
1875
+ settings: makeSettings({ sections: [manual("Programs", [10])] }),
1876
+ known: [makePage(10, { title: "Admissions" })],
1877
+ search: [makePage(10, { title: "Admissions" }), makePage(11, { title: "Law" })],
1878
+ });
1879
+ await openSection("Programs");
1880
+ await click(screen.getByRole("button", { name: "Add pages" }));
1881
+ await screen.findByText("Law");
1882
+
1883
+ const added = within(pickerRow("Admissions")).getByRole("button", { name: "Added" });
1884
+ expect(added).toBeDisabled();
1885
+ await click(added);
1886
+ await click(within(pickerRow("Law")).getByRole("button", { name: "Add" }));
1887
+
1888
+ // The other one does get added —the half that shows adding works—, and the one it carried is still there once.
1889
+ expect((await save()).index.sections[0]).toEqual(manual("Programs", [10, 11]));
1890
+ });
1891
+
1892
+ it("AC101 · the Site filter offers, by their name, the Sites the source the Render asks says count for the Domain", async () => {
1893
+ await renderScreen({ settings: makeSettings({ sections: [automatic("Degrees")] }) });
1894
+ await openSection("Degrees");
1895
+ await settle();
1896
+
1897
+ await addFilter("Site");
1898
+
1899
+ expect(await offered("site")).toEqual(["Degrees", "Research", "Masters"]);
1900
+ });
1901
+
1902
+ it("AC102 · the model sent carries, in the Site filter, the Sites the editor chose", async () => {
1903
+ await renderScreen({ settings: makeSettings({ sections: [automatic("Degrees")] }) });
1904
+ await openSection("Degrees");
1905
+ await settle();
1906
+
1907
+ await addFilter("Site");
1908
+ await click(within(await openValues("site")).getByText("Research"));
1909
+ await click(within(await openValues("site")).getByText("Degrees"));
1910
+
1911
+ expect((await save()).index.sections[0]).toEqual(
1912
+ automatic("Degrees", { filters: [{ axis: "site", operator: "isAnyOf", values: [4, 3] }] }),
1913
+ );
1914
+ });
1915
+
1916
+ it("AC103 · the Language filter offers every Language of the Instance, by its name, also those the Domain serves no Site in, and the same ones with Sites in the Site filter as without them", async () => {
1917
+ await renderScreen({ settings: makeSettings({ sections: [automatic("Degrees")] }) });
1918
+ await openSection("Degrees");
1919
+ await settle();
1920
+
1921
+ await addFilter("Language");
1922
+ expect(await offered("language")).toEqual(["English", "Español", "Français"]);
1923
+
1924
+ // Research is only in English, and the filter goes on offering the three.
1925
+ await addFilter("Site");
1926
+ await click(within(await openValues("site")).getByText("Research"));
1927
+ expect(await offered("language")).toEqual(["English", "Español", "Français"]);
1928
+ });
1929
+
1930
+ it("AC105 · the model sent carries, in the Language filter, the Languages the editor chose", async () => {
1931
+ await renderScreen({ settings: makeSettings({ sections: [automatic("Degrees")] }) });
1932
+ await openSection("Degrees");
1933
+ await settle();
1934
+
1935
+ await addFilter("Language");
1936
+ await click(within(await openValues("language")).getByText("Español"));
1937
+
1938
+ expect((await save()).index.sections[0]).toEqual(
1939
+ automatic("Degrees", { filters: [{ axis: "language", operator: "isAnyOf", values: [2] }] }),
1940
+ );
1941
+ });
1942
+
1943
+ it("AC106 · removing a Site from the Site filter leaves the Language filter as it was", async () => {
1944
+ await renderScreen({
1945
+ settings: makeSettings({
1946
+ sections: [
1947
+ automatic("Degrees", {
1948
+ filters: [
1949
+ { axis: "site", operator: "isAnyOf", values: [3, 5] },
1950
+ { axis: "language", operator: "isAnyOf", values: [1, 2] },
1951
+ ],
1952
+ }),
1953
+ ],
1954
+ }),
1955
+ });
1956
+ await openSection("Degrees");
1957
+ await settle();
1958
+
1959
+ // Degrees goes, and English stays, although Masters, the one that stays, is only in Spanish.
1960
+ const [degrees] = within(filterRow("site")).getAllByTestId("delete-icon-wrapper");
1961
+ await click(degrees);
1962
+
1963
+ expect((await save()).index.sections[0]).toEqual(
1964
+ automatic("Degrees", {
1965
+ filters: [
1966
+ { axis: "site", operator: "isAnyOf", values: [5] },
1967
+ { axis: "language", operator: "isAnyOf", values: [1, 2] },
1968
+ ],
1969
+ }),
1970
+ );
1971
+ });
1972
+
1973
+ it("AC107 · the LLM Surface Settings sent say neither whether the Domain publishes the LLM Index of each URL Prefix nor which Language it chooses for the root", async () => {
1974
+ await renderScreen();
1975
+ await write(field("llmsTitle"), "Example");
1976
+
1977
+ const sent = await save();
1978
+ await openPreview();
1979
+ await waitFor(() => expect(resolutions()).toHaveLength(1));
1980
+
1981
+ for (const settings of [sent, lastResolved()]) {
1982
+ expect(settings.index).not.toHaveProperty("perPrefix");
1983
+ expect(settings.index).not.toHaveProperty("rootLanguage");
1984
+ }
1985
+ });
1986
+ it("AC108 · the editor chooses in the Index header whether the LLM Index says when it was generated, and the model sent reflects it", async () => {
1987
+ await renderScreen();
1988
+
1989
+ await toggle("llmsIncludeGeneratedAt");
1990
+ expect((await save()).index.includeGeneratedAt).toBe(true);
1991
+
1992
+ await toggle("llmsIncludeGeneratedAt");
1993
+ expect((await save()).index.includeGeneratedAt).toBe(false);
1994
+ });
1995
+
1996
+ it("AC109 · the Index footer is written once, in a single text, and sent as it was written", async () => {
1997
+ await renderScreen({ settings: makeSettings({ footer: { content: "Old footer" } }) });
1998
+ await openItem(screen.getByTestId("llms-outline-footer"));
1999
+
2000
+ // A single text, not one per Language, and no title, summary or detail of its own.
2001
+ expect(screen.queryByText("Español")).toBeNull();
2002
+ for (const piece of ["llmsFooterTitle", "llmsFooterSummary", "llmsFooterDetail"]) {
2003
+ expect(document.querySelector(`[name="${piece}"]`)).toBeNull();
2004
+ }
2005
+ expect(field("llmsFooterContent").value).toBe("Old footer");
2006
+
2007
+ const written = "\n## Contact\n\nWrite to [info@example.edu](mailto:info@example.edu). \n";
2008
+ await write(field("llmsFooterContent"), written);
2009
+
2010
+ const sent = await save();
2011
+
2012
+ // As written: its blanks and its markdown untouched.
2013
+ expect(sent.index.footer).toEqual({ content: written });
2014
+ // The header is another text: the footer does not write in it.
2015
+ expect(sent.index.texts).toEqual({});
2016
+ });
2017
+
2018
+ it("AC113 · the Index header title is not required: its field says that, left empty, the LLM Index takes the domain name, and which one", async () => {
2019
+ await renderScreen();
2020
+ await openHeader();
2021
+
2022
+ expect(screen.getByText("If left empty, the domain name is used: www.example.edu.")).toBeInTheDocument();
2023
+ // Without a title the model is still saved.
2024
+ await write(field("llmsSummary"), "Degrees and masters");
2025
+ expect((await save()).index.texts).toEqual({ summary: "Degrees and masters" });
2026
+ });
2027
+
2028
+ it("AC114 · the list of the Pages an automatic LLM Index Section takes, the Optional Section included, comes out unfolded and can be folded and unfolded again; folded, its paginator folds with it and it still says how many Pages it takes in all", async () => {
2029
+ await renderScreen({
2030
+ settings: makeSettings({ sections: [automatic("News")], optionalSection: optionalAutomatic() }),
2031
+ sectionPages: (asked) => takes(asked.section === "optional" ? 2 : 120)(asked),
2032
+ });
2033
+
2034
+ for (const [open, total, shown] of [
2035
+ [() => openSection("News"), "120 pages", 50],
2036
+ [openOptional, "2 pages", 2],
2037
+ ] as const) {
2038
+ const hasPaginator = shown === 50;
2039
+ await open();
2040
+ await settle();
2041
+ await waitFor(() => expect(resolvedPages()).toHaveLength(shown));
2042
+ expect(paginator() !== null).toBe(hasPaginator);
2043
+
2044
+ await click(screen.getByRole("button", { name: "Hide pages" }));
2045
+ expect(resolvedPages()).toHaveLength(0);
2046
+ expect(paginator()).toBeNull();
2047
+ expect(screen.getByText(`${total}, in the order the llms.txt lists them.`)).toBeInTheDocument();
2048
+
2049
+ await click(screen.getByRole("button", { name: "Show pages" }));
2050
+ expect(resolvedPages()).toHaveLength(shown);
2051
+ expect(paginator() !== null).toBe(hasPaginator);
2052
+ }
2053
+ });
2054
+
2055
+ it("AC115 · a folded list stays folded when it is asked again because the editor changed what is on screen", async () => {
2056
+ await renderScreen({
2057
+ settings: makeSettings({ sections: [automatic("News")] }),
2058
+ sectionPages: () => sectionSlice([1, 2, 3]),
2059
+ });
2060
+ await openSection("News");
2061
+ await settle();
2062
+ await waitFor(() => expect(resolvedPages()).toHaveLength(3));
2063
+ await click(screen.getByRole("button", { name: "Hide pages" }));
2064
+ const asked = listings().length;
2065
+
2066
+ await choose("llmsGlobalOperator", "OR");
2067
+ await settle();
2068
+
2069
+ await waitFor(() => expect(listings().length).toBeGreaterThan(asked));
2070
+ await screen.findByText("3 pages, in the order the llms.txt lists them.");
2071
+ expect(resolvedPages()).toHaveLength(0);
2072
+ expect(screen.getByRole("button", { name: "Show pages" })).toBeInTheDocument();
2073
+ });
2074
+
2075
+ it("AC116 · folding or unfolding one of those lists is remembered by the screen in this browser: the other lists, also those of other Domains, and the screen opened later come out the same", async () => {
2076
+ const api: IApi = {
2077
+ domains: [DOMAIN, OTHER_DOMAIN],
2078
+ settingsOf: {
2079
+ [DOMAIN.id]: makeSettings({ sections: [automatic("News")], optionalSection: optionalAutomatic() }),
2080
+ [OTHER_DOMAIN.id]: makeSettings({ sections: [automatic("Research")] }),
2081
+ },
2082
+ sectionPages: (asked) => sectionSlice(asked.section === "optional" ? [3] : [1, 2]),
2083
+ };
2084
+ await renderList(api);
2085
+ await openDomain();
2086
+ await openSection("News");
2087
+ await settle();
2088
+ await waitFor(() => expect(resolvedPages()).toHaveLength(2));
2089
+
2090
+ await click(screen.getByRole("button", { name: "Hide pages" }));
2091
+
2092
+ // The Optional Section of the same Domain.
2093
+ await openOptional();
2094
+ await settle();
2095
+ await screen.findByText("1 page, in the order the llms.txt lists them.");
2096
+ expect(resolvedPages()).toHaveLength(0);
2097
+
2098
+ // A section of another Domain.
2099
+ await click(screen.getByRole("button", { name: "LLMs.txt editor" }));
2100
+ await openDomain(OTHER_DOMAIN.name as string);
2101
+ await openSection("Research");
2102
+ await settle();
2103
+ await screen.findByText("2 pages, in the order the llms.txt lists them.");
2104
+ expect(resolvedPages()).toHaveLength(0);
2105
+
2106
+ // The screen opened later, and unfolding is remembered too.
2107
+ cleanup();
2108
+ mockedAxios.mockReset();
2109
+ await renderScreen(api);
2110
+ await openSection("News");
2111
+ await settle();
2112
+ await screen.findByText("2 pages, in the order the llms.txt lists them.");
2113
+ expect(resolvedPages()).toHaveLength(0);
2114
+ await click(screen.getByRole("button", { name: "Show pages" }));
2115
+
2116
+ cleanup();
2117
+ mockedAxios.mockReset();
2118
+ await renderScreen(api);
2119
+ await openSection("News");
2120
+ await settle();
2121
+ await waitFor(() => expect(resolvedPages()).toHaveLength(2));
2122
+ });
2123
+
2124
+ it("AC110 · the outline shows the Index footer after the Optional Section", async () => {
2125
+ await renderScreen({ settings: makeSettings({ sections: [manual("Programs")] }) });
2126
+
2127
+ const entries = within(outline())
2128
+ .getAllByRole("button")
2129
+ .map((button) => button.textContent ?? "");
2130
+ const optional = entries.findIndex((entry) => entry.startsWith("Optional"));
2131
+ const footer = entries.findIndex((entry) => entry.startsWith("Footer"));
2132
+
2133
+ expect(optional).toBeGreaterThan(-1);
2134
+ expect(footer).toBe(optional + 1);
2135
+ });
2136
+ it("AC111 · the preview opens in a modal from the eye in the corner of the outline", async () => {
2137
+ await renderScreen({
2138
+ resolve: () => ok({ enabled: true, index: resolvedIndex([], "# Example\n"), sites: SITES }),
2139
+ });
2140
+ expect(screen.queryByRole("button", { name: "Preview llms.txt" })).toBeNull();
2141
+
2142
+ await openPreview();
2143
+
2144
+ const modal = previewModal();
2145
+ expect(within(modal).getByText("llms.txt preview")).toBeInTheDocument();
2146
+ expect((await within(modal).findByTestId("llms-preview-content")).textContent).toBe("# Example\n");
2147
+ expect(screen.queryByTestId("floating-panel")).toBeNull();
2148
+ });
2149
+
2150
+ it("AC117 · the Optional Section is modelled as an LLM Index Section: the editor chooses its Section Selection, manual or automatic, and the model sent carries it with what belongs to that selection", async () => {
2151
+ await renderScreen({
2152
+ settings: makeSettings({ optionalSection: { type: "manual", pages: [10, 11] } }),
2153
+ known: [makePage(10, { title: "Admissions" }), makePage(11, { title: "Scholarships" })],
2154
+ });
2155
+ await openOptional();
2156
+ await screen.findByText("Admissions");
2157
+
2158
+ await click(within(pageRow("Admissions")).getByTestId("icon-action-delete"));
2159
+ expect((await save()).index.optionalSection).toEqual({ type: "manual", pages: [11] });
2160
+
2161
+ await chooseRadio("llmsSectionSelection", "automatic");
2162
+ await addFilter("Template");
2163
+ await addTemplate("News detail");
2164
+
2165
+ expect((await save()).index.optionalSection).toEqual(
2166
+ optionalAutomatic({ filters: [{ axis: "template", operator: "isAnyOf", values: ["NewsDetail"] }] }),
2167
+ );
2168
+ });
2169
+
2170
+ it("AC118 · the Optional Section has no name to write: the outline and its panel show it as Optional, and the model sent carries it without a name", async () => {
2171
+ await renderScreen();
2172
+
2173
+ expect(within(screen.getByTestId("llms-outline-optional")).getByText("Optional")).toBeInTheDocument();
2174
+
2175
+ await openOptional();
2176
+
2177
+ expect(within(optionalPanel()).getByText("Optional section")).toBeInTheDocument();
2178
+ expect(document.querySelector('[name="llmsSectionName"]')).toBeNull();
2179
+ await chooseRadio("llmsSectionSelection", "automatic");
2180
+ expect((await save()).index.optionalSection).not.toHaveProperty("name");
2181
+ });
2182
+
2183
+ it("AC119 · the Optional Section is neither switched on or off nor removed: its panel does not offer it", async () => {
2184
+ await renderScreen();
2185
+ await openOptional();
2186
+
2187
+ const panel = optionalPanel();
2188
+ expect(within(panel).queryByRole("checkbox")).toBeNull();
2189
+ expect(within(panel).queryByTestId("icon-action-delete")).toBeNull();
2190
+ });
2191
+
2192
+ it("AC120 · the outline shows, in this order, the LLM Index Sections, the button that adds another, the Optional Section and the footer", async () => {
2193
+ await renderScreen({ settings: makeSettings({ sections: [manual("Programs"), manual("Research")] }) });
2194
+
2195
+ const entries = within(outline())
2196
+ .getAllByRole("button")
2197
+ .map((button) => button.textContent ?? "")
2198
+ .filter((entry) => !entry.startsWith("Reorder") && entry !== "");
2199
+
2200
+ expect(entries.slice(-5).map((entry) => entry.split(/Manual|Title|Markdown/)[0])).toEqual([
2201
+ "Programs",
2202
+ "Research",
2203
+ "Add section",
2204
+ "Optional",
2205
+ "Footer",
2206
+ ]);
2207
+ });
2208
+
2209
+ it("AC121 · on opening the Optional Section, the screen explains that it comes out as Optional, the section an agent can skip, and only if it has Pages", async () => {
2210
+ await renderScreen();
2211
+ await openOptional();
2212
+
2213
+ const help = screen.getByTestId("llms-optional-help").textContent;
2214
+ expect(help).toContain("«Optional»");
2215
+ expect(help).toContain("can skip");
2216
+ expect(help).toContain("Only appears if it has pages");
2217
+ });
2218
+
2219
+ it("AC122 · an automatic LLM Index Section does not offer adding a Branch filter", async () => {
2220
+ await renderScreen({ settings: makeSettings({ sections: [automatic("Degrees")] }) });
2221
+ await openSection("Degrees");
2222
+
2223
+ const menu = await openAddFilter();
2224
+
2225
+ // Without any filter yet, every other axis is offered: the Branch is missing because it is not offered.
2226
+ expect(
2227
+ within(menu)
2228
+ .getAllByRole("button")
2229
+ .map((option) => option.textContent),
2230
+ ).toEqual(["Template", "Site", "Language"]);
2231
+ });
2232
+
2233
+ it("AC123 · the limit of an automatic LLM Index Section is chosen in Pages: all those it takes, or a number of them", async () => {
2234
+ await renderScreen({ settings: makeSettings({ sections: [automatic("News")] }) });
2235
+ await openSection("News");
2236
+
2237
+ expect(within(inspector()).getByText("Number of pages")).toBeInTheDocument();
2238
+ expect(within(inspector()).getByText("All pages")).toBeInTheDocument();
2239
+ expect(within(inspector()).getByText("Choose number of pages")).toBeInTheDocument();
2240
+ // Not in items, the word of the distributor, whose subject is not the Page.
2241
+ expect(within(inspector()).queryAllByText(/items/i)).toHaveLength(0);
2242
+ });
2243
+
2244
+ it("AC124 · an automatic LLM Index Section without filters invites the editor to add them to refine its selection", async () => {
2245
+ await renderScreen({ settings: makeSettings({ sections: [automatic("News")] }) });
2246
+ await openSection("News");
2247
+ const invitation = "Add filters to refine the selection";
2248
+
2249
+ expect(within(inspector()).getByText(invitation)).toBeInTheDocument();
2250
+
2251
+ // Only without filters: with one, the invitation goes.
2252
+ await addFilter("Template");
2253
+ expect(within(inspector()).queryByText(invitation)).toBeNull();
2254
+ });
2255
+
2256
+ it("AC125 · an LLM Index Section with no name, not counting the Optional Section, cannot be saved: its name is marked required, and saving is not offered until it is written", async () => {
2257
+ await renderScreen({ settings: makeSettings({ sections: [manual("Programs")] }) });
2258
+ await openSection("Programs");
2259
+
2260
+ // Marked required from the start, like the other required fields of AX.
2261
+ expect(within(screen.getByText("Section name")).getByText("*")).toBeInTheDocument();
2262
+
2263
+ await write(field("llmsSectionName"), "");
2264
+ expect(screen.getByRole("button", { name: "Save" })).toBeDisabled();
2265
+ fireEvent.blur(field("llmsSectionName"));
2266
+ expect(screen.getByText("Please, fill me. This field is required.")).toBeInTheDocument();
2267
+ // Blanks only are no name either, as for the outline.
2268
+ await write(field("llmsSectionName"), " ");
2269
+ expect(screen.getByRole("button", { name: "Save" })).toBeDisabled();
2270
+
2271
+ // The Optional Section, which the model carries without a name, does not stop it.
2272
+ await write(field("llmsSectionName"), "Degrees");
2273
+ expect((await save()).index.sections[0]).toEqual(manual("Degrees"));
2274
+ });
2275
+
2276
+ it("AC126 · an empty footer, or one with blanks only, travels without text in the model sent", async () => {
2277
+ await renderScreen({ settings: makeSettings({ footer: { content: "Write to info@example.edu" } }) });
2278
+ await openItem(screen.getByTestId("llms-outline-footer"));
2279
+
2280
+ await write(field("llmsFooterContent"), "");
2281
+ // Absent, not an empty string.
2282
+ expect((await save()).index.footer).toEqual({});
2283
+
2284
+ await write(field("llmsFooterContent"), "Write to info@example.edu");
2285
+ expect((await save()).index.footer).toEqual({ content: "Write to info@example.edu" });
2286
+
2287
+ await write(field("llmsFooterContent"), " \n\t ");
2288
+ expect((await save()).index.footer).toEqual({});
2289
+ });
2290
+
2291
+ it("AC127 · the footer field says that, if it does not start with a heading of its own (## ), the footer reads as part of the last LLM Index Section", async () => {
2292
+ await renderScreen();
2293
+ await openItem(screen.getByTestId("llms-outline-footer"));
2294
+
2295
+ const footer = screen.getByRole("region", { name: "Footer" });
2296
+ const help = within(footer).getByText(/reads as part of the last section/).textContent;
2297
+ expect(help).toContain("start it with a heading such as «## ");
2298
+ });
2299
+
2300
+ it("AC128 · the list of what an automatic LLM Index Section takes, the Optional Section included, shows its Pages 50 at a time, in the order the LLM Index lists them, with a paginator below if it takes more than 50", async () => {
2301
+ await renderScreen({
2302
+ settings: makeSettings({
2303
+ sections: [automatic("News"), automatic("Events")],
2304
+ optionalSection: optionalAutomatic(),
2305
+ }),
2306
+ sectionPages: (asked) => takes(asked.section === 0 ? 120 : asked.section === 1 ? 50 : 51)(asked),
2307
+ });
2308
+
2309
+ await openSection("News");
2310
+ await settle();
2311
+
2312
+ // The first 50, in the order the answer gives them, which is the one the LLM Index lists them in.
2313
+ await waitFor(() => expect(shownIds()).toEqual(range(1, 50)));
2314
+ expect(lastListed()).toMatchObject({ section: 0, page: 1, itemsPerPage: 50 });
2315
+ expect(paginatorSays()).toBe("Page 1 of 3");
2316
+ const rows = screen.getAllByTestId("llms-resolved-page");
2317
+ expect(
2318
+ rows[49].compareDocumentPosition(paginator() as HTMLElement) & Node.DOCUMENT_POSITION_FOLLOWING,
2319
+ ).toBeTruthy();
2320
+
2321
+ // Exactly 50: a single slice, with no paginator.
2322
+ await openSection("Events");
2323
+ await settle();
2324
+ await waitFor(() => expect(shownIds()).toEqual(range(1, 50)));
2325
+ expect(paginator()).toBeNull();
2326
+
2327
+ await openOptional();
2328
+ await settle();
2329
+ await waitFor(() => expect(shownIds()).toEqual(range(1, 50)));
2330
+ expect(lastListed()).toMatchObject({ section: "optional", page: 1, itemsPerPage: 50 });
2331
+ expect(paginatorSays()).toBe("Page 1 of 2");
2332
+ });
2333
+
2334
+ it("AC129 · the header of that list says how many Pages the section takes in all, not how many the open slice shows", async () => {
2335
+ const header = "120 pages, in the order the llms.txt lists them.";
2336
+ await renderScreen({ settings: makeSettings({ sections: [automatic("News")] }), sectionPages: takes(120) });
2337
+ await openSection("News");
2338
+ await settle();
2339
+ await waitFor(() => expect(resolvedPages()).toHaveLength(50));
2340
+
2341
+ expect(within(inspector()).getByText(header)).toBeInTheDocument();
2342
+ expect(within(inspector()).queryByText(/^50 pages/)).toBeNull();
2343
+
2344
+ // Also on the last slice, which shows fewer.
2345
+ await nextSlice();
2346
+ await nextSlice();
2347
+ await waitFor(() => expect(shownIds()).toEqual(range(101, 120)));
2348
+ expect(within(inspector()).getByText(header)).toBeInTheDocument();
2349
+ });
2350
+
2351
+ it("AC130 · changing the slice with the paginator asks for that slice right away, without waiting for the editor to stop changing anything", async () => {
2352
+ await renderScreen({ settings: makeSettings({ sections: [automatic("News")] }), sectionPages: takes(120) });
2353
+ await openSection("News");
2354
+ await settle();
2355
+ await waitFor(() => expect(resolvedPages()).toHaveLength(50));
2356
+ const asked = listings().length;
2357
+
2358
+ await nextSlice();
2359
+
2360
+ // Already asked for, with no wait in between.
2361
+ expect(listings()).toHaveLength(asked + 1);
2362
+ expect(lastListed()).toMatchObject({ section: 0, page: 2, itemsPerPage: 50 });
2363
+ await waitFor(() => expect(shownIds()).toEqual(range(51, 100)));
2364
+ expect(paginatorSays()).toBe("Page 2 of 3");
2365
+ });
2366
+
2367
+ it("AC131 · a change in what the editor has on screen that asks for the list again takes it back to its first slice", async () => {
2368
+ await renderScreen({ settings: makeSettings({ sections: [automatic("News")] }), sectionPages: takes(120) });
2369
+ await openSection("News");
2370
+ await settle();
2371
+ await waitFor(() => expect(resolvedPages()).toHaveLength(50));
2372
+ await nextSlice();
2373
+ await waitFor(() => expect(shownIds()).toEqual(range(51, 100)));
2374
+
2375
+ await choose("llmsGlobalOperator", "OR");
2376
+ await settle();
2377
+
2378
+ await waitFor(() => expect(shownIds()).toEqual(range(1, 50)));
2379
+ expect(lastListed()).toMatchObject({ page: 1 });
2380
+ expect(lastListed().settings.index.sections[0]).toEqual(automatic("News", { globalOperator: "OR" }));
2381
+ expect(paginatorSays()).toBe("Page 1 of 3");
2382
+ });
2383
+
2384
+ it("AC132 · the list of an automatic LLM Index Section without a name shows the Pages it takes, even though the section does not come out in the LLM Index", async () => {
2385
+ await renderScreen({
2386
+ settings: makeSettings({ sections: [automatic("")] }),
2387
+ sectionPages: () => sectionSlice([1, 2]),
2388
+ });
2389
+
2390
+ await openSection("Untitled section");
2391
+ await settle();
2392
+
2393
+ await waitFor(() => expect(shownIds()).toEqual([1, 2]));
2394
+ expect(lastListed().section).toBe(0);
2395
+ expect(lastListed().settings.index.sections[0].name).toBe("");
2396
+ expect(within(inspector()).queryByText(/does not come out/)).toBeNull();
2397
+ });
2398
+
2399
+ it("AC133 · the total in the header is the one of the last answer: on changing the slice, it says the one that slice brings, even if it does not match the previous one", async () => {
2400
+ // Between one slice and the next, the section came to take fewer Pages.
2401
+ await renderScreen({
2402
+ settings: makeSettings({ sections: [automatic("News")] }),
2403
+ sectionPages: (asked) => takes(asked.page === 1 ? 120 : 101)(asked),
2404
+ });
2405
+ await openSection("News");
2406
+ await settle();
2407
+ await within(inspector()).findByText("120 pages, in the order the llms.txt lists them.");
2408
+
2409
+ await nextSlice();
2410
+
2411
+ expect(
2412
+ await within(inspector()).findByText("101 pages, in the order the llms.txt lists them."),
2413
+ ).toBeInTheDocument();
2414
+ expect(shownIds()).toEqual(range(51, 100));
2415
+ });
2416
+
2417
+ it("AC134 · if the answer to a slice asked before arrives after the answer to one asked later, the list keeps the one asked later", async () => {
2418
+ let answerSecond: () => void = () => {};
2419
+ await renderScreen({
2420
+ settings: makeSettings({ sections: [automatic("News")] }),
2421
+ sectionPages: (asked) =>
2422
+ asked.page === 2
2423
+ ? new Promise((resolve) => {
2424
+ answerSecond = () => resolve(takes(150)(asked));
2425
+ })
2426
+ : takes(150)(asked),
2427
+ });
2428
+ await openSection("News");
2429
+ await settle();
2430
+ await waitFor(() => expect(resolvedPages()).toHaveLength(50));
2431
+
2432
+ // The second slice is still on its way when the editor moves on to the third.
2433
+ await nextSlice();
2434
+ await nextSlice();
2435
+ await waitFor(() => expect(shownIds()).toEqual(range(101, 150)));
2436
+ await act(async () => {
2437
+ answerSecond();
2438
+ });
2439
+
2440
+ expect(shownIds()).toEqual(range(101, 150));
2441
+ expect(paginatorSays()).toBe("Page 3 of 3");
2442
+ });
2443
+
2444
+ it("AC135 · while the chosen slice is on its way, the list says it is asking for it and shows no Pages of another slice", async () => {
2445
+ let answerSecond: () => void = () => {};
2446
+ await renderScreen({
2447
+ settings: makeSettings({ sections: [automatic("News")] }),
2448
+ sectionPages: (asked) =>
2449
+ asked.page === 2
2450
+ ? new Promise((resolve) => {
2451
+ answerSecond = () => resolve(takes(120)(asked));
2452
+ })
2453
+ : takes(120)(asked),
2454
+ });
2455
+ await openSection("News");
2456
+ await settle();
2457
+ await waitFor(() => expect(shownIds()).toEqual(range(1, 50)));
2458
+
2459
+ await nextSlice();
2460
+
2461
+ expect(within(inspector()).getByText("Loading the pages…")).toBeInTheDocument();
2462
+ expect(resolvedPages()).toHaveLength(0);
2463
+
2464
+ // Until it arrives: then the list shows it, and says no more that it is asking.
2465
+ await act(async () => {
2466
+ answerSecond();
2467
+ });
2468
+ await waitFor(() => expect(shownIds()).toEqual(range(51, 100)));
2469
+ expect(within(inspector()).queryByText("Loading the pages…")).toBeNull();
2470
+ });
2471
+
2472
+ it("AC136 · while the chosen slice is on its way, the list still says the total and shows the paginator: the editor can ask for another slice without waiting for it", async () => {
2473
+ await renderScreen({
2474
+ settings: makeSettings({ sections: [automatic("News")] }),
2475
+ // The second slice never arrives.
2476
+ sectionPages: (asked) => (asked.page === 2 ? new Promise(() => {}) : takes(150)(asked)),
2477
+ });
2478
+ await openSection("News");
2479
+ await settle();
2480
+ await waitFor(() => expect(resolvedPages()).toHaveLength(50));
2481
+
2482
+ await nextSlice();
2483
+
2484
+ expect(within(inspector()).getByText("150 pages, in the order the llms.txt lists them.")).toBeInTheDocument();
2485
+ expect(paginatorSays()).toBe("Page 2 of 3");
2486
+
2487
+ await nextSlice();
2488
+
2489
+ expect(lastListed()).toMatchObject({ page: 3 });
2490
+ await waitFor(() => expect(shownIds()).toEqual(range(101, 150)));
2491
+ });
2492
+
2493
+ it("AC137 · the header fields —title, summary and detail—, the name of an LLM Index Section and the footer show, while empty, an example of what they take", async () => {
2494
+ await renderScreen({ settings: makeSettings({ sections: [manual("Programs")] }) });
2495
+
2496
+ expect(field("llmsTitle").placeholder).toBe("e.g. Example University");
2497
+ expect(field("llmsSummary").placeholder).toBe("e.g. Degrees, masters and research programmes");
2498
+ expect(field("llmsDetail").placeholder).toBe("e.g. Admissions open in March; fees are on each programme page");
2499
+
2500
+ await openSection("Programs");
2501
+
2502
+ expect(field("llmsSectionName").placeholder).toBe("e.g. Degrees");
2503
+
2504
+ await openItem(screen.getByTestId("llms-outline-footer"));
2505
+
2506
+ expect(field("llmsFooterContent").placeholder).toBe("## Contact\nWrite to info@example.edu");
2507
+ });
2508
+
2509
+ it("AC138 · choosing the header, an LLM Index Section or the footer in the outline, or adding a section, leaves the focus on its text field: the title, the name of the section or the content of the footer", async () => {
2510
+ await renderScreen({ settings: makeSettings({ sections: [manual("Programs")] }) });
2511
+
2512
+ await openSection("Programs");
2513
+ expect(document.activeElement).toBe(field("llmsSectionName"));
2514
+
2515
+ await openItem(screen.getByTestId("llms-outline-footer"));
2516
+ expect(document.activeElement).toBe(field("llmsFooterContent"));
2517
+
2518
+ await openHeader();
2519
+ expect(document.activeElement).toBe(field("llmsTitle"));
2520
+
2521
+ // Also when it is the one already open.
2522
+ field("llmsTitle").blur();
2523
+ await openHeader();
2524
+ expect(document.activeElement).toBe(field("llmsTitle"));
2525
+
2526
+ await click(screen.getByRole("button", { name: "Add section" }));
2527
+ expect(document.activeElement).toBe(field("llmsSectionName"));
2528
+ expect(field("llmsSectionName").value).toBe("");
2529
+ });
2530
+
2531
+ it.each([
2532
+ {
2533
+ list: "the page search",
2534
+ rows: "llms-picker-page",
2535
+ open: async () => {
2536
+ await renderScreen({
2537
+ settings: makeSettings({ sections: [manual("Programs")] }),
2538
+ search: [makePage(1, { title: LONG_TITLE }), makePage(2)],
2539
+ });
2540
+ await openSection("Programs");
2541
+ await click(screen.getByRole("button", { name: "Add pages" }));
2542
+ },
2543
+ },
2544
+ {
2545
+ list: "the Pages chosen by hand",
2546
+ rows: "llms-section-page",
2547
+ open: async () => {
2548
+ await renderScreen({
2549
+ settings: makeSettings({ sections: [manual("Programs", [1, 2])] }),
2550
+ known: [makePage(1, { title: LONG_TITLE }), makePage(2)],
2551
+ });
2552
+ await openSection("Programs");
2553
+ },
2554
+ },
2555
+ {
2556
+ list: "the Pages the automatic Optional Section takes",
2557
+ rows: "llms-resolved-page",
2558
+ open: async () => {
2559
+ await renderScreen({
2560
+ settings: makeSettings({ optionalSection: optionalAutomatic() }),
2561
+ sectionPages: () =>
2562
+ ok({
2563
+ enabled: true,
2564
+ pages: { totalItems: 2, items: [{ ...indexPage(1), title: LONG_TITLE }, indexPage(2)] },
2565
+ sites: SITES,
2566
+ }),
2567
+ });
2568
+ await openOptional();
2569
+ await settle();
2570
+ },
2571
+ },
2572
+ ])(
2573
+ "AC139 · in $list, the title of a Page that does not fit in its row is cut, and only then reads whole on hovering it",
2574
+ async ({ rows, open }) => {
2575
+ layOutTitles();
2576
+ await open();
2577
+ await waitFor(() => expect(screen.getAllByTestId(rows)).toHaveLength(2));
2578
+ const [cut, fits] = screen.getAllByTestId(rows);
2579
+
2580
+ const [title] = within(cut).getAllByText(LONG_TITLE);
2581
+ expect(getComputedStyle(title)).toMatchObject({
2582
+ overflow: "hidden",
2583
+ textOverflow: "ellipsis",
2584
+ whiteSpace: "nowrap",
2585
+ });
2586
+ expect(within(fits).queryByTestId("tooltip-component")).toBeNull();
2587
+
2588
+ const tip = within(cut).getByTestId("tip-component");
2589
+ expect(tip.textContent).toBe(LONG_TITLE);
2590
+ expect(tip).not.toBeVisible();
2591
+
2592
+ fireEvent.mouseEnter(within(cut).getByTestId("tooltip-component"));
2593
+ // The tooltip waits a second before it shows.
2594
+ await act(async () => {
2595
+ await new Promise((resolve) => setTimeout(resolve, 1100));
2596
+ });
2597
+ expect(tip).toBeVisible();
2598
+ },
2599
+ );
2600
+ });
2601
+
2602
+ /** The common options, the ones the list edits for every domain. */
2603
+ const COMMON_OPTIONS = [
2604
+ "markdownMainOnly",
2605
+ "markdownIncludeNav",
2606
+ "markdownFrontMatter",
2607
+ "markdownDiscoveryLinks",
2608
+ "markdownLinkToMarkdown",
2609
+ ];
2610
+
2611
+ /** The domains of the screen when the options go to more than one. */
2612
+ const TWO_DOMAINS = { domains: [DOMAIN, OTHER_DOMAIN] };
2613
+
2614
+ /** The block of the list where the options common to every domain are edited. */
2615
+ const mirrorPanel = () => screen.getByRole("region", { name: "Markdown mirror" });
2616
+
2617
+ /** What the example beside the common options shows: the mirror of a made-up page and its head. */
2618
+ const example = () => ({
2619
+ markdown: screen.getByTestId("llms-mirror-example-markdown").textContent ?? "",
2620
+ head: screen.getByTestId("llms-mirror-example-head").textContent ?? "",
2621
+ });
2622
+
2623
+ /** Saves the common options and waits for the document of each domain. */
2624
+ const saveMirror = async (ids: number[] = [DOMAIN.id]) => {
2625
+ await click(screen.getByRole("button", { name: "Save" }));
2626
+ await waitFor(() => {
2627
+ for (const id of ids) expect(putsTo(id)).toHaveLength(1);
2628
+ });
2629
+ };
2630
+
2631
+ describe("[UC-AX-configure-markdown-mirror] the markdown mirror options common to every domain, end to end", () => {
2632
+ it("AC1 · the editor switches the writing of Markdown Mirrors of a Domain on or off from that Domain open, and the settings sent to it reflect it", async () => {
2633
+ await renderList(TWO_DOMAINS);
2634
+ await openDomain();
2635
+
2636
+ await toggle("markdownEnabled");
2637
+
2638
+ expect((await save()).markdown.enabled).toBe(false);
2639
+ expect(putsTo(OTHER_DOMAIN.id)).toHaveLength(0);
2640
+ });
2641
+
2642
+ it("AC3 · the common options are edited also when no Domain writes Markdown Mirrors", async () => {
2643
+ await renderList({ settings: makeSettings({}, { enabled: false }) });
2644
+
2645
+ for (const name of COMMON_OPTIONS) expect(field(name)).toBeEnabled();
2646
+ await toggle("markdownIncludeNav");
2647
+ await saveMirror();
2648
+
2649
+ expect(putsTo(DOMAIN.id)[0].markdown).toEqual({ ...MIRROR, enabled: false, includeNav: false });
2650
+ });
2651
+
2652
+ it("AC6 · switching the mirror of a Domain off does not change its options: the ones it had saved are sent", async () => {
2653
+ await renderScreen();
2654
+
2655
+ await toggle("markdownEnabled");
2656
+
2657
+ expect((await save()).markdown).toEqual({ ...MIRROR, enabled: false });
2658
+ });
2659
+
2660
+ it("AC7 · the screen does not show what the Markdown Mirror does with the images nor whether its internal links are absolute, and always sends each image kept once and the links absolute", async () => {
2661
+ await renderList({ settings: makeSettings({}, { images: "skip", absoluteLinks: false }) });
2662
+
2663
+ expect(document.querySelector('[name="markdownImages"]')).toBeNull();
2664
+ expect(document.querySelector('[name="markdownAbsoluteLinks"]')).toBeNull();
2665
+ await toggle("markdownIncludeNav");
2666
+ await saveMirror();
2667
+
2668
+ expect(putsTo(DOMAIN.id)[0].markdown).toEqual({
2669
+ ...MIRROR,
2670
+ includeNav: false,
2671
+ images: "dedupe",
2672
+ absoluteLinks: true,
2673
+ });
2674
+ });
2675
+
2676
+ it("AC8 · options saved with other values for those two open without unsaved changes", async () => {
2677
+ await renderList({ settings: makeSettings({}, { images: "keep", absoluteLinks: false }) });
2678
+
2679
+ expect(screen.getByRole("button", { name: "Saved" })).toBeDisabled();
2680
+ });
2681
+
2682
+ it("AC9 · the options are edited once, beside the list of Domains, and open with what the first Domain of the list whose settings could be read has saved", async () => {
2683
+ await renderList({
2684
+ domains: [OTHER_DOMAIN, DOMAIN],
2685
+ failures: { [OTHER_DOMAIN.id]: Number.POSITIVE_INFINITY },
2686
+ settingsOf: { [DOMAIN.id]: makeSettings({}, { includeNav: false, frontMatter: true }) },
2687
+ });
2688
+
2689
+ expect(mirrorPanel().querySelectorAll('input[type="checkbox"]')).toHaveLength(COMMON_OPTIONS.length);
2690
+ expect(within(mirrorPanel()).queryByText("Write a markdown mirror of each page")).toBeNull();
2691
+ expect(field("markdownIncludeNav").checked).toBe(false);
2692
+ expect(field("markdownFrontMatter").checked).toBe(true);
2693
+ expect(field("markdownDiscoveryLinks").checked).toBe(true);
2694
+ });
2695
+
2696
+ it("AC10 · saving the common options sends each Domain its whole LLM Surface Settings: its LLM Index Model and whether it writes Markdown Mirrors, as it has them saved, and the common options", async () => {
2697
+ const first = makeSettings({ texts: { title: "Main" }, sections: [manual("Programs", [10])] });
2698
+ const second = makeSettings({ enabled: false, sections: [automatic("News", { quantity: 5 })] }, { enabled: false });
2699
+ await renderList({ ...TWO_DOMAINS, settingsOf: { [DOMAIN.id]: first, [OTHER_DOMAIN.id]: second } });
2700
+
2701
+ await toggle("markdownLinkToMarkdown");
2702
+ await saveMirror([DOMAIN.id, OTHER_DOMAIN.id]);
2703
+
2704
+ const markdown = { ...MIRROR, linkToMarkdown: true };
2705
+ expect(putsTo(DOMAIN.id)).toEqual([{ index: first.index, markdown }]);
2706
+ expect(putsTo(OTHER_DOMAIN.id)).toEqual([{ index: second.index, markdown: { ...markdown, enabled: false } }]);
2707
+ });
2708
+
2709
+ it("AC11 · the open LLM Index Model of a Domain does not show the common Markdown Mirror options", async () => {
2710
+ await renderScreen();
2711
+
2712
+ for (const name of COMMON_OPTIONS) expect(document.querySelector(`[name="${name}"]`)).toBeNull();
2713
+ expect(screen.queryByRole("region", { name: "Markdown mirror" })).toBeNull();
2714
+ });
2715
+
2716
+ it("AC12 · if the settings of some Domain could not be read or have not arrived yet, the options cannot be saved and the screen says so", async () => {
2717
+ const notice = "The markdown mirror options can only be saved once the settings of every domain have been read.";
2718
+
2719
+ await renderList({ ...TWO_DOMAINS, failures: { [OTHER_DOMAIN.id]: Number.POSITIVE_INFINITY } });
2720
+ await toggle("markdownIncludeNav");
2721
+ expect(screen.getByRole("button", { name: "Save" })).toBeDisabled();
2722
+ expect(within(mirrorPanel()).getByText(notice)).toBeInTheDocument();
2723
+ cleanup();
2724
+ mockedAxios.mockReset();
2725
+
2726
+ await renderList({ ...TWO_DOMAINS, pending: [OTHER_DOMAIN.id] });
2727
+ await toggle("markdownIncludeNav");
2728
+ expect(screen.getByRole("button", { name: "Save" })).toBeDisabled();
2729
+ expect(within(mirrorPanel()).getByText(notice)).toBeInTheDocument();
2730
+ expect(requests("PUT", /llms-settings$/)).toHaveLength(0);
2731
+ });
2732
+
2733
+ it("AC13 · if saving fails in some Domain, it is reported, and the options keep their unsaved changes", async () => {
2734
+ await renderList({ ...TWO_DOMAINS, saveFailures: [OTHER_DOMAIN.id] });
2735
+
2736
+ await toggle("markdownIncludeNav");
2737
+ await saveMirror([DOMAIN.id, OTHER_DOMAIN.id]);
2738
+
2739
+ await waitFor(() => expect(store.getState().app.error.text).toBe("The server could not do it"));
2740
+ expect(screen.getByRole("button", { name: "Save" })).toBeEnabled();
2741
+ expect(field("markdownIncludeNav").checked).toBe(false);
2742
+ });
2743
+
2744
+ it("AC15 · with unsaved changes in the options, leaving the screen asks for confirmation before discarding them", async () => {
2745
+ await renderList();
2746
+ await toggle("markdownIncludeNav");
2747
+
2748
+ await act(async () => {
2749
+ history.push("/settings/robots");
2750
+ });
2751
+
2752
+ expect(screen.getByText(/Some LLM settings/)).toBeInTheDocument();
2753
+ expect(history.location.pathname).toBe("/settings/llms");
2754
+ });
2755
+
2756
+ it("AC16 · the unsaved changes in the options are kept when a Domain is opened and the editor goes back to the list", async () => {
2757
+ await renderList();
2758
+ await toggle("markdownIncludeNav");
2759
+
2760
+ await openDomain();
2761
+ await click(screen.getByRole("button", { name: "LLMs.txt editor" }));
2762
+
2763
+ expect(field("markdownIncludeNav").checked).toBe(false);
2764
+ expect(screen.getByRole("button", { name: "Save" })).toBeEnabled();
2765
+ });
2766
+
2767
+ it("AC17 · saving an open Domain sends it the options it has saved, not the unsaved changes of the common options", async () => {
2768
+ await renderList();
2769
+ await toggle("markdownIncludeNav");
2770
+ await openDomain();
2771
+
2772
+ await write(field("llmsTitle"), "Main");
2773
+
2774
+ expect((await save()).markdown).toEqual(MIRROR);
2775
+ });
2776
+
2777
+ it("AC18 · with no Domain, the screen does not show the options", async () => {
2778
+ serveApi({ domains: [] });
2779
+ await act(async () => {
2780
+ render(
2781
+ <Router history={history}>
2782
+ <ThemeProvider theme={theme}>
2783
+ <Llms navItems={navItems} currentNavItem={navItems[1]} />
2784
+ </ThemeProvider>
2785
+ </Router>,
2786
+ { store: makeStore() },
2787
+ );
2788
+ });
2789
+ await screen.findByText("There are no domains to configure.");
2790
+
2791
+ expect(screen.queryByRole("region", { name: "Markdown mirror" })).toBeNull();
2792
+ expect(document.querySelector('[name="markdownEnabled"]')).toBeNull();
2793
+ });
2794
+
2795
+ it("AC20 · after saving a Domain, the list says whether it writes Markdown Mirrors with what was saved", async () => {
2796
+ await renderScreen();
2797
+ await toggle("markdownEnabled");
2798
+ await save();
2799
+
2800
+ await click(screen.getByRole("button", { name: "LLMs.txt editor" }));
2801
+
2802
+ expect(within(domainRow("www.example.edu")).getByTestId("llms-domain-mirror").textContent).toBe("Off");
2803
+ });
2804
+
2805
+ it("AC21 · beside the common options, an example shows the Markdown Mirror of a made-up Page opening with its metadata header when that option is on on screen, and without it when it is off", async () => {
2806
+ await renderList({ settings: makeSettings({}, { frontMatter: true }) });
2807
+ expect(example().markdown.startsWith("---\ntitle: ")).toBe(true);
2808
+
2809
+ await toggle("markdownFrontMatter");
2810
+
2811
+ expect(example().markdown).not.toContain("title: ");
2812
+ expect(example().markdown.startsWith("## Navigation")).toBe(true);
2813
+ });
2814
+
2815
+ it("AC22 · the example carries the navigation section before the content when that option is on on screen, and does not carry it when it is off", async () => {
2816
+ await renderList({ settings: makeSettings({}, { includeNav: true, frontMatter: false }) });
2817
+ const { markdown } = example();
2818
+ expect(markdown.indexOf("## Navigation")).toBeGreaterThanOrEqual(0);
2819
+ expect(markdown.indexOf("## Navigation")).toBeLessThan(markdown.indexOf("# Degrees"));
2820
+
2821
+ await toggle("markdownIncludeNav");
2822
+
2823
+ expect(example().markdown).not.toContain("## Navigation");
2824
+ expect(example().markdown.startsWith("# Degrees")).toBe(true);
2825
+ });
2826
+
2827
+ it("AC23 · the internal links of the example lead to the other Page's Markdown Mirror or to the Page itself as the option says on screen, always absolute", async () => {
2828
+ await renderList({ settings: makeSettings({}, { linkToMarkdown: true }) });
2829
+ expect(example().markdown).toContain("[apply](https://www.example.edu/admissions/index.md)");
2830
+
2831
+ await toggle("markdownLinkToMarkdown");
2832
+
2833
+ expect(example().markdown).toContain("[apply](https://www.example.edu/admissions/)");
2834
+ expect(example().markdown).not.toContain("index.md)");
2835
+ });
2836
+
2837
+ it("AC24 · the example shows the Discovery Links the Page would announce when that option is on on screen, and says it announces none when it is off", async () => {
2838
+ await renderList({ settings: makeSettings({}, { discoveryLinks: true }) });
2839
+ expect(example().head).toContain(
2840
+ '<link rel="alternate" type="text/markdown" href="https://www.example.edu/degrees/index.md">',
2841
+ );
2842
+ expect(example().head).toContain(
2843
+ '<link rel="describedby" type="text/plain" href="https://www.example.edu/llms.txt">',
2844
+ );
2845
+
2846
+ await toggle("markdownDiscoveryLinks");
2847
+
2848
+ expect(example().head).not.toContain("<link");
2849
+ expect(example().head).toContain("The page announces no discovery links.");
2850
+ });
2851
+
2852
+ it("AC25 · the example closes with the footer of the Page when the option on screen converts the whole Page, and ends with its content when it converts only the main region", async () => {
2853
+ await renderList({ settings: makeSettings({}, { mainOnly: false }) });
2854
+ expect(example().markdown.endsWith("© Example University · All rights reserved")).toBe(true);
2855
+
2856
+ await toggle("markdownMainOnly");
2857
+
2858
+ expect(example().markdown).not.toContain("© Example University");
2859
+ expect(example().markdown.endsWith("read how to [apply](https://www.example.edu/admissions/).")).toBe(true);
2860
+ });
2861
+ });