// The report's "How do I…?" help (#919): its topics name the report's controls by their labels in // English and German, "Show me" plans what to open and mark for the report as it is, the card goes // beside what it marks, the docs links follow the host's docsUrl, and the host's `helpTopics` picks // the built-in questions and adds its own, checked, with the list's first HELP_LIST shown; an own // question's Show me finds the page's element by its id only, in the report's tree and outwards. import { test } from "node:test"; import assert from "node:assert/strict"; import { encode, normalize } from "pivotkit-core"; import "../src/deferred.js"; import { CARD, HELP_GROUPS, HELP_LIST, HELP_TEXTS, HELP_TOPICS, OWN_LIMITS, docsHref, helpList, helpMatch, helpNames, helpSections, helpText, helpTopicsOf, ownCardText, textLang } from "../src/help-topics.js"; import { hostElement, offered, offeredSteps, showPlan } from "../src/help-show.js"; import { dimHoles, dimPath, placeCard } from "../src/help-place.js"; import { MENU } from "./helpers.js"; const data = encode([ { Region: "North", Product: "A", Date: "2024-01-05", Units: 3 }, { Region: "South", Product: "B", Date: "2024-02-07", Units: 5 } ]); const norm = (v) => normalize(v, data).view; const types = { Region: "string", Product: "string", Date: "date", Units: "number" }; const FEATURES = { drillDown: true, save: true, link: true, import: true, fullScreen: true, date: true, number: true, viewsInMore: false, dataInMore: false, startOverInMore: false, zonesFolded: false, fieldsHidden: false, tableHidden: false, chartHidden: false, resetOff: false, undoOff: false }; /** The report as Show me reads it. */ const state = (view, extra = {}) => ({ view: norm(view), typeOf: (f) => types[f.replace(/ \(.*\)$/, "")] ?? "string", fields: Object.keys(types), display: "table", features: FEATURES, ...extra }); const FIRST = ["add-field", "filter", "date-range", "top-n", "sort-value", "group-dates", "drill-down", "chart", "percent", "export", "share", "load-data"]; test("the questions in six groups, the twelve asked most marked first, every text in English and German, every step a whole sentence", () => { assert.deepEqual(HELP_GROUPS, ["fields", "filter", "table", "chart", "values", "export"]); assert.deepEqual(HELP_TOPICS.filter((t) => t.top).map((t) => t.id), FIRST); assert.ok(FIRST.length <= HELP_LIST); // the questions added with the list's level "All questions" (#919) assert.deepEqual(HELP_TOPICS.filter((t) => !t.top).map((t) => t.id), ["filter-rule", "number-ranges", "subtotals", "grand-totals", "expand-collapse", "swap", "chart-type", "value-labels", "legend", "chart-title", "reference-line", "chart-image", "summarize", "number-format", "highlight", "rename", "export-csv", "print", "undo", "start-over", "full-screen"]); // offered only where the report does so, or where its data has a field of that type assert.deepEqual(HELP_TOPICS.filter((t) => t.needs).map((t) => [t.id, t.needs]), [["date-range", "date"], ["group-dates", "date"], ["number-ranges", "number"], ["drill-down", "drillDown"], ["share", "share"], ["load-data", "import"], ["full-screen", "fullScreen"]]); assert.equal(new Set(HELP_TOPICS.map((t) => t.id)).size, HELP_TOPICS.length, "topic ids are unique"); // in the order of their groups, so the list and All questions read top down assert.deepEqual(HELP_TOPICS.map((t) => HELP_GROUPS.indexOf(t.group)), HELP_TOPICS.map((t) => HELP_GROUPS.indexOf(t.group)).sort((a, b) => a - b)); assert.deepEqual(Object.keys(HELP_TEXTS.de).sort(), Object.keys(HELP_TEXTS.en).sort()); assert.deepEqual(Object.keys(HELP_TEXTS.de.groups), ["general", ...HELP_GROUPS]); for (const topic of HELP_TOPICS) { assert.ok(HELP_GROUPS.includes(topic.group), topic.id); assert.ok(topic.keywords, `${topic.id}: words the search finds it by`); for (const lang of ["en", "de"]) { assert.match(topic.question[lang], /\?$/, `${topic.id}: question in ${lang}`); assert.ok(topic.keywords[lang].trim(), `${topic.id}: keywords in ${lang}`); for (const step of topic.steps) { // a whole sentence: never one that goes on from the step before ("Or …") assert.match(step[lang], /^[^a-zäöü].*[.?]$/u, `${topic.id}: a step in ${lang}`); assert.doesNotMatch(step[lang], /^(Or|Oder) /, `${topic.id}: ${step[lang]}`); } } } }); test("a step names each control by the label it shows, in the report's language: every name fills in", () => { for (const lang of ["en", "de"]) { const names = helpNames(MENU[lang], "Date", "Sum of Units", "⌘"); for (const [name, text] of Object.entries(names)) { assert.ok(typeof text === "string" && text.trim(), `${lang}: ${name} has no label`); } // the card's count is filled with its numbers (help-guide.jsx) const texts = [...HELP_TOPICS.flatMap((t) => t.steps.map((s) => s[lang])), ...Object.entries(HELP_TEXTS[lang]).filter(([k, v]) => typeof v === "string" && k !== "stepOf").map(([, v]) => v)]; for (const text of texts) { assert.doesNotMatch(helpText(text, names), /\{\w+\}/, `${lang}: ${text}`); } } // the menu paths of the steps are the menus' own words const en = helpNames(MENU.en, "Date", "Sum of Units", "⌘"); assert.deepEqual([en.filter, en.topItems, en.sortByValue, en.showAs, en.grandTotal, en.group, en.xlsx, en.optionsFor, en.addToFilters, en.loadData], ["Filter", "Top items", "Sort by value", "Show as", "% of grand total", "Group", "Excel workbook (.xlsx)", "Options for Date", "Add to Filters", "Load data…"]); // sorting by a value: the entries of a field's menu, by the value's name (H1 of the review) assert.deepEqual([en.sortLargest, en.sortSmallest, en.undoKeys], ["Largest Sum of Units first", "Smallest Sum of Units first", "⌘Z"]); assert.deepEqual([en.tableSettings, en.rowSubtotals, en.collapseAll, en.swap, en.chartSettings, en.valueLabels, en.referenceLines, en.average, en.png, en.aggregation, en.sum, en.format, en.conditional, en.rename, en.addRuleTotal, en.bins, en.csv, en.print, en.startOver, en.reset, en.fullScreen], ["Table settings", "Row subtotals", "Collapse all", "Swap rows and columns", "Chart settings", "Value labels", "Reference lines", "Average", "Chart image (.png)", "Summarize by", "Sum", "Number format", "Highlight", "Name", "Filter by total", "Number ranges", "Table as CSV (.csv)", "Print or save as PDF…", "Start over", "Reset", "Full screen"]); const de = helpNames(MENU.de, "Datum", "Summe von Menge"); assert.deepEqual([de.filter, de.topItems, de.optionsFor, de.addToFilters, de.sortLargest, de.undoKeys], ["Filter", "Oberste Einträge", "Optionen für Datum", "Zu Filter hinzufügen", "Größte Summe von Menge zuerst", "Ctrl+Z"]); assert.equal(helpText(HELP_TOPICS.find((t) => t.id === "percent").steps[2].en, en), "Choose “Show as”, then “% of grand total”."); // the German questions as decided (#919) assert.deepEqual(["sort-value", "group-dates"].map((id) => HELP_TOPICS.find((t) => t.id === id).question.de), ["Wie sortiere ich nach den Zahlen?", "Wie gruppiere ich Daten nach Monat oder Jahr?"]); }); /** A plan's steps in short: a key, or a selector with its match, and its flags. */ const short = (plan) => plan.steps.map((s) => [s.key ?? `${s.select}${s.nth ? `#${s.nth}` : ""}`, ...["origin", "prep", "keep"].filter((f) => s[f])]); const CHIP = (zone) => `[data-zone="${zone}"] [data-testid^="chip-menu-"]`; const VALUES = '.pk-popover [data-testid="level-filter"] .pk-values'; const GROUP_LEVEL = '.pk-popover [data-testid="level-group"]'; test("Show me's steps: a field's chip, the entry of its menu, to the last one the answer names; the zones and the field list opened first", () => { const view = { rows: ["Region", "Date"], cols: ["Product"], values: [{ field: "Units", agg: "sum" }] }; // the first field of Rows: its chip (the menu's origin, in Rows), Filter, the values to untick (the last step, where the reader picks several) const filter = showPlan("filter", state(view)); assert.deepEqual(short(filter), [[CHIP("rows"), "origin"], ["topic-filter"], [VALUES, "keep"]]); assert.deepEqual([filter.field, filter.steps[0].origin, filter.steps[0].from, filter.steps.map((s) => s.say)], ["Region", "[data-chip]", "rows", [CARD.openMenu, 2, 3]]); // the zones folded away (a phone): opening them is a step of its own, first assert.deepEqual(short(showPlan("filter", state(view, { features: { ...FEATURES, zonesFolded: true } })))[0], ['[data-testid="layout-summary"]', "prep"]); assert.deepEqual(short(showPlan("filter-rule", state(view))).at(-1), ["topic-filter"]); assert.deepEqual(short(showPlan("top-n", state(view))).at(-1), ["topic-top"]); // one value: its entry "Largest … first" right in the menu, exactly one row; more: the row Sort by value assert.deepEqual([short(showPlan("sort-value", state(view))).at(-1), showPlan("sort-value", state(view)).measure], [["sort-value-desc-0"], { field: "Units", agg: "sum" }]); const two = { ...view, values: [...view.values, { field: "Units", agg: "average" }] }; assert.deepEqual(short(showPlan("sort-value", state(two))).at(-1), ["topic-sortValue"]); // a date: the second chip of Rows, Group, then its units assert.deepEqual([short(showPlan("group-dates", state(view))), showPlan("group-dates", state(view)).field], [[[`${CHIP("rows")}#1`, "origin"], ["topic-group"], [GROUP_LEVEL, "keep"]], "Date"]); assert.deepEqual([showPlan("date-range", state(view)).field, short(showPlan("date-range", state(view))).at(-1)], ["Date", ["topic-filter"]]); // a number: its ranges; a number grouped already is still that number assert.deepEqual(short(showPlan("number-ranges", state({ rows: ["Region"], cols: ["Units"] }))), [[CHIP("cols"), "origin"], ["topic-bins"]]); const binned = norm({ rows: ["Units (by 2)"], derived: [{ name: "Units (by 2)", field: "Units", by: "bin", size: 2 }] }); assert.equal(showPlan("number-ranges", { ...state({}), view: binned }).field, "Units (by 2)"); // a value's menu: Show as, Summarize by, Number format, Highlight (its row by its selector), Name assert.deepEqual(short(showPlan("percent", state(view))), [[CHIP("values"), "origin"], ["topic-showAs"]]); assert.deepEqual(["summarize", "number-format"].map((id) => short(showPlan(id, state(view))).at(-1)), [["topic-summarize"], ["topic-format"]]); assert.deepEqual(short(showPlan("highlight", state(view))).at(-1), ['[data-testid="topic-highlight"]']); assert.deepEqual(short(showPlan("rename", state(view))), [[CHIP("rows"), "origin"], ["topic-name"]]); assert.deepEqual(short(showPlan("rename", state({ values: [{ field: "Units", agg: "sum" }] })))[0], [CHIP("values"), "origin"]); // nothing placed: the field list's first field, its row the origin, into Rows; the date into Filters const empty = {}; assert.deepEqual(short(showPlan("add-field", state(empty))), [['[data-testid="field-menu-Region"]', "origin"], ["field-rows-Region"]]); assert.deepEqual([showPlan("add-field", state(empty)).steps[0].origin, showPlan("add-field", state(empty)).steps[0].say], ["[data-field]", CARD.notPlaced]); assert.deepEqual(short(showPlan("date-range", state(empty))), [['[data-testid="field-menu-Date"]', "origin"], ["field-filter-Date"]]); // the field list in its drawer (a phone) or on its rail: opened first, by its own button assert.deepEqual(short(showPlan("add-field", state(empty, { features: { ...FEATURES, fieldsHidden: "drawer" } })))[0], ['[data-pk-opener="fields"]', "prep"]); assert.deepEqual(short(showPlan("add-field", state(empty, { features: { ...FEATURES, fieldsHidden: "rail" } })))[0], ['[data-testid="expand-fields"]', "prep"]); // the first field not yet placed assert.equal(showPlan("add-field", state({ rows: ["Region", "Product"] })).field, "Date"); // nothing to point at: a sentence instead assert.deepEqual(["filter", "filter-rule", "top-n", "sort-value", "percent", "summarize", "highlight", "drill-down", "rename"].map((id) => showPlan(id, state(empty)).none), ["noAxis", "noAxis", "noRows", "noValue", "noValue", "noValue", "noValue", "noValue", "noAxis"]); assert.equal(showPlan("top-n", state({ cols: ["Product"] })).none, "noRows"); assert.equal(showPlan("add-field", state(empty, { fields: [] })).none, "noField"); // a selector names a field as a quoted value, whatever it holds assert.equal(showPlan("add-field", state(empty, { fields: ['Say "hi"'] })).steps[0].select, '[data-testid="field-menu-Say \\"hi\\""]'); // a line break, which a CSV header can hold, as CSS escapes it assert.equal(showPlan("add-field", state(empty, { fields: ["Two\nlines"] })).steps[0].select, '[data-testid="field-menu-Two\\a lines"]'); }); test("a field the question needs that is in the data, not in Rows or Columns: the answer names it, Show me adds it first", () => { const view = { rows: ["Region"], values: [{ field: "Units", agg: "sum" }] }; const dates = showPlan("group-dates", state(view)); assert.equal(dates.notice, "needDate"); assert.equal(dates.field, "Date"); // its row's menu, Add to Rows (a change, by the reader's click or "Do it for me"), then its chip, the last of Rows assert.deepEqual(short(dates), [['[data-testid="field-menu-Date"]', "origin"], ["field-rows-Date"], [`${CHIP("rows")}#1`, "origin"], ["topic-group"], [GROUP_LEVEL, "keep"]]); assert.deepEqual(dates.steps[1].say, CARD.addToRows); // on a phone: the field list first, and the zones before the chip const phone = showPlan("group-dates", state(view, { features: { ...FEATURES, fieldsHidden: "drawer", zonesFolded: true } })); assert.deepEqual(short(phone).map((s) => s[0]), ['[data-pk-opener="fields"]', '[data-testid="field-menu-Date"]', "field-rows-Date", '[data-testid="layout-summary"]', `${CHIP("rows")}#1`, "topic-group", GROUP_LEVEL]); const numbers = showPlan("number-ranges", state(view)); assert.deepEqual([numbers.notice, numbers.field, short(numbers).at(-1)], ["needNumber", "Units", ["topic-bins"]]); // the notice names the field and says what Show me does, in English and German const names = { ...helpNames(MENU.en, "Date"), showMe: HELP_TEXTS.en.showMe }; assert.equal(helpText(HELP_TEXTS.en.needDate, names), "There is no date field in Rows or Columns yet. This data has one: “Date”. “Show me” first shows you how to add it to Rows."); // a type the data does not have: the question is not listed at all (help-show.js: offered) const groupDates = HELP_TOPICS.find((t) => t.id === "group-dates"); assert.deepEqual([offered(groupDates, { ...FEATURES, date: false }), offered(groupDates, FEATURES)], [false, true]); assert.deepEqual(HELP_TOPICS.filter((t) => !offered(t, { ...FEATURES, date: false, number: false })).map((t) => t.id), ["date-range", "group-dates", "number-ranges"]); }); test("Show me of the toolbar and the result: the button its menu opens from, the other tab first, what is in More now", () => { const view = { rows: ["Region"], values: [{ field: "Units", agg: "sum" }] }; assert.deepEqual(short(showPlan("export", state(view))), [['[data-testid="export"]', "origin"], ["export-xlsx"]]); assert.deepEqual(["export-csv", "print"].map((id) => short(showPlan(id, state(view))).at(-1)), [["export-csv"], ["export-print"]]); // the table shown: the tab Chart first; a chart: its settings at the chart's type, Both's own button assert.deepEqual(short(showPlan("chart", state(view))), [["show-chart", "prep"], ['[data-testid="view-settings"]', "origin"], ["chart-types"]]); assert.deepEqual(short(showPlan("chart", state(view, { display: "chart" }))), [['[data-testid="view-settings"]', "origin"], ["chart-types"]]); assert.deepEqual(short(showPlan("chart", state(view, { display: "both" })))[0], ['[data-testid="chart-settings"]', "origin"]); // the chart's settings: their row, or the one chart type the step names const chart = state(view, { display: "chart" }); assert.deepEqual(["value-labels", "legend", "chart-title", "reference-line"].map((id) => short(showPlan(id, chart)).at(-1)[0]), ["topic-valueLabels", "topic-legend", "topic-title", "topic-lines"]); assert.deepEqual(short(showPlan("chart-type", chart)).at(-1), ['[data-testid="chart-line"]']); assert.deepEqual(short(showPlan("legend", state(view))), [["show-chart", "prep"], ['[data-testid="view-settings"]', "origin"], ["topic-legend"]]); assert.deepEqual(short(showPlan("legend", state(view, { display: "both" }))), [['[data-testid="chart-settings"]', "origin"], ["topic-legend"]]); assert.deepEqual(short(showPlan("chart-image", state(view))), [["show-chart", "prep"], ['[data-testid="export"]', "origin"], ["export-png"]]); // the table's settings: the one switch that changes something in this layout const rows2 = { rows: ["Region", "Product"], values: [{ field: "Units", agg: "sum" }] }; assert.deepEqual(short(showPlan("subtotals", state(rows2))).at(-1), ["total-rowSubtotals"]); assert.deepEqual(short(showPlan("subtotals", state({ rows: ["Region"], cols: ["Product", "Date"], values: [{ field: "Units", agg: "sum" }] }))).at(-1), ["total-colSubtotals"]); assert.deepEqual(short(showPlan("grand-totals", state({ cols: ["Product"], values: [{ field: "Units", agg: "sum" }] }))).at(-1), ["total-grandTotalColumn"]); assert.deepEqual(short(showPlan("expand-collapse", state(rows2, { display: "both" })))[0], ['[data-testid="table-settings"]', "origin"]); assert.deepEqual(short(showPlan("grand-totals", chart))[0], ["show-table", "prep"]); // a control that draws no mark of its own: by its selector, one step assert.deepEqual(["swap", "undo", "full-screen"].map((id) => short(showPlan(id, state(view)))), [[['[data-testid="swap"]']], [['[data-testid="undo"]']], [['[data-testid="full-screen"]']]]); // the number of the table the arrow keys start from, or the tab Table first while the chart alone shows assert.deepEqual(short(showPlan("drill-down", state(view))), [['[data-testid="pivot-table"] td[tabindex="0"]']]); assert.deepEqual(short(showPlan("drill-down", chart))[0], ["show-table", "prep"]); // saving, then the link, its menu opened again once the view is saved; without a link, saving and a sentence const share = showPlan("share", state(view)); // saving a view: its entry, then the level that names it (done once it goes), then the link assert.deepEqual([short(share), share.steps[2].gone, share.steps[3].via, share.note], [[['[data-testid="views"]', "origin"], ["save-as"], ['.pk-popover [data-testid="level-saveAs"]'], ["copy-link"]], true, ['[data-testid="views"]'], undefined]); assert.deepEqual(short(showPlan("share", state(view, { features: { ...FEATURES, save: false } }))), [['[data-testid="views"]', "origin"], ["copy-link"]]); const noLink = showPlan("share", state(view, { features: { ...FEATURES, link: false } })); assert.deepEqual([short(noLink), noLink.note], [[['[data-testid="views"]', "origin"], ["save-as"], ['.pk-popover [data-testid="level-saveAs"]']], "noLink"]); // Views in More (a phone): More, its entry Views…, and More again for the link const inMore = showPlan("share", state(view, { features: { ...FEATURES, viewsInMore: true } })); assert.deepEqual([short(inMore), inMore.steps[4].via], [[['[data-testid="more"]', "origin"], ["more-views"], ["save-as"], ['.pk-popover [data-testid="level-saveAs"]'], ["copy-link"]], ['[data-testid="more"]', '[data-testid="more-views"]']]); assert.deepEqual(short(showPlan("load-data", state(view))).at(-1), ["load-file"]); assert.deepEqual(short(showPlan("load-data", state(view, { features: { ...FEATURES, dataInMore: true } }))), [['[data-testid="more"]', "origin"], ["more-data"], ["load-file"]]); assert.deepEqual(short(showPlan("start-over", state(view))), [['[data-testid="start-over"]', "origin"], ["reset"]]); assert.deepEqual(short(showPlan("start-over", state(view, { features: { ...FEATURES, startOverInMore: true } }))), [['[data-testid="more"]', "origin"], ["more-reset"]]); }); test("an entry greyed out now is not marked: the answer says why (UX review of round 3)", () => { const one = { rows: ["Region"], values: [{ field: "Units", agg: "sum" }] }; // Reset at the start view assert.equal(showPlan("start-over", state(one, { features: { ...FEATURES, resetOff: true } })).none, "atStart"); // subtotals with one field in Rows and Columns; expanding with one field in Rows assert.equal(showPlan("subtotals", state(one)).none, "noSubtotals"); assert.equal(showPlan("expand-collapse", state(one)).none, "noGroups"); // the totals without a value, or without a field on either axis assert.equal(showPlan("subtotals", state({ rows: ["Region", "Product"] })).none, "noValue"); assert.equal(showPlan("grand-totals", state({ values: [{ field: "Units", agg: "sum" }] })).none, "noAxis"); // Undo before anything changed; Swap without a field in Rows or Columns assert.equal(showPlan("undo", state(one, { features: { ...FEATURES, undoOff: true } })).none, "nothingToUndo"); assert.equal(showPlan("swap", state({ values: [{ field: "Units", agg: "sum" }] })).none, "noAxis"); // groups collapsed: Expand all, not Collapse all assert.deepEqual(short(showPlan("expand-collapse", state({ ...one, rows: ["Region", "Product"], collapsed: { rows: [["North"]] } }))).at(-1), ["expand-all"]); }); test("every question's Show me: steps of one control each, cards that say a step of the answer or a text of their own, a prep step only before what it opens", () => { const view = { rows: ["Region", "Date"], cols: ["Product", "Units"], values: [{ field: "Units", agg: "sum" }] }; for (const display of ["table", "chart", "both"]) { for (const more of [false, true]) { const features = { ...FEATURES, viewsInMore: more, dataInMore: more, startOverInMore: more, zonesFolded: more, fieldsHidden: more ? "drawer" : false, tableHidden: display === "chart", chartHidden: display === "table" }; for (const topic of HELP_TOPICS) { const plan = showPlan(topic.id, state(view, { display, features })); const at = `${topic.id} (${display}, phone ${more})`; assert.equal(plan.none, undefined, `${at}: ${plan.none}`); assert.ok(plan.steps.length > 0, at); for (const step of plan.steps) { assert.ok(Boolean(step.key) !== Boolean(step.select), `${at}: one control`); // a step of the answer as the report is now, or a text of the card's own const text = typeof step.say === "number" ? topic.steps[step.say] : step.say; assert.ok(text && (typeof step.say !== "number" || offeredSteps(topic, features).includes(text)), `${at}: step ${step.say} is not in the answer`); assert.ok(Object.values(CARD).includes(text) || topic.steps.includes(text), at); } assert.ok(!plan.steps.at(-1).prep, `${at}: the last step does something`); } } } // the card's texts name every control, in both languages; {name} is the control's own words for (const lang of ["en", "de"]) { const names = helpNames(MENU[lang], "Date"); for (const text of Object.values(CARD)) { assert.doesNotMatch(helpText(text[lang], { ...names, name: "Team" }), /\{\w+\}/, `${lang}: ${text[lang]}`); } assert.equal(helpText(HELP_TEXTS[lang].stepOf, { n: 2, m: 3 }), lang === "en" ? "Step 2 of 3" : "Schritt 2 von 3"); } }); test("a question the report does not offer is not listed; a step only where the report is so now", () => { const share = HELP_TOPICS.find((t) => t.id === "share"); const none = { ...FEATURES, drillDown: false, save: false, link: false, import: false, fullScreen: false }; assert.deepEqual(HELP_TOPICS.filter((t) => !offered(t, none)).map((t) => t.id), ["drill-down", "share", "load-data", "full-screen"]); assert.equal(offered(share, { ...none, link: true }), true); assert.deepEqual(offeredSteps(share, { ...none, link: true }).map((s) => s.needs), ["link"]); assert.deepEqual(offeredSteps(share, FEATURES).map((s) => s.needs), ["save", "link"]); // Views in More (a phone): the answer says so first (H2 of the review) assert.deepEqual(offeredSteps(share, { ...FEATURES, viewsInMore: true }).map((s) => s.needs), ["viewsInMore", ["save", "viewsInMore"], "link"]); // Start over in More: one step says where, the toolbar's step does not show (UX review of round 3) const startOver = HELP_TOPICS.find((t) => t.id === "start-over"); assert.deepEqual(offeredSteps(startOver, { ...FEATURES, startOverInMore: true }).map((s) => s.needs ?? s.unless), ["startOverInMore", undefined]); assert.deepEqual(offeredSteps(startOver, FEATURES).map((s) => s.unless ?? null), ["startOverInMore", null]); // the other tab shown: the answer says first to switch to it const legend = HELP_TOPICS.find((t) => t.id === "legend"); assert.equal(helpText(offeredSteps(legend, { ...FEATURES, chartHidden: true })[0].en, helpNames(MENU.en, "Date")), "The chart is not shown now: switch to the tab “Chart” first."); assert.equal(offeredSteps(legend, FEATURES).length, 2); // the zones folded away: a field's menu is behind their heading, the answer says so first const filter = HELP_TOPICS.find((t) => t.id === "filter"); assert.equal(offeredSteps(filter, FEATURES).length, 3); assert.equal(helpText(offeredSteps(filter, { ...FEATURES, zonesFolded: true })[0].en, helpNames(MENU.en, "Date")), "Rows, Columns and Values are folded away now: open “Fields in the report” first."); assert.ok(HELP_TOPICS.filter((t) => t.steps.some((s) => s.needs === "zonesFolded")).every((t) => t.steps[0].needs === "zonesFolded")); }); test("the card goes beside the menu, not over it, its arrow at the control; beside a control below it; else at the window's top", () => { const viewport = { width: 1280, height: 800 }; const size = { width: 300, height: 80 }; const control = { top: 200, left: 420, right: 780, bottom: 232 }; const menu = { top: 100, left: 400, right: 800, bottom: 500 }; const BESIDE = ["right", "left", "below", "above"]; // right of the menu, its middle at the control's, the arrow there assert.deepEqual(placeCard(control, menu, size, viewport, BESIDE), { top: 176, left: 812, side: "right", arrow: 40 }); // no room on the right: on the left assert.deepEqual(placeCard({ ...control, left: 900, right: 1200 }, { ...menu, left: 880, right: 1220 }, size, viewport, BESIDE), { top: 176, left: 568, side: "left", arrow: 40 }); // a control outside a menu (a chip): below it, the arrow at its middle, kept from the card's corners assert.deepEqual(placeCard({ top: 100, left: 20, right: 120, bottom: 130 }, { top: 100, left: 20, right: 120, bottom: 130 }, size, viewport, ["below", "above"]), { top: 142, left: 8, side: "below", arrow: 62 }); // never past the window's bottom beside a control low on the page assert.equal(placeCard({ top: 760, left: 100, right: 140, bottom: 790 }, { top: 700, left: 90, right: 400, bottom: 790 }, size, viewport, BESIDE).top, 712); // a bottom sheet over the whole window: no side with room, at the top without an arrow const phone = { width: 390, height: 844 }; assert.deepEqual(placeCard({ top: 300, left: 0, right: 390, bottom: 340 }, { top: 40, left: 0, right: 390, bottom: 844 }, size, phone, ["above"]), { top: 8, left: 45, side: null, arrow: 0 }); // the room above a sheet that leaves it: there, over the dimmed report assert.equal(placeCard({ top: 500, left: 0, right: 390, bottom: 540 }, { top: 400, left: 0, right: 390, bottom: 844 }, size, phone, ["above"]).side, "above"); }); test("the card never covers the origin or its ring: beside the menu it moves clear of them, above a short sheet it takes the window's top or bottom edge (#1166, #1167)", () => { // 1280 x 500, a date's units: the level as tall as the window, left of the menu its middle is on the chip the menu opened from const level = { top: 48, left: 590, right: 996, bottom: 485 }; const menu = { top: 8, left: 583, right: 1003, bottom: 492 }; const card = { width: 303, height: 109 }; const chip = { top: 283, left: 526, right: 790, bottom: 316 }; const ring = { top: 17, left: 658, right: 845, bottom: 35 }; const BESIDE = ["right", "left", "below", "above"]; assert.deepEqual(placeCard(level, menu, card, { width: 1280, height: 500 }, BESIDE), { top: 212, left: 268, side: "left", arrow: 54.5 }); // just above the chip, the arrow still at the level assert.deepEqual(placeCard(level, menu, card, { width: 1280, height: 500 }, BESIDE, [chip, ring]), { top: 162, left: 268, side: "left", arrow: 93 }); // no room above a taller box: below it, the arrow kept from the card's corner assert.deepEqual(placeCard(level, menu, card, { width: 1280, height: 500 }, BESIDE, [{ ...chip, top: 100, bottom: 240 }]), { top: 252, left: 268, side: "left", arrow: 16 }); // 390 x 640: the sheet leaves 115 px above it, too few for card and arrow; its head's ring at 128 const phone = { width: 390, height: 640 }; const units = { top: 159, left: 11, right: 379, bottom: 629 }; const sheet = { top: 115, left: 0, right: 390, bottom: 640 }; const head = { top: 128, left: 79, right: 266, bottom: 146 }; assert.deepEqual(placeCard(units, sheet, card, phone, ["above"], [head]), { top: 8, left: 43.5, side: null, arrow: 0 }); // a taller card (German) would cover the head at the top: at the bottom, over the end of the list assert.deepEqual(placeCard(units, sheet, { width: 320, height: 131 }, phone, ["above"], [head]), { top: 501, left: 35, side: null, arrow: 0 }); }); test("the dimmed report: holes around the menu and the origin, grown a little, cut to the report, never over each other", () => { const report = { top: 0, left: 0, right: 1000, bottom: 600 }; // the chip inside its own hole is that hole; a menu that overlaps it: the parts of the menu beside it const holes = dimHoles([{ top: 100, left: 100, right: 200, bottom: 130 }, { top: 120, left: 150, right: 400, bottom: 400 }], report, 0); const area = (bs) => bs.reduce((sum, b) => sum + (b.right - b.left) * (b.bottom - b.top), 0); assert.equal(area(holes), 100 * 30 + 250 * 280 - 50 * 10); for (const [i, a] of holes.entries()) { for (const b of holes.slice(i + 1)) { assert.ok(a.right <= b.left || b.right <= a.left || a.bottom <= b.top || b.bottom <= a.top, "no two holes overlap"); } } assert.equal(area(dimHoles([{ top: 10, left: 10, right: 20, bottom: 20 }, { top: 0, left: 0, right: 50, bottom: 50 }], report, 0)), 50 * 50); // grown by the pad, cut at the report's edge; one outside the report: none assert.deepEqual(dimHoles([{ top: 2, left: 990, right: 1100, bottom: 30 }, { top: 700, left: 0, right: 10, bottom: 800 }], report, 6), [{ top: 0, left: 984, right: 1000, bottom: 36 }]); // the path: the report, then each hole, relative to the report's box assert.equal(dimPath({ top: 10, left: 20, right: 120, bottom: 60 }, [{ top: 20, left: 30, right: 40, bottom: 30 }]), "M0,0H100V50H0ZM10,10H20V20H10Z"); }); test("the docs links: the pivotkit site, the host's base URL or function, or none; never a script", () => { const topic = HELP_TOPICS.find((t) => t.id === "top-n"); const site = "https://docs.example"; assert.equal(docsHref(topic, undefined, site), "https://docs.example/use/filters/#top-n"); assert.equal(docsHref(topic, "https://intranet.example/pivot", site), "https://intranet.example/pivot/use/filters/#top-n"); assert.equal(docsHref(topic, "/docs/", site), "/docs/use/filters/#top-n"); assert.equal(docsHref(topic, (id) => `https://wiki.example/pivot/${id}`, site), "https://wiki.example/pivot/top-n"); assert.equal(docsHref(topic, () => null, site), null); assert.equal(docsHref(topic, false, site), null); assert.equal(docsHref(topic, () => "javascript:alert(1)", site), null); assert.equal(docsHref(topic, "javascript:alert(1)//", site), null); assert.equal(docsHref({ ...topic, docs: "use/index.md#where-to-start" }, undefined, site), "https://docs.example/use/#where-to-start"); // a host function that throws: no link, said once however often the help asks const broken = () => { throw new Error("no wiki"); }; const thrown = warnings(() => [docsHref(topic, broken, site), docsHref({ id: "vpn", own: true }, broken, site)]); assert.deepEqual(thrown, { value: [null, null], said: ["pivotkit: docsUrl threw: no docs link"] }); }); /** Runs `fn` with console.warn caught: what it returned, and the warnings. */ function warnings(fn) { const said = []; const warn = console.warn; console.warn = (text) => said.push(text); try { return { value: fn(), said }; } finally { console.warn = warn; } } const ids = (topics) => topics.map((t) => t.id); const own = (extra = {}) => ({ id: "vpn", question: "How do I reach the VPN?", answer: "Open the portal.", ...extra }); test("helpTopics: every built-in question by default, none, only those listed, and the host's own first", () => { const all = ids(HELP_TOPICS); assert.deepEqual(ids(helpTopicsOf(undefined)), all); assert.deepEqual(ids(helpTopicsOf({})), all); assert.deepEqual(ids(helpTopicsOf({ builtIn: true })), all); assert.deepEqual(helpTopicsOf({ builtIn: false }), []); // a list: only those, in the built-in order; to hide one, list the others assert.deepEqual(ids(helpTopicsOf({ builtIn: ["export", "filter"] })), ["filter", "export"]); assert.deepEqual(ids(helpTopicsOf({ builtIn: all.filter((id) => id !== "share") })), all.filter((id) => id !== "share")); // own questions come first, then the built-in ones; only own ones with builtIn false assert.deepEqual(ids(helpTopicsOf({ own: [own(), own({ id: "printer" })] })), ["vpn", "printer", ...all]); assert.deepEqual(ids(helpTopicsOf({ builtIn: false, own: [own()] })), ["vpn"]); // a text in English and German, or one text for both; the group: a built-in one, a text, or "general" const [a, b, c] = helpTopicsOf({ builtIn: false, own: [own(), own({ id: "b", question: { en: "Where?", de: "Wo?" }, group: "filter" }), own({ id: "c", group: { en: "Network", de: "Netzwerk" } })] }); assert.deepEqual([a.question, a.answer, a.group, a.own], [{ en: "How do I reach the VPN?", de: "How do I reach the VPN?" }, { en: "Open the portal.", de: "Open the portal." }, "general", true]); assert.deepEqual([b.question, b.group, c.group], [{ en: "Where?", de: "Wo?" }, "filter", { en: "Network", de: "Netzwerk" }]); // English alone: the German report shows it, marked as English (#1133); one text counts as every language assert.deepEqual(helpTopicsOf({ builtIn: false, own: [own({ question: { en: "Only English" } })] })[0].question, { en: "Only English", de: "Only English", from: "en" }); assert.deepEqual(textLang({ en: "Only English", de: "Only English", from: "en" }, "de"), "en"); assert.deepEqual([textLang({ en: "Only English", de: "Only English", from: "en" }, "en"), textLang(a.question, "de"), textLang(b.question, "de")], [undefined, undefined, undefined]); }); test("helpTopics: an own group named like a built-in one joins it, in either language and any case (#1134)", () => { const groups = helpTopicsOf({ builtIn: false, own: [own({ id: "a", group: "Fields" }), own({ id: "b", group: { en: "Filter and sort", de: "Filtern und sortieren" } }), own({ id: "c", group: " felder " }), own({ id: "d", group: "Fields of work" })] }).map((t) => t.group); assert.deepEqual(groups, ["fields", "filter", "fields", { en: "Fields of work", de: "Fields of work" }]); // one section, the built-in one, with the own question first const sections = helpSections(helpTopicsOf({ builtIn: ["add-field"], own: [own({ group: "Fields" })] })); assert.deepEqual(sections.map((s) => [s.key, ids(s.topics)]), [["fields", ["vpn", "add-field"]]]); }); test("helpTopics: a wrong entry is left out with a warning that names it and why; the rest show", () => { const long = "x".repeat(OWN_LIMITS.answer + 1); const bad = [ [own({ id: "with space" }), /own\[0\].*id/], [own({ id: "x".repeat(OWN_LIMITS.id + 1) }), new RegExp(`own\\[0\\] "x{${OWN_LIMITS.id}}" is left out: id must be 1 to ${OWN_LIMITS.id}`)], [own({ id: "filter" }), /own\[0\] "filter".*taken/], [own({ id: "shortcuts" }), /own\[0\] "shortcuts".*taken/], [own({ id: "search" }), /own\[0\] "search".*taken/], [own({ id: "a1", question: "" }), /own\[0\] "a1".*question/], [own({ id: "a2", question: "Bold?" }), /own\[0\] "a2".*question.*markup/], [own({ id: "a3", answer: long }), new RegExp(`own\\[0\\] "a3".*answer.*${OWN_LIMITS.answer}`)], [own({ id: "a4", answer: { en: "Yes", de: 1 } }), /own\[0\] "a4".*answer/], [own({ id: "a5", group: "x".repeat(OWN_LIMITS.group + 1) }), /own\[0\] "a5".*group/], [own({ id: "a6", docs: 3 }), /own\[0\] "a6".*docs/], // show: only an id, never a selector; its text as short as a question [own({ id: "s1", show: "vpn-box" }), /own\[0\] "s1".*show must be/], [own({ id: "s2", show: {} }), /own\[0\] "s2".*show must be/], [own({ id: "s3", show: { target: "#vpn-box" } }), /own\[0\] "s3".*show must be/], [own({ id: "s4", show: { target: "nav a" } }), /own\[0\] "s4".*show must be/], [own({ id: "s5", show: { target: "x".repeat(OWN_LIMITS.id + 1) } }), new RegExp(`own\\[0\\] "s5".*target.*1 to ${OWN_LIMITS.id}`)], [own({ id: "s6", show: { target: "vpn-box", text: "x".repeat(OWN_LIMITS.question + 1) } }), new RegExp(`own\\[0\\] "s6".*text 1 to ${OWN_LIMITS.question}`)], [own({ id: "s7", show: { target: "vpn-box", text: "Here" } }), /own\[0\] "s7".*markup/], [own({ id: "s8", show: { target: "vpn-box", text: "" } }), /own\[0\] "s8".*show must be/], ["text", /own\[0\]/] ]; for (const [entry, why] of bad) { const { value, said } = warnings(() => helpTopicsOf({ builtIn: false, own: [entry, own({ id: "ok" })] })); assert.deepEqual(ids(value), ["ok"], JSON.stringify(entry).slice(0, 60)); assert.equal(said.length, 1, JSON.stringify(entry).slice(0, 60)); assert.match(said[0], /^pivotkit: helpTopics/); assert.match(said[0], why); } // the second of two with one id; a mistake is said once per page, however often the help shows const twice = warnings(() => helpTopicsOf({ builtIn: false, own: [own(), own({ answer: "Again" })] })); assert.deepEqual(ids(twice.value), ["vpn"]); assert.match(twice.said[0], /own\[1\] "vpn".*taken/); // more than OWN_LIMITS.count: the first ones, and a warning const many = Array.from({ length: OWN_LIMITS.count + 2 }, (_, i) => own({ id: `q${i}` })); const cut = warnings(() => helpTopicsOf({ builtIn: false, own: many })); assert.equal(cut.value.length, OWN_LIMITS.count); assert.match(cut.said[0], new RegExp(`own.*${OWN_LIMITS.count}`)); // a wrong shape: the built-in questions, and one warning for the page; a wrong part alone: only that part is dropped const shapes = warnings(() => ["all", ["vpn"]].map((input) => ids(helpTopicsOf(input)))); assert.deepEqual(shapes.value, Array(2).fill(ids(HELP_TOPICS))); assert.deepEqual(shapes.said, ["pivotkit: helpTopics must be { builtIn, own }; the built-in questions show"]); const parts = warnings(() => [ids(helpTopicsOf({ builtIn: "yes", own: [own()] })), ids(helpTopicsOf({ builtIn: false, own: { id: "vpn" } }))]); assert.deepEqual(parts.value, [["vpn", ...ids(HELP_TOPICS)], []]); assert.equal(parts.said.length, 2); assert.match(parts.said[0], /builtIn must be true, false or a list/); assert.match(parts.said[1], /own must be a list/); assert.deepEqual(warnings(() => ids(helpTopicsOf(null))), { value: ids(HELP_TOPICS), said: [] }); // a built-in id that does not exist const unknown = warnings(() => helpTopicsOf({ builtIn: ["export", "nope"] })); assert.deepEqual(ids(unknown.value), ["export"]); assert.match(unknown.said[0], /builtIn.*"nope"/); }); test("the list: the twelve asked most in their groups, every question under All questions, the search finds every question", () => { // without own questions: the questions marked top, in the groups' order; All questions holds more const builtIns = helpList(HELP_TOPICS, "", "en"); assert.deepEqual(builtIns.sections.map((s) => s.key), HELP_GROUPS); assert.deepEqual(builtIns.sections.flatMap((s) => ids(s.topics)), FIRST); assert.equal(builtIns.more, true); // All questions: every one, in its group, in the groups' order assert.deepEqual(helpSections(HELP_TOPICS).map((s) => [s.key, s.topics.length]), [["fields", 1], ["filter", 7], ["table", 5], ["chart", 7], ["values", 5], ["export", 8]]); // the host's own first: they take the list's first places, in their groups const mine = Array.from({ length: 3 }, (_, i) => own({ id: `q${i}`, question: `Own question ${i}?`, group: i === 1 ? "filter" : undefined })); const topics = helpTopicsOf({ own: mine }); const list = helpList(topics, "", "en"); // the host's own groups first, then the built-in ones in their order, an own question first in its // group; three own questions leave room for the first nine built-in ones (Export and more is under All questions) assert.deepEqual(list.sections.map((s) => s.key), ["general", "fields", "filter", "table", "chart", "values"]); const shown = list.sections.flatMap((s) => ids(s.topics)); assert.equal(shown.length, HELP_LIST); assert.deepEqual(shown.slice(0, 4), ["q0", "q2", "add-field", "q1"]); assert.equal(list.more, true); assert.deepEqual(helpSections(topics).find((s) => s.key === "filter").topics[0].id, "q1"); // a host that lists only some built-in questions, all shown: no All questions assert.equal(helpList(helpTopicsOf({ builtIn: ["filter", "export"] }), "", "en").more, false); // none of them asked most: its first ones, not an empty list (neutral review of round 3) const picked = helpList(helpTopicsOf({ builtIn: ["undo", "print", "legend"] }), "", "en"); assert.deepEqual([picked.sections.flatMap((s) => ids(s.topics)), picked.more], [["legend", "print", "undo"], false]); // the search: every question, not only those listed first, by its words or by more words (N1 of the review) const found = (query, lang = "en") => helpList(topics, query, lang).sections.flatMap((s) => ids(s.topics)); assert.deepEqual(found("pdf"), ["print"]); assert.deepEqual(found("undo"), ["undo"]); assert.deepEqual(found("csv"), ["export-csv", "load-data"]); assert.ok(found("column").includes("swap")); assert.ok(found("rückgängig", "de").includes("undo")); // every word, in any order assert.deepEqual(found("save pdf"), ["print"]); assert.ok(found("Own question").length === 3 && found("Own question").includes("q2")); assert.equal(helpList(topics, "pdf", "en").more, false); // a group of the host's own: its text is the heading's key; nothing found: no sections const named = helpList(helpTopicsOf({ builtIn: false, own: [own({ group: { en: "Network", de: "Netzwerk" } })] }), "vpn", "en"); assert.deepEqual(named.sections.map((s) => [s.key, s.title]), [[":Network", { en: "Network", de: "Netzwerk" }]]); assert.deepEqual(helpList(topics, "nothing like it", "en"), { sections: [], more: false }); // a text is shown as it is: braces are not names to fill assert.equal(helpTopicsOf({ builtIn: false, own: [own({ answer: "Type {rows} as is." })] })[0].answer.en, "Type {rows} as is."); }); test("the search matches the starts of words, umlauts folded both ways, the shortcuts' row the same (#1150)", () => { const found = (query, lang) => helpList(HELP_TOPICS, query, lang).sections.flatMap((s) => ids(s.topics)); // a word's start, not its middle: "bild" finds the chart's picture ("Bild"), not "Vollbild" assert.deepEqual(found("bild", "de"), ["chart-image"]); assert.ok(found("voll", "de").includes("full-screen")); assert.deepEqual(found("creen", "en"), []); // umlauts as readers type them without the keys: ae, oe, ue, ss, and the other way round assert.ok(found("rueckgaengig", "de").includes("undo")); assert.deepEqual(found("rueckgaengig", "de"), found("rückgängig", "de")); assert.ok(found("groesste", "de").includes("sort-value")); assert.ok(found("RÜCK", "de").includes("undo")); // "top" is a German word for the top items too, as is "zehn" for the 10 for (const query of ["top", "top 10", "Top-10", "top-n", "zehn"]) { assert.ok(found(query, "de").includes("top-n"), query); } // the shortcuts' row: by the same rule, every word assert.equal(helpMatch("Tastenkürzel", "tastenkuerzel", "de"), true); assert.equal(helpMatch("Keyboard shortcuts", "short key", "en"), true); assert.equal(helpMatch("Keyboard shortcuts", "cuts", "en"), false); assert.equal(helpMatch("Keyboard shortcuts", "", "en"), true); }); test("an own question's link: its own address, else the host's function, never the pivotkit site or a script", () => { const site = "https://docs.example/"; const [mine] = helpTopicsOf({ builtIn: false, own: [own({ docs: "https://intranet.example/vpn" })] }); assert.equal(docsHref(mine, undefined, site), "https://intranet.example/vpn"); // the question's own link wins over the host's docsUrl, also over false assert.equal(docsHref(mine, false, site), "https://intranet.example/vpn"); assert.equal(docsHref(mine, "https://other.example/", site), "https://intranet.example/vpn"); const [plain] = helpTopicsOf({ builtIn: false, own: [own()] }); assert.equal(docsHref(plain, undefined, site), null); assert.equal(docsHref(plain, "https://other.example/", site), null); assert.equal(docsHref(plain, (id) => `https://wiki.example/${id}`, site), "https://wiki.example/vpn"); const [none] = helpTopicsOf({ builtIn: false, own: [own({ docs: false })] }); assert.equal(docsHref(none, (id) => `https://wiki.example/${id}`, site), null); const [script] = helpTopicsOf({ builtIn: false, own: [own({ docs: "javascript:alert(1)" })] }); assert.equal(docsHref(script, undefined, site), null); const [relative] = helpTopicsOf({ builtIn: false, own: [own({ docs: "/wiki/vpn" })] }); assert.equal(docsHref(relative, undefined, site), "/wiki/vpn"); }); test("an own question's Show me: an element's id, its card text or none; without show, no Show me", () => { const [plain, bare, said] = helpTopicsOf({ builtIn: false, own: [own(), own({ id: "b", show: { target: "vpn-box" } }), own({ id: "c", show: { target: "vpn_box-2", text: { en: "Here it is.", de: "Hier ist es." } } })] }); assert.equal(plain.show, undefined); assert.deepEqual(bare.show, { target: "vpn-box", text: null }); assert.deepEqual(said.show, { target: "vpn_box-2", text: { en: "Here it is.", de: "Hier ist es." } }); assert.deepEqual(helpTopicsOf({ builtIn: false, own: [own({ show: { target: "x", text: "One text" } })] })[0].show.text, { en: "One text", de: "One text" }); // the card: its own text, else the answer's first paragraph, cut after a word to a question's length assert.equal(ownCardText(said, "de"), "Hier ist es."); assert.equal(ownCardText(bare, "en"), "Open the portal."); const word = "word ".repeat(OWN_LIMITS.answer / 10); const [long] = helpTopicsOf({ builtIn: false, own: [own({ answer: `\n${word}\nSecond.`, show: { target: "x" } })] }); const card = ownCardText(long, "en"); assert.ok(card.length <= OWN_LIMITS.question && card.endsWith("word…"), card); // the sentence where the page has no such element, in both languages assert.ok(HELP_TEXTS.en.noTarget && HELP_TEXTS.de.noTarget); }); test("an own question's element: by its id in the report's tree, then outwards through each shadow host, never the report's own or a hidden one", () => { /** A tree (a document or a shadow root) holding elements by id; a shadow root has its host. */ const tree = (ids, host = null) => ({ host, getElementById: (id) => ids[id] ?? null }); const el = (name, root, shown = true) => ({ name, getRootNode: () => root, getClientRects: () => (shown ? [{}] : []) }); const report = { contains: (n) => n?.name === "inside", getRootNode: () => null }; // the report in the document (pivotkit-react on a page) const doc = tree({}); doc.getElementById = (id) => ({ box: el("box", doc), mine: { name: "inside" }, folded: el("folded", doc, false) })[id] ?? null; report.getRootNode = () => doc; assert.equal(hostElement(report, "box")?.name, "box"); assert.equal(hostElement(report, "nope"), null); // one the page does not show (display: none) has nothing to ring assert.equal(hostElement(report, "folded"), null); // one of the report's own is never marked assert.equal(hostElement(report, "mine"), null); // the report in a shadow root (pivotkit-element, or a React host's): the shadow root first, then the // page around its host; an element of the report's own there is passed over for the page's const page = tree({ box: el("page-box", null), shared: el("page-shared", null) }); const host = el("host", page); const shadow = tree({ shared: { name: "inside" }, near: el("near", null) }, host); report.getRootNode = () => shadow; assert.equal(hostElement(report, "near")?.name, "near"); assert.equal(hostElement(report, "box")?.name, "page-box"); assert.equal(hostElement(report, "shared")?.name, "page-shared"); // nested: a shadow root inside another one, out to the document const outer = tree({ mid: el("mid", null) }, el("outer-host", page)); const inner = tree({}, el("inner-host", outer)); report.getRootNode = () => inner; assert.equal(hostElement(report, "mid")?.name, "mid"); assert.equal(hostElement(report, "box")?.name, "page-box"); });