Skip to content

Build your personal knowledge base with Trilium Notes

test(ckeditor5): co-locate specs with source and revive the editor test

Elian Doranb10fe91c7a36
diff --git a/packages/ckeditor5/tests/collapsible_list_items.spec.ts b/packages/ckeditor5/src/plugins/collapsible_list_items.spec.ts
similarity index 99%
rename from packages/ckeditor5/tests/collapsible_list_items.spec.ts
rename to packages/ckeditor5/src/plugins/collapsible_list_items.spec.ts
index 0e6d7aceec..a5040eaf01 100644
--- a/packages/ckeditor5/tests/collapsible_list_items.spec.ts
+++ b/packages/ckeditor5/src/plugins/collapsible_list_items.spec.ts
@@ -1,7 +1,7 @@
import { _setModelData as setModelData, ClassicEditor, keyCodes, List, Paragraph, TodoList, Typing, Undo, type ModelElement } from "ckeditor5";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
-import CollapsibleListItems, { LIST_COLLAPSED_ATTRIBUTE } from "../src/plugins/collapsible_list_items.js";
+import CollapsibleListItems, { LIST_COLLAPSED_ATTRIBUTE } from "./collapsible_list_items.js";
// Lists are flat in the model: sibling blocks related by listIndent/listItemId.
const LIST_FIXTURE =
diff --git a/packages/ckeditor5/src/translation_overrides.spec.ts b/packages/ckeditor5/src/translation_overrides.spec.ts
new file mode 100644
index 0000000000..cb5fc8a6b9
--- /dev/null
+++ b/packages/ckeditor5/src/translation_overrides.spec.ts
@@ -0,0 +1,57 @@
+import { Bookmark, ClassicEditor, Essentials, Paragraph } from "ckeditor5";
+import { afterEach, beforeEach, describe, expect, it } from "vitest";
+
+// Side effect: assigns window.CKEDITOR_TRANSLATIONS, the global CKEditor reads to relabel its
+// built-in strings. Imported before any editor is created so the override is in place.
+import "./translation_overrides.js";
+
+describe("translation overrides", () => {
+ let editorElement: HTMLDivElement;
+ let editor: ClassicEditor;
+
+ beforeEach(async () => {
+ editorElement = document.createElement("div");
+ document.body.appendChild(editorElement);
+ editor = await ClassicEditor.create(editorElement, {
+ licenseKey: "GPL",
+ plugins: [Essentials, Paragraph, Bookmark],
+ toolbar: { items: ["bookmark"] }
+ });
+ });
+
+ afterEach(async () => {
+ editorElement.remove();
+ await editor.destroy();
+ });
+
+ it("are picked up by the editor UI (Bookmark relabelled to Anchor)", () => {
+ const labels = toolbarLabels(editor);
+ expect(labels).toContain("Anchor");
+ expect(labels).not.toContain("Bookmark");
+ });
+
+ it("register the text-snippet relabels for the premium template feature", () => {
+ // The Template feature is premium and not loaded here, so its relabel can't be exercised
+ // through the UI — assert the override dictionary carries it instead.
+ const dictionary = window.CKEDITOR_TRANSLATIONS?.en?.dictionary ?? {};
+ expect(dictionary["Insert template"]).toBe("Insert text snippet");
+ expect(dictionary["Search template"]).toBe("Search text snippet");
+ });
+});
+
+function toolbarLabels(editor: ClassicEditor): string[] {
+ const labels: string[] = [];
+ for (const item of editor.ui.view.toolbar?.items ?? []) {
+ // Toolbar items are buttons (label directly) or dropdowns (label on the inner buttonView).
+ const view = item as unknown as { label?: unknown; buttonView?: { label?: unknown } };
+ const label = typeof view.label === "string"
+ ? view.label
+ : typeof view.buttonView?.label === "string"
+ ? view.buttonView.label
+ : null;
+ if (label) {
+ labels.push(label);
+ }
+ }
+ return labels;
+}
diff --git a/packages/ckeditor5/tests/templates.ts b/packages/ckeditor5/tests/templates.ts
deleted file mode 100644
index f8894ac609..0000000000
--- a/packages/ckeditor5/tests/templates.ts
+++ /dev/null
@@ -1,37 +0,0 @@
-import { it } from "vitest";
-import { describe } from "vitest";
-import { ClassicEditor } from "../src/index.js";
-import { type BalloonEditor, type ButtonView, type Editor } from "ckeditor5";
-import { beforeEach } from "vitest";
-import { expect } from "vitest";
-
-describe("Text snippets", () => {
- let editorElement: HTMLDivElement;
- let editor: Editor;
-
- beforeEach(async () => {
- editorElement = document.createElement( 'div' );
- document.body.appendChild( editorElement );
-
- console.log("Trigger each");
-
- editor = await ClassicEditor.create(editorElement, {
- licenseKey: "GPL",
- toolbar: {
- items: [
- "insertTemplate"
- ]
- }
- });
- });
-
- it("uses correct translations", () => {
- const itemsWithButtonView = Array.from(editor.ui.view.toolbar?.items)
- .filter(item => "buttonView" in item)
- .map(item => (item.buttonView as ButtonView).label);
-
- expect(itemsWithButtonView).not.toContain("Insert template");
- expect(itemsWithButtonView).toContain("Insert text snippet");
- });
-});
-
diff --git a/packages/ckeditor5/tsconfig.lib.json b/packages/ckeditor5/tsconfig.lib.json
index 583a2668c3..09c4f6eb8d 100644
--- a/packages/ckeditor5/tsconfig.lib.json
+++ b/packages/ckeditor5/tsconfig.lib.json
@@ -17,6 +17,9 @@
"include": [
"src/**/*.ts"
],
+ "exclude": [
+ "src/**/*.spec.ts"
+ ],
"references": [
{
"path": "../ckeditor5-footnotes"
diff --git a/packages/ckeditor5/vitest.config.ts b/packages/ckeditor5/vitest.config.ts
index aa77a7dfe4..ddfe3bfd61 100644
--- a/packages/ckeditor5/vitest.config.ts
+++ b/packages/ckeditor5/vitest.config.ts
@@ -10,7 +10,7 @@ export default defineConfig({
ui: false,
instances: [{ browser: "chrome" }]
},
- include: ["tests/**/*.spec.ts"],
+ include: ["src/**/*.spec.ts"],
globals: true,
watch: false
}