Skip to content

Build your personal knowledge base with Trilium Notes

test(spreadsheet): update three specs the styling move left behind

Elian Dorane146ac47e8f2
diff --git a/apps/client/src/widgets/type_widgets/file/Office.spec.tsx b/apps/client/src/widgets/type_widgets/file/Office.spec.tsx
index a00564a46b..6e8af1d2e4 100644
--- a/apps/client/src/widgets/type_widgets/file/Office.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/file/Office.spec.tsx
@@ -1,7 +1,7 @@
import { render } from "preact";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
-const renderOfficeToHtml = vi.fn<(entityType: string, entityId: string) => Promise<string>>();
+const renderOfficeToHtml = vi.fn<(entityType: string, entityId: string) => Promise<{ css: string; html: string }>>();
vi.mock("../../../services/office_renderer", () => ({
renderOfficeToHtml: (...args: [string, string]) => renderOfficeToHtml(...args)
@@ -31,7 +31,7 @@ function mount(noteId = "office1", blobId = "blob1") {
describe("OfficePreview", () => {
it("shows the loading state, then the sanitized server-rendered HTML for the note", async () => {
- let resolve: (html: string) => void = () => {};
+ let resolve: (preview: { css: string; html: string }) => void = () => {};
renderOfficeToHtml.mockReturnValue(new Promise((r) => { resolve = r; }));
mount("note42");
@@ -41,7 +41,7 @@ describe("OfficePreview", () => {
// Effects run after the render tick, so the fetch is observed asynchronously.
await vi.waitFor(() => expect(renderOfficeToHtml).toHaveBeenCalledWith("notes", "note42"));
- resolve('<p class="converted-doc">Hello</p>');
+ resolve({ css: "", html: '<p class="converted-doc">Hello</p>' });
await vi.waitFor(() => expect(container.querySelector(".converted-doc")?.textContent).toBe("Hello"));
const body = container.querySelector(".office-preview-body");
@@ -60,18 +60,18 @@ describe("OfficePreview", () => {
});
it("re-fetches when the note's content (blobId) changes", async () => {
- renderOfficeToHtml.mockResolvedValue("<p>v1</p>");
+ renderOfficeToHtml.mockResolvedValue({ css: "", html: "<p>v1</p>" });
mount("note1", "blobA");
await vi.waitFor(() => expect(container.querySelector(".office-preview-body")).not.toBeNull());
- renderOfficeToHtml.mockResolvedValue('<p class="v2">v2</p>');
+ renderOfficeToHtml.mockResolvedValue({ css: "", html: '<p class="v2">v2</p>' });
mount("note1", "blobB");
await vi.waitFor(() => expect(container.querySelector(".v2")).not.toBeNull());
expect(renderOfficeToHtml).toHaveBeenCalledTimes(2);
});
it("discards a conversion that resolves after unmount without touching the DOM", async () => {
- let resolve: (html: string) => void = () => {};
+ let resolve: (preview: { css: string; html: string }) => void = () => {};
renderOfficeToHtml.mockReturnValue(new Promise((r) => { resolve = r; }));
mount();
@@ -79,7 +79,7 @@ describe("OfficePreview", () => {
// path (not a never-started effect) is what's exercised.
await vi.waitFor(() => expect(renderOfficeToHtml).toHaveBeenCalled());
render(null, container);
- resolve("<p>too late</p>");
+ resolve({ css: "", html: "<p>too late</p>" });
// Let the microtask run; the cancelled effect must not re-render into the container.
await Promise.resolve();
expect(container.innerHTML).toBe("");
diff --git a/apps/standalone/src/lightweight/browser_routes.spec.ts b/apps/standalone/src/lightweight/browser_routes.spec.ts
index ac91e246cb..3e08062684 100644
--- a/apps/standalone/src/lightweight/browser_routes.spec.ts
+++ b/apps/standalone/src/lightweight/browser_routes.spec.ts
@@ -227,8 +227,10 @@ describe("route wrapper branches (via controlled handlers)", () => {
expect(parseJson((await router.dispatch("GET", "http://localhost/t/r-obj")).body)).toEqual({ a: 1 });
expect(parseJson((await router.dispatch("GET", "http://localhost/t/r-tuple")).body)).toEqual({ created: true });
+ // apiResultHandler turns undefined into "", which goes out as an empty body — what the
+ // server's send() does with the same value, rather than a JSON-quoted empty string.
const undefRes = await router.dispatch("GET", "http://localhost/t/r-undef");
- expect(text(undefRes.body)).toBe('""');
+ expect(text(undefRes.body)).toBe("");
});
it("returns a plain route() result when no result handler is supplied", async () => {
diff --git a/packages/trilium-e2e/src/note_types/spreadsheet.spec.ts b/packages/trilium-e2e/src/note_types/spreadsheet.spec.ts
index 2af31a5dd7..53a5e79350 100644
--- a/packages/trilium-e2e/src/note_types/spreadsheet.spec.ts
+++ b/packages/trilium-e2e/src/note_types/spreadsheet.spec.ts
@@ -60,6 +60,14 @@ const WORKBOOK = {
}
};
+/**
+ * The heights the workbook above states, in order. Read from here rather than back out of the
+ * markup: the renderer writes a row's height into the stylesheet it emits, so the `tr` carries a
+ * class and not a `style` attribute, and a test that read one would be asserting the DOM agrees
+ * with itself rather than that the sheet's own numbers survived.
+ */
+const DECLARED_HEIGHTS = [30, 40, 24, 24, 60];
+
test("prints the grid at the row heights the sheet declares", async ({ page, context }) => {
const app = new App(page, context);
await app.goto();
@@ -74,19 +82,19 @@ test("prints the grid at the row heights the sheet declares", async ({ page, con
const table = document.querySelector(".spreadsheet-table");
const base = table?.getBoundingClientRect().top ?? 0;
return [...(table?.querySelectorAll("tr") ?? [])].map((row) => ({
- declared: Number.parseFloat((row as HTMLElement).style.height),
top: row.getBoundingClientRect().top - base,
rendered: row.getBoundingClientRect().height
}));
});
- expect(rows.length).toBe(5);
+ expect(rows.length).toBe(DECLARED_HEIGHTS.length);
let expectedTop = 0;
for (const [index, row] of rows.entries()) {
- expect(row.rendered, `row ${index} keeps the height it declares`).toBeCloseTo(row.declared, 0);
+ const declared = DECLARED_HEIGHTS[index];
+ expect(row.rendered, `row ${index} keeps the height it declares`).toBeCloseTo(declared, 0);
expect(row.top, `row ${index} starts where the rows above it end`).toBeCloseTo(expectedTop, 0);
- expectedTop += row.declared;
+ expectedTop += declared;
}
} finally {
await deleteNote(app, noteId);