"use strict"; const test = require("node:test"); const assert = require("node:assert/strict"); const { firstCappedIndex } = require("../main.js").__test__; test("firstCappedIndex finds the cap on the real measured live-preview chain", () => { // Measured in Obsidian live preview via getComputedStyle, walking outward // from .webinar-dash. The cap is on .cm-content at 700px; .cm-sizer - the // element a class-name lookup finds first - is already uncapped at 1680px. // Matching by class name selected .cm-sizer and stopped, leaving the real // cap in place. This test pins the measurement so that cannot recur. const chain = [ { maxWidth: "none", isWorkspaceLeaf: false }, // block-language-webinar-dash { maxWidth: "none", isWorkspaceLeaf: false }, // cm-preview-code-block { maxWidth: "700px", isWorkspaceLeaf: false }, // cm-content <- the cap { maxWidth: "none", isWorkspaceLeaf: false }, // cm-contentContainer { maxWidth: "none", isWorkspaceLeaf: false }, // cm-sizer { maxWidth: "none", isWorkspaceLeaf: false }, // cm-scroller ]; assert.equal(firstCappedIndex(chain), 2); }); test("firstCappedIndex finds the cap on a reading-view chain", () => { const chain = [ { maxWidth: "none", isWorkspaceLeaf: false }, // block-language-webinar-dash { maxWidth: "700px", isWorkspaceLeaf: false }, // markdown-preview-sizer { maxWidth: "none", isWorkspaceLeaf: false }, // markdown-preview-view ]; assert.equal(firstCappedIndex(chain), 1); }); test("firstCappedIndex returns -1 when nothing above the dashboard is capped", () => { const chain = [ { maxWidth: "none", isWorkspaceLeaf: false }, { maxWidth: "none", isWorkspaceLeaf: false }, ]; assert.equal(firstCappedIndex(chain), -1); }); test("firstCappedIndex stops at the workspace leaf rather than widening chrome", () => { const chain = [ { maxWidth: "none", isWorkspaceLeaf: false }, { maxWidth: "none", isWorkspaceLeaf: true }, // workspace-leaf { maxWidth: "900px", isWorkspaceLeaf: false }, // must never be reached ]; assert.equal(firstCappedIndex(chain), -1); }); test("firstCappedIndex takes the innermost cap when several ancestors are capped", () => { const chain = [ { maxWidth: "none", isWorkspaceLeaf: false }, { maxWidth: "700px", isWorkspaceLeaf: false }, { maxWidth: "1200px", isWorkspaceLeaf: false }, ]; assert.equal(firstCappedIndex(chain), 1); });