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/adaptive colors: improve test coverage
Adorian Doran500f29904a12
diff --git a/packages/ckeditor5/src/plugins/adaptive_colors.spec.ts b/packages/ckeditor5/src/plugins/adaptive_colors.spec.tsindex df9136840e..f63b9dd614 100644--- a/packages/ckeditor5/src/plugins/adaptive_colors.spec.ts+++ b/packages/ckeditor5/src/plugins/adaptive_colors.spec.ts@@ -2,10 +2,12 @@ import {_getModelData as getModelData,_setModelData as setModelData,type ClassicEditor,+ type DowncastAttributeEvent,Essentials,FontBackgroundColor,FontColor,GeneralHtmlSupport,+ type ModelElement,Paragraph,Table,TableCellProperties,@@ -98,6 +100,26 @@ describe("AdaptiveColors", () => {expect(cleared).not.toContain("--tn-border-color:#000000");});+ it("adds no variable for a table color another converter has already handled", () => {+ editor.conversion.for("downcast").add((dispatcher) => {+ dispatcher.on<DowncastAttributeEvent<ModelElement>>(+ "attribute:tableBorderColor:table",+ (eventInfo, data, { consumable }) => {+ consumable.consume(data.item, eventInfo.name);+ },+ { priority: "highest" }+ );+ });+ setModelData(editor.model, "<table><tableRow><tableCell><paragraph>[]a</paragraph>"+ + "</tableCell></tableRow></table>");+ editor.execute("tableBorderStyle", { value: "solid" });+ editor.execute("tableBorderColor", { value: "#4d99e6" });++ const saved = editor.getData();+ expect(saved).toContain("border-style:solid;");+ expect(saved).not.toContain("--tn-border-color");+ });+it("keeps a variable out of the model, also with General HTML Support", async () => {const withGhs = await createTestEditor([ Essentials, Paragraph, FontColor, GeneralHtmlSupport, AdaptiveColors ],diff --git a/packages/ckeditor5/src/plugins/adaptive_colors.ts b/packages/ckeditor5/src/plugins/adaptive_colors.tsindex f63854f7df..bebeccf01c 100644--- a/packages/ckeditor5/src/plugins/adaptive_colors.ts+++ b/packages/ckeditor5/src/plugins/adaptive_colors.ts@@ -56,6 +56,8 @@ export default class AdaptiveColors extends Plugin {}const element = findStyledElement(mapper.toViewElement(data.item));+ /* v8 ignore next -- CKEditor gives every table and cell a view element, and+ draws a table as a `<figure>` holding its `<table>`. */if (!element) {return;}@@ -99,6 +101,6 @@ function findStyledElement(viewElement: ViewElement | undefined) {return viewElement;}- const table = [ ...viewElement.getChildren() ].find((child) => child.is("element", "table"));- return table?.is("element") ? table : undefined;+ return [ ...viewElement.getChildren() ]+ .find((child): child is ViewElement => child.is("element", "table"));}