Skip to content

Build your personal knowledge base with Trilium Notes

feat(test): add test for code block mpapings

Elian Doran952ec516eeea
diff --git a/src/services/code_block_theme.spec.ts b/src/services/code_block_theme.spec.ts
new file mode 100644
index 0000000000..84482b4167
--- /dev/null
+++ b/src/services/code_block_theme.spec.ts
@@ -0,0 +1,21 @@
+import { describe, expect, it } from "vitest";
+import { getStylesDirectory, readThemesFromFileSystem } from "./code_block_theme.js";
+
+import themeNames from "./code_block_theme_names.json" with { type: "json" };
+
+describe("Code block theme", () => {
+ it("all themes are mapped", () => {
+ const themes = readThemesFromFileSystem(getStylesDirectory());
+
+ const mappedThemeNames = new Set(Object.values(themeNames));
+ const unmappedThemeNames = new Set<string>();
+
+ for (const theme of themes) {
+ if (!mappedThemeNames.has(theme.title)) {
+ unmappedThemeNames.add(theme.title);
+ }
+ }
+
+ expect(unmappedThemeNames.size, `Unmapped themes: ${Array.from(unmappedThemeNames).join(", ")}`).toBe(0);
+ });
+});
diff --git a/src/services/code_block_theme.ts b/src/services/code_block_theme.ts
index 8351b2519c..8a3964fcdc 100644
--- a/src/services/code_block_theme.ts
+++ b/src/services/code_block_theme.ts
@@ -44,7 +44,7 @@ export function listSyntaxHighlightingThemes() {
};
}
-function getStylesDirectory() {
+export function getStylesDirectory() {
if (isElectron && !isDev) {
return "styles";
}
@@ -60,7 +60,7 @@ function getStylesDirectory() {
* @param path the path to read from. Usually this is the highlight.js `styles` directory.
* @returns the list of themes.
*/
-function readThemesFromFileSystem(path: string): ColorTheme[] {
+export function readThemesFromFileSystem(path: string): ColorTheme[] {
return fs
.readdirSync(path)
.filter((el) => el.endsWith(".min.css"))