| 
									
										
										
										
											2025-03-19 17:53:31 +02:00
										 |  |  | import { describe, expect, it } from "vitest"; | 
					
						
							|  |  |  | import { byBookType, byNoteType } from "./help_button.js"; | 
					
						
							|  |  |  | import fs from "fs"; | 
					
						
							| 
									
										
										
										
											2025-04-18 10:46:43 +03:00
										 |  |  | import type { HiddenSubtreeItem } from "@triliumnext/commons"; | 
					
						
							| 
									
										
										
										
											2025-04-29 10:57:15 +03:00
										 |  |  | import path from "path"; | 
					
						
							| 
									
										
										
										
											2025-03-19 17:53:31 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | describe("Help button", () => { | 
					
						
							|  |  |  |     it("All help notes are accessible", () => { | 
					
						
							| 
									
										
										
										
											2025-04-12 09:16:20 +03:00
										 |  |  |         function getNoteIds(item: HiddenSubtreeItem | HiddenSubtreeItem[]): string[] { | 
					
						
							|  |  |  |             const items: (string | string[])[] = []; | 
					
						
							| 
									
										
										
										
											2025-03-19 17:53:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-12 09:16:20 +03:00
										 |  |  |             if ("id" in item && item.id) { | 
					
						
							|  |  |  |                 items.push(item.id); | 
					
						
							| 
									
										
										
										
											2025-03-19 17:53:31 +02:00
										 |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-12 09:16:20 +03:00
										 |  |  |             const subitems = (Array.isArray(item) ? item : item.children); | 
					
						
							|  |  |  |             for (const child of subitems ?? []) { | 
					
						
							|  |  |  |                 items.push(getNoteIds(child as (HiddenSubtreeItem | HiddenSubtreeItem[]))); | 
					
						
							| 
									
										
										
										
											2025-03-19 17:53:31 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |             return items.flat(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const allHelpNotes = [ | 
					
						
							|  |  |  |             ...Object.values(byNoteType), | 
					
						
							|  |  |  |             ...Object.values(byBookType) | 
					
						
							|  |  |  |         ].filter((noteId) => noteId) as string[]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-29 10:57:15 +03:00
										 |  |  |         const metaPath = path.resolve(path.join(__dirname, "../../../../server/src/public/app/doc_notes/en/User Guide/!!!meta.json")); | 
					
						
							|  |  |  |         const meta: HiddenSubtreeItem[] = JSON.parse(fs.readFileSync(metaPath, "utf-8")); | 
					
						
							| 
									
										
										
										
											2025-03-19 17:53:31 +02:00
										 |  |  |         const allNoteIds = new Set(getNoteIds(meta)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (const helpNote of allHelpNotes) { | 
					
						
							| 
									
										
										
										
											2025-04-12 09:16:20 +03:00
										 |  |  |             if (!allNoteIds.has(`_help_${helpNote}`)) { | 
					
						
							| 
									
										
										
										
											2025-03-19 17:53:31 +02:00
										 |  |  |                 expect.fail(`Help note with ID ${helpNote} does not exist in the in-app help.`); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | }); |