fix(test): help buttons ID check after change in structure

This commit is contained in:
Elian Doran 2025-04-12 09:16:20 +03:00
parent 2cd69cc57a
commit 3c88e3c12c
No known key found for this signature in database

View File

@ -1,21 +1,20 @@
import { describe, expect, it } from "vitest"; import { describe, expect, it } from "vitest";
import { byBookType, byNoteType } from "./help_button.js"; import { byBookType, byNoteType } from "./help_button.js";
import fs from "fs"; import fs from "fs";
import type { NoteMetaFile } from "../../../../services/meta/note_meta.js"; import type { HiddenSubtreeItem } from "../../../../services/hidden_subtree.js";
import type NoteMeta from "../../../../services/meta/note_meta.js";
describe("Help button", () => { describe("Help button", () => {
it("All help notes are accessible", () => { it("All help notes are accessible", () => {
function getNoteIds(item: NoteMeta | NoteMetaFile): string[] { function getNoteIds(item: HiddenSubtreeItem | HiddenSubtreeItem[]): string[] {
const items = []; const items: (string | string[])[] = [];
if ("noteId" in item && item.noteId) { if ("id" in item && item.id) {
items.push(item.noteId); items.push(item.id);
} }
const children = "files" in item ? item.files : item.children; const subitems = (Array.isArray(item) ? item : item.children);
for (const child of children ?? []) { for (const child of subitems ?? []) {
items.push(getNoteIds(child)); items.push(getNoteIds(child as (HiddenSubtreeItem | HiddenSubtreeItem[])));
} }
return items.flat(); return items.flat();
} }
@ -25,11 +24,11 @@ describe("Help button", () => {
...Object.values(byBookType) ...Object.values(byBookType)
].filter((noteId) => noteId) as string[]; ].filter((noteId) => noteId) as string[];
const meta: NoteMetaFile = JSON.parse(fs.readFileSync("src/public/app/doc_notes/en/User Guide/!!!meta.json", "utf-8")); const meta: HiddenSubtreeItem[] = JSON.parse(fs.readFileSync("src/public/app/doc_notes/en/User Guide/!!!meta.json", "utf-8"));
const allNoteIds = new Set(getNoteIds(meta)); const allNoteIds = new Set(getNoteIds(meta));
for (const helpNote of allHelpNotes) { for (const helpNote of allHelpNotes) {
if (!allNoteIds.has(helpNote)) { if (!allNoteIds.has(`_help_${helpNote}`)) {
expect.fail(`Help note with ID ${helpNote} does not exist in the in-app help.`); expect.fail(`Help note with ID ${helpNote} does not exist in the in-app help.`);
} }
} }