Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
client/text editor/canvas: improve coverage
Adorian Doran88a48f8f5a69
diff --git a/packages/ckeditor5/src/plugins/content_embed/content_embed_tools.spec.ts b/packages/ckeditor5/src/plugins/content_embed/content_embed_tools.spec.tsindex f718da3280..f156b9f64b 100644--- a/packages/ckeditor5/src/plugins/content_embed/content_embed_tools.spec.ts+++ b/packages/ckeditor5/src/plugins/content_embed/content_embed_tools.spec.ts@@ -140,6 +140,9 @@ describe("ContentEmbedTools", () => {.toEqual([ "Undo", false, ICON, "Undo", "Undo", false, false, false ]);expect(getItems(tools)).toEqual([ "1", "2", "|", "Undo" ]);+ provider.change([ { id: "a", label: "A", text: "A" }, { id: "b", label: "B", text: "B" } ]);+ expect(getItems(tools)).toEqual([ "A", "B" ]);+provider.change([ SELECTION, RECTANGLE, { ...UNDO, isEnabled: true, class: "undo" } ]);expect(getButtons(tools)[2]?.isEnabled).toBe(true);expect(getButtons(tools)[2]?.element?.classList.contains("undo")).toBe(true);@@ -168,7 +171,7 @@ describe("ContentEmbedTools", () => {const children = [{ id: "eraser", label: "Eraser", isOn: true },- { id: "laser", label: "Laser pointer", isOn: false }+ { id: "laser", label: "Laser pointer" }];provider.change([ RECTANGLE, { ...MORE_TOOLS, isOn: true, children, class: "more" } ]);expect(tools.views[1]).toBe(menu);diff --git a/packages/ckeditor5/src/plugins/content_embed/content_embed_tools.ts b/packages/ckeditor5/src/plugins/content_embed/content_embed_tools.tsindex a370482d57..82af46f2e6 100644--- a/packages/ckeditor5/src/plugins/content_embed/content_embed_tools.ts+++ b/packages/ckeditor5/src/plugins/content_embed/content_embed_tools.ts@@ -62,10 +62,10 @@ type ContentEmbedToolsResizeEvent = {args: [];};-/** The view of a tool, and the way it shows a new state of the tool. */+/** The view of a tool, and the way it shows a new state of the tool and of its children. */interface ToolView {view: ButtonView | DropdownView;- update(tool: ContentEmbedTool): void;+ update(tool: ContentEmbedTool, children: ContentEmbedTool[]): void;}/** The buttons of a `ContentEmbedToolProvider`, updated when the provider changes. */@@ -76,7 +76,7 @@ export class ContentEmbedToolsView extends View {public views: Array<ButtonView | DropdownView> = [];/** The views and the separators between their groups. */private readonly items: ViewCollection;- private updaters: Array<(tool: ContentEmbedTool) => void> = [];+ private updaters: Array<ToolView["update"]> = [];private provider: ContentEmbedToolProvider | null = null;private unsubscribe: (() => void) | undefined;/** The group and the ids of each tool, to create the views again only for another set. */@@ -141,7 +141,7 @@ export class ContentEmbedToolsView extends View {}for (const [ index, tool ] of tools.entries()) {- this.updaters[index]?.(tool);+ this.updaters[index]?.(tool, tool.children ?? []);}this.isVisible = tools.length > 0;@@ -204,15 +204,12 @@ export class ContentEmbedToolsView extends View {}addListToDropdown(dropdown, definitions);this.listenTo(dropdown, "execute", (evt) => {- const { toolId } = evt.source as { toolId?: string };- if (toolId) {- this.provider?.execute(toolId);- }+ this.provider?.execute((evt.source as { toolId: string }).toolId);});return {view: dropdown,- update: (tool) => {+ update: (tool, children) => {// `createDropdown()` binds `isOn` of the button to the dropdown being open.const classes = [ tool.class, tool.isOn && "ck-on" ].filter(Boolean);dropdown.buttonView.set({@@ -220,7 +217,7 @@ export class ContentEmbedToolsView extends View {class: classes.length ? classes.join(" ") : undefined});dropdown.isEnabled = tool.isEnabled ?? true;- for (const [ index, child ] of (tool.children ?? []).entries()) {+ for (const [ index, child ] of children.entries()) {models[index]?.set({label: child.label,icon: child.icon,