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: improve test coverage
Adorian Doranf5fa92c86a46
diff --git a/packages/ckeditor5/src/plugins/content_embed/content_embed_caret.spec.ts b/packages/ckeditor5/src/plugins/content_embed/content_embed_caret.spec.tsindex a8936871dd..979314f19e 100644--- a/packages/ckeditor5/src/plugins/content_embed/content_embed_caret.spec.ts+++ b/packages/ckeditor5/src/plugins/content_embed/content_embed_caret.spec.ts@@ -383,6 +383,14 @@ describe("ContentEmbedCaret as the editor of an embed", () => {expect(getEdge("ArrowLeft")).toBe("start");});+ it("stays in a table whose last cell ends with an object", async () => {+ const tableEditor = await createTestEditor([ ...TEXT_PLUGINS, Table ]);+ setModelData(tableEditor.model, "<table>"+ + "<tableRow><tableCell><paragraph>a[]</paragraph></tableCell></tableRow>"+ + `<tableRow><tableCell>${HR}</tableCell></tableRow></table>`);+ expect(getEdge("ArrowDown", {}, tableEditor)).toBe(null);+ });+it("leaves the arrow keys to an open mention list", async () => {const list = {element: null as HTMLElement | null,diff --git a/packages/ckeditor5/src/plugins/table_sticky_header_read_only.spec.ts b/packages/ckeditor5/src/plugins/table_sticky_header_read_only.spec.tsindex 7bb74623e6..b1a3627385 100644--- a/packages/ckeditor5/src/plugins/table_sticky_header_read_only.spec.ts+++ b/packages/ckeditor5/src/plugins/table_sticky_header_read_only.spec.ts@@ -166,6 +166,53 @@ describe("applyStickyTableHeaders", () => {expect(thead.style.getPropertyValue(START_PROPERTY)).toBe(aligned);});+ it("aligns the header rows once per scroll of their scroll container", async () => {+ snapScrollOffsets();+ const { scroller, content, spacer } = renderContent(tableFigure(1, 20));+ onTestFinished(applyStickyTableHeaders(content));+ await settle();+ const { thead } = parts(content);+ const start = () => thead.style.getPropertyValue(START_PROPERTY);++ spacer.style.height = "100.4px";+ scroller.dispatchEvent(new Event("scroll"));+ await settle();+ const aligned = start();+ spacer.style.height = "100px";+ scroller.dispatchEvent(new Event("scroll"));+ await settle();+ expect(start()).toBe(aligned);++ scroller.dispatchEvent(new Event("scrollend"));+ scroller.dispatchEvent(new Event("scroll"));+ await settle();+ expect(start()).not.toBe(aligned);+ });++ it("aligns the header rows of a table that scrolls with the page", async () => {+ snapScrollOffsets();+ const content = document.createElement("div");+ content.className = "ck-content";+ content.innerHTML = `<div style="height:100.4px"></div>${tableFigure(1, 20)}`+ + "<div style=\"height:2000px\"></div>";+ document.body.appendChild(content);+ document.documentElement.style.scrollPaddingTop = "10.5px";+ window.scrollTo(0, 31);+ onTestFinished(() => {+ content.remove();+ document.documentElement.style.scrollPaddingTop = "";+ window.scrollTo(0, 0);+ });+ onTestFinished(applyStickyTableHeaders(content));+ await settle();++ const { figure, thead } = parts(content);+ expect(window.scrollY).toBe(31);+ const offset = figure.getBoundingClientRect().top + window.scrollY - 10.5+ + lengthOf(thead, START_PROPERTY);+ expect(offset * SCALE % 1).toBeCloseTo(0.5, 1);+ });+it("keeps the header rows of a table that scrolls sideways in view", async () => {const html = tableFigure(1, 20, "Caption", "width:300%;");const { scroller, content } = renderContent(html);diff --git a/packages/ckeditor5/src/plugins/table_sticky_header_read_only.ts b/packages/ckeditor5/src/plugins/table_sticky_header_read_only.tsindex c3398b0e47..231148c17e 100644--- a/packages/ckeditor5/src/plugins/table_sticky_header_read_only.ts+++ b/packages/ckeditor5/src/plugins/table_sticky_header_read_only.ts@@ -44,7 +44,7 @@ export class StickyTableHeaders {private readonly pending = new Set<Element>();/** The scroll containers between their first `scroll` event and their `scrollend` event. */- private readonly scrolling = new Set<EventTarget>();+ private readonly scrolling = new Set<Node>();private frame: number | undefined;@@ -99,18 +99,20 @@ export class StickyTableHeaders {this.observed.add(element);}- /** `measure()` aligns the steps to where the table sits, which can change without a resize. */- private readonly onScroll = ({ target }: Event) => {- if (target instanceof Node && !this.scrolling.has(target)) {+ /**+ * `measure()` aligns the steps to where the table sits, which can change without a resize. A+ * listener on `document` receives the events of its nodes only.+ */+ private readonly onScroll = (event: Event) => {+ const target = event.target as Node;+ if (!this.scrolling.has(target)) {this.scrolling.add(target);this.schedule([ ...this.observed ].filter((element) => target.contains(element)));}};- private readonly onScrollEnd = ({ target }: Event) => {- if (target) {- this.scrolling.delete(target);- }+ private readonly onScrollEnd = (event: Event) => {+ this.scrolling.delete(event.target as Node);};/** Measures the figures of `elements` in the next animation frame. */