// The report's "How do I…?" help (#919, pivotkit-react's help-*.js): it never opens by itself; its // list has a search and the questions in their groups; every question's Show me walks its steps, each // control marked by a ring of its own, enabled and visible, the card at it, at desktop and phone width, // light and dark, English and German, the report changed only by the reader's click or "Do it for me"; // a field the question needs is added first, greyed-out controls are explained; Escape ends it; More holds // the help and its button's switch; help={false} and help="more"; a host's docsUrl in every link; // the web component's shadow root; a host's own questions (helpTopics): listed first, a built-in one // left out, past HELP_LIST only by the search, their own links, and Show me on an element of the page // (pages/element/help.html). tests/help-docs.test.js checks that the docs anchors exist, pivotkit-react's // test/help.test.js what Show me plans for each question and how helpTopics is checked. import { animationsSettled, expect, test, textOf, toolbar, twoFrames, TEXTS } from "./fixtures.js"; import { HELP_GROUPS, HELP_LIST, HELP_TEXTS, HELP_TOPICS } from "../../packages/pivotkit-react/src/help-topics.js"; const PHONE = { width: 390, height: 844 }; /** The ring's colour in each theme (styles.css: --pk-guide-ring). */ const RING = { light: "rgb(181, 74, 0)", dark: "rgb(255, 166, 92)" }; /** The playground as the docs site embeds it (a date in Columns), or another data set, with its data and toolbar settled. */ async function open(page, query = "", data = "weather") { await page.goto(`?data=${data}${query}`); await expect(page.locator('[data-testid="pivot-table"], [data-testid="empty-state"]').first()).toBeVisible(); await expect(page.getByTestId("skeleton")).toHaveCount(0); await twoFrames(page); } /** Opens the help from its button, or from More where the button is not in the toolbar. */ async function openHelp(page) { const button = page.getByTestId("help"); if (await button.count()) { await button.click(); } else { await page.getByTestId("more").click(); await page.getByTestId("more-help").click(); } await expect(page.getByTestId("help-list")).toBeVisible(); } /** * Whether the marked control is in the window and not under anything else of the page, and the card * is in the window, covering neither the control nor the origin, nor the menu the control is in (a * bottom sheet's full width leaves room above it only: there, when the window has it), nor ever that * menu's head (Back, the title, the field's name). */ function judge(page) { return page.evaluate(() => { const marked = document.querySelector("[data-pk-guided]"); const card = document.querySelector('[data-testid="help-card"]'); if (!marked || !card) return "nothing marked"; const r = marked.getBoundingClientRect(); const x = r.left + Math.min(r.width / 2, 40); const y = r.top + Math.min(r.height / 2, 20); if (r.width === 0 || r.top < 0 || r.bottom > innerHeight + 1 || r.left < 0 || r.right > innerWidth + 1) return `out of the window: ${JSON.stringify(r)}`; const hit = document.elementFromPoint(x, y); if (!hit || !(marked.contains(hit) || hit.contains(marked))) return `covered by ${hit?.className}`; const c = card.getBoundingClientRect(); if (c.width === 0 || c.top < 0 || c.bottom > innerHeight + 1) return "the card is not in the window"; const over = (b) => b.left < c.right - 1 && c.left < b.right - 1 && b.top < c.bottom - 1 && c.top < b.bottom - 1; if (over(r)) return "the card covers the control"; // the origin under a bottom sheet's scrim (a field's row in the drawer) may be under the card const origin = document.querySelector("[data-pk-guide-origin]"); const sheet = marked.closest(".pk-sheet"); if (origin && !(sheet && !sheet.contains(origin)) && over(origin.getBoundingClientRect())) return "the card covers the origin"; const menu = marked.closest(".pk-popover"); const head = menu ? [...menu.querySelectorAll('[data-testid="level-back"], [data-testid="level-title"], [data-testid="menu-head"]')].filter((h) => h.getClientRects().length) : []; if (head.some((h) => over(h.getBoundingClientRect()))) return "the card covers the menu's head"; if (menu && over(menu.getBoundingClientRect()) && !(menu.classList.contains("pk-sheet") && menu.getBoundingClientRect().top < c.height + 24)) return "the card covers the menu"; // outside a menu, not over its neighbours: the field list, the zones, the toolbar, the tabs // (in a drawer too narrow to stand beside, at the control) const group = menu ? null : marked.closest('[data-testid="field-list"], [data-testid="zone-section"], .pk-toolbar, .pk-tabs'); const drawer = group?.matches('[data-testid="field-list"]') && innerWidth - group.getBoundingClientRect().right < c.width + 24; const neighbours = group && !drawer ? [...group.querySelectorAll("button, input, select")].filter((b) => !b.contains(marked) && !marked.contains(b) && !(origin && origin.contains(b)) && b.getClientRects().length) : []; if (neighbours.some((b) => over(b.getBoundingClientRect()))) return "the card covers the controls around it"; return "ok"; }); } /** Whether the origin's ring lies over the origin (or `selector`'s words, a sheet's head), to the pixel. */ const onOrigin = (page, selector = "[data-pk-guide-origin]") => page.evaluate((sel) => { const ring = document.querySelector('[data-testid="help-origin"]')?.getBoundingClientRect(); const el = document.querySelector(sel); if (!ring || !el) return false; const words = document.createRange(); words.selectNodeContents(el); const box = sel === "[data-pk-guide-origin]" ? el.getBoundingClientRect() : words.getBoundingClientRect(); return ["top", "left", "width", "height"].every((k) => Math.abs(ring[k] - box[k]) <= 1); }, selector); /** A sentence of HELP_TEXTS with its names as wildcards, as a whole-text pattern. */ const sentence = (/** @type {string[]} */ keys, /** @type {"en" | "de"} */ lang) => new RegExp(`^(${keys.map((k) => HELP_TEXTS[lang][k].replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/\\\{\w+\\\}/g, ".+")).join("|")})$`); /** * Walks a running Show me to its end with "Do it for me", as a reader who lets it act: at each step one * control marked, enabled and in view (judge), its ring or its origin's in the theme's colour, the * count the same, the report unchanged (Undo off) until a step that adds a field; at the last step * "Done" ends it and takes every mark away. A view to save is named. The cards' texts. * @returns {Promise} */ async function walk(page, id, theme = "light") { const texts = []; let total = null; let changed = false; for (let n = 1; n <= 12; n++) { const card = page.getByTestId("help-card"); await expect(card, `${id}: step ${n}`).toBeVisible(); const marked = page.locator("[data-pk-guided]"); await expect(marked, `${id}: step ${n}`).toHaveCount(1); expect(await marked.evaluate((el) => el.matches(":disabled, [aria-disabled='true']")), `${id}: step ${n} greyed out`).toBe(false); await expect.poll(() => judge(page), { message: `${id}: step ${n}` }).toBe("ok"); // its own ring, or the origin's around it (a cell's ring fades in) await expect.poll(() => marked.evaluate((el) => (el.closest("[data-pk-guide-origin]") ? getComputedStyle(el.getRootNode().querySelector('[data-testid="help-origin"]')).outlineColor : getComputedStyle(el).boxShadow)), { message: `${id}: step ${n}` }).toContain(RING[theme]); // one step: no count const [at, of] = (await page.getByTestId("help-card-count").count()) ? (await page.getByTestId("help-card-count").textContent()).match(/\d+/g).map(Number) : [1, 1]; expect([at, of], id).toEqual([n, total ?? of]); total = of; await expect(page.getByTestId("help-card-text")).not.toHaveText(""); texts.push(await page.getByTestId("help-card-text").textContent()); if (!changed && (await page.getByTestId("undo").isVisible())) await expect(page.getByTestId("undo"), `${id}: step ${n} changed the report`).toBeDisabled(); if (await page.getByTestId("help-done").count()) { expect(n, id).toBe(total); await page.getByTestId("help-done").click(); await expect(card).toHaveCount(0); await expect(page.locator("[data-pk-guided], [data-pk-guide-origin]")).toHaveCount(0); return texts; } // adding a field and switching the tab change the report (Undo takes them back) changed ||= /^(field-rows-|show-)/.test((await marked.getAttribute("data-testid")) ?? ""); if (await page.getByTestId("saved-view-name").isVisible()) { // naming a view is the reader's: no Do it for me; saved, the guide goes on await expect(page.getByTestId("help-do")).toHaveCount(0); await page.getByTestId("saved-view-name").fill(`Walked ${n}`); await page.keyboard.press("Enter"); } else { await page.getByTestId("help-do").click(); } } throw new Error(`${id}: no end after 12 steps`); } test("the help never opens by itself; its button names it, its list has a search and the questions in groups", async ({ page }) => { await open(page); await expect(page.getByTestId("help")).toHaveAccessibleName(textOf("helpButton")); await expect(page.getByTestId("help")).toHaveAttribute("aria-haspopup", "dialog"); // a moment with nothing done: still closed await page.waitForTimeout(300); // a fixed sleep: checks that nothing opens for a while await expect(page.getByTestId("help-panel")).toHaveCount(0); await page.getByTestId("help").click(); const dialog = page.getByRole("dialog", { name: textOf("helpButton") }); await expect(dialog).toBeVisible(); // the search takes the focus; the list is a list box, not a menu await expect(page.getByTestId("help-search")).toBeFocused(); await expect(dialog.getByRole("menu")).toHaveCount(0); const list = dialog.getByRole("listbox"); await expect(list.getByRole("group")).toHaveText([/^Fields/, /^Filter and sort/, /^Table/, /^Chart/, /^Values/, /^Export and more/, /Keyboard shortcuts/]); // the playground offers drill-down, saving, links and files: the twelve questions asked most, then // the shortcuts; below them, outside the list, All questions with how many there are const first = HELP_TOPICS.filter((t) => t.top); expect(first.length).toBeLessThanOrEqual(HELP_LIST); await expect(list.getByRole("option")).toHaveText([...first.map((t) => t.question.en), textOf("shortcutsTitle")]); const all = dialog.getByTestId("help-all"); await expect(all).toHaveAccessibleName(new RegExp(`^${HELP_TEXTS.en.all} \\(\\d+\\)$`)); await expect(list.getByTestId("help-all")).toHaveCount(0); // the down arrow goes from the search into the list, and on past the shortcuts to All questions await page.keyboard.press("ArrowDown"); await expect(page.getByTestId(`help-${first[0].id}`)).toBeFocused(); await page.keyboard.press("End"); await expect(all).toBeFocused(); // the search finds every question, also one not listed first, also by another word (N1 of the review); // the width measured once the popover has stopped moving in await animationsSettled(page); const width = await dialog.evaluate((el) => el.getBoundingClientRect().width); await page.getByTestId("help-search").fill("own file"); await expect(list.getByRole("option")).toHaveText([HELP_TOPICS.find((t) => t.id === "load-data").question.en]); await expect(all).toHaveCount(0); await page.getByTestId("help-search").fill("excel"); await expect(list.getByRole("option")).toHaveText(["How do I export to Excel?", "How do I use my own file?"]); await page.getByTestId("help-search").fill("pdf"); await expect(list.getByRole("option")).toHaveText(["How do I print or save as PDF?"]); await page.getByTestId("help-search").fill("nothing like it"); await expect(page.getByTestId("help-nothing")).toHaveText(HELP_TEXTS.en.nothing); // the popover keeps its width, and the way out clears the search expect(await dialog.evaluate((el) => el.getBoundingClientRect().width)).toBe(width); await page.getByTestId("help-clear").click(); await expect(page.getByTestId("help-search")).toHaveValue(""); await expect(page.getByTestId("help-search")).toBeFocused(); await expect(list.getByRole("option")).toHaveCount(first.length + 1); }); test("All questions: every question in its group as a level of its own; Back and Escape go back the way they came", async ({ page }) => { await open(page); await page.getByTestId("help").click(); await page.getByTestId("help-all").click(); await expect(page.getByTestId("help-title")).toHaveText(HELP_TEXTS.en.all); await expect(page.getByTestId("help-title")).toBeFocused(); const list = page.getByTestId("help-list"); await expect(list.getByRole("group")).toHaveText([/^Fields/, /^Filter and sort/, /^Table/, /^Chart/, /^Values/, /^Export and more/]); // every question the playground offers (full screen only where the browser can) const full = await page.evaluate(() => document.fullscreenEnabled); await expect(list.getByRole("option")).toHaveCount(HELP_TOPICS.length - (full ? 0 : 1)); await expect(page.getByTestId("help-all")).toHaveCount(0); // the list scrolls in its level: a fade at its edge says it goes on (M2 of the review) await expect(list).toHaveAttribute("data-pk-more", ""); // a question there, then Back: All questions again, the focus on the question await page.getByTestId("help-undo").click(); await expect(page.getByTestId("help-title")).toHaveText("How do I undo a step?"); // the title takes the focus without a ring around it (N4 of the review) await expect(page.getByTestId("help-title")).toBeFocused(); expect(await page.getByTestId("help-title").evaluate((el) => getComputedStyle(el).outlineStyle)).toBe("none"); await page.getByTestId("help-back").click(); await expect(page.getByTestId("help-title")).toHaveText(HELP_TEXTS.en.all); await expect(page.getByTestId("help-undo")).toBeFocused(); await page.getByTestId("help-undo").click(); await page.keyboard.press("Escape"); await expect(page.getByTestId("help-undo")).toBeFocused(); // Escape on All questions: the list, the focus on All questions; again: closed await page.keyboard.press("Escape"); await expect(page.getByTestId("help-all")).toBeFocused(); await page.keyboard.press("Escape"); await expect(page.getByTestId("help-panel")).toHaveCount(0); }); test("a question opens its answer as a level with Back: steps, Show me, the docs; Escape goes back, then closes", async ({ page }) => { await open(page); await page.getByTestId("help").click(); await page.getByTestId("help-top-n").click(); await expect(page.getByTestId("help-title")).toHaveText("How do I show only the top 10?"); await expect(page.getByTestId("help-title")).toBeFocused(); await expect(page.getByTestId("help-steps").getByRole("listitem")).toHaveText(["Click a field in Rows: its menu opens.", "Choose “Top items”, then “Top 10” or a count of your own."]); await expect(page.getByTestId("help-show")).toHaveText(HELP_TEXTS.en.showMe); const docs = page.getByTestId("help-docs"); await expect(docs).toHaveAttribute("href", /\/use\/filters\/#top-n$/); await expect(docs).toHaveAttribute("target", "_blank"); await expect(docs).toHaveAccessibleName(`${HELP_TEXTS.en.readMore} ↗ ${HELP_TEXTS.en.newTab}`); // Escape: back to the list, the focus on the question; again: closed, the focus on the button await page.keyboard.press("Escape"); await expect(page.getByTestId("help-top-n")).toBeFocused(); await page.getByTestId("help-top-n").click(); await page.getByTestId("help-back").click(); await expect(page.getByTestId("help-top-n")).toBeFocused(); await page.keyboard.press("Escape"); await expect(page.getByTestId("help-panel")).toHaveCount(0); await expect(page.getByTestId("help")).toBeFocused(); // the keyboard shortcuts are the list's last row await page.getByTestId("help").click(); await page.getByTestId("help-shortcuts").click(); await expect(page.getByTestId("help-title")).toHaveText(textOf("shortcutsTitle")); await expect(page.getByTestId("shortcuts")).toContainText("Undo"); }); test("Show me walks the steps the reader clicks: the chip, Filter, the values; one Escape ends menu and card, the focus on the chip", async ({ page }) => { await open(page); await page.getByTestId("help").click(); await page.getByTestId("help-filter").click(); await page.getByTestId("help-show").click(); // step 1: the chip of the first field in Rows, its menu not open yet; the chip takes the focus const chip = page.getByTestId("chip-menu-City"); await expect(chip).toHaveAttribute("data-pk-guided", ""); await expect(chip).toBeFocused(); await expect(page.locator(".pk-popover:not(.pk-guide-card)")).toHaveCount(0); await expect(page.getByTestId("help-card-count")).toHaveText("Step 1 of 3"); await expect(page.getByTestId("help-card-text")).toHaveText("Click “City” to open its menu."); await expect(page.getByTestId("help-do")).toHaveText(HELP_TEXTS.en.doIt); // the whole chip is the origin: its ring over it, to the end; the rest of the report is dimmed const origin = page.locator('[data-chip="City"]'); await expect(origin).toHaveAttribute("data-pk-guide-origin", ""); await expect.poll(() => onOrigin(page)).toBe(true); await expect.poll(() => page.getByTestId("help-origin").evaluate((el) => getComputedStyle(el).outlineColor)).toBe(RING.light); await expect(page.getByTestId("help-dim")).toBeVisible(); // the card describes the marked control for a screen reader (N3 of the review) const status = page.getByTestId("help-card").getByRole("status"); await expect(status).toHaveText("Step 1 of 3. Click “City” to open its menu."); const textId = await status.getAttribute("id"); await expect(chip).toHaveAttribute("aria-describedby", new RegExp(`(^| )${textId.replace(/[^\w]/g, "\\$&")}$`)); // the reader clicks it: step 2, Filter in its menu, beside it the card with its arrow at Filter await chip.click(); const marked = page.locator(".pk-chip-menu [data-pk-guided]"); await expect(marked).toHaveAttribute("data-testid", "topic-filter"); await expect(marked).toBeFocused(); await expect(page.getByTestId("help-card-count")).toHaveText("Step 2 of 3"); await expect(page.getByTestId("help-card-text")).toHaveText("Choose “Filter”."); await expect.poll(() => judge(page)).toBe("ok"); await expect.poll(() => marked.evaluate((el) => getComputedStyle(el).boxShadow)).toContain(RING.light); await expect(origin).toHaveAttribute("data-pk-guide-origin", ""); await expect.poll(() => onOrigin(page)).toBe(true); // one Escape closes the menu and ends the guide; nothing marked, the focus back on the chip await page.keyboard.press("Escape"); await expect(page.locator(".pk-popover")).toHaveCount(0); await expect(page.getByTestId("help-card")).toHaveCount(0); await expect(page.locator("[data-pk-guided], [data-pk-guide-origin]")).toHaveCount(0); await expect(page.locator('[data-testid="help-dim"], [data-testid="help-origin"]')).toHaveCount(0); await expect(chip).toBeFocused(); // by the keyboard: Enter on each marked control takes the step, to the values; Done ends it await page.getByTestId("help").click(); await page.getByTestId("help-filter").click(); await page.getByTestId("help-show").click(); await expect(chip).toBeFocused(); await page.keyboard.press("Enter"); await expect(page.locator("[data-pk-guided]")).toBeFocused(); await page.keyboard.press("Enter"); await expect(page.getByTestId("help-card-count")).toHaveText("Step 3 of 3"); await expect(page.locator('[data-testid="level-filter"] .pk-values')).toHaveAttribute("data-pk-guided", ""); // the last step: the reader unticks values, the card stays; Done ends it, the menu stays open await page.locator('[data-testid="level-filter"] .pk-values input[type="checkbox"]').first().click(); await expect(page.getByTestId("help-card")).toBeVisible(); await page.getByTestId("help-done").click(); await expect(page.getByTestId("help-card")).toHaveCount(0); await expect(page.locator('[data-testid="level-filter"]')).toBeVisible(); await expect(page.locator("[data-pk-guided], [data-pk-guide-origin]")).toHaveCount(0); }); test("a short window, the menu over the chip: the origin's ring goes to the menu's head, never over its entries (UX review)", async ({ page }) => { await page.setViewportSize({ width: 1280, height: 600 }); await open(page, "", "tickets"); await page.getByTestId("help").click(); await page.getByTestId("help-filter").click(); await page.getByTestId("help-show").click(); while (!(await page.locator('.pk-popover [data-testid="topic-filter"][data-pk-guided]').count())) { await page.getByTestId("help-do").click(); await twoFrames(page); } const covered = await page.evaluate(() => { const m = document.querySelector(".pk-chip-menu").getBoundingClientRect(); const c = document.querySelector("[data-pk-guide-origin]").getBoundingClientRect(); return m.left < c.right && c.left < m.right && m.top < c.bottom && c.top < m.bottom; }); expect(covered, "the menu covers the chip at 1280 x 600").toBe(true); await expect.poll(() => onOrigin(page, '.pk-chip-menu [data-testid="menu-head"]')).toBe(true); await expect(page.getByTestId("help-origin")).toHaveText(`· ${TEXTS.zones.rows}`); // the values' level: its title carries it ("Team › Filter") await page.getByTestId("help-do").click(); await expect(page.locator('.pk-chip-menu [data-testid="level-title"]')).toBeVisible(); await expect.poll(() => onOrigin(page, '.pk-chip-menu [data-testid="level-title"]')).toBe(true); }); test("Show me changes the report only on the reader's click or Do it for me; a click elsewhere ends it", async ({ page }) => { await open(page, "", "tickets"); await page.getByTestId("help").click(); await page.getByTestId("help-add-field").click(); await page.getByTestId("help-show").click(); await expect(page.getByTestId("help-card-text")).toHaveText("“Status” is not in the report yet. Click the dots next to it to open its menu."); await expect(page.locator('[data-field="Status"]')).toHaveAttribute("data-pk-guide-origin", ""); await page.getByTestId("help-do").click(); await expect(page.locator("[data-pk-guided]")).toHaveAttribute("data-testid", "field-rows-Status"); await expect(page.getByTestId("help-card-text")).toHaveText(`Choose “${textOf("addTo", { zone: TEXTS.zones.rows })}”. This adds the field to your report.`); // a moment with the step on the card: nothing added await page.waitForTimeout(300); // a fixed sleep: checks that nothing changes for a while await expect(page.getByTestId("undo")).toBeDisabled(); await expect(page.locator('[data-zone="rows"] [data-chip="Status"]')).toHaveCount(0); // a click elsewhere (the page's heading) ends it, and changes nothing either await page.getByRole("heading", { name: "pivotkit playground" }).click(); await expect(page.getByTestId("help-card")).toHaveCount(0); await expect(page.getByTestId("undo")).toBeDisabled(); // Done on the last step: the reader's own choice, the guide ends await page.getByTestId("help").click(); await page.getByTestId("help-add-field").click(); await page.getByTestId("help-show").click(); await page.getByTestId("help-do").click(); await expect(page.getByTestId("help-done")).toBeVisible(); await page.locator("[data-pk-guided]").click(); await expect(page.locator('[data-zone="rows"] [data-chip="Status"]')).toHaveCount(1); await expect(page.getByTestId("help-card")).toHaveCount(0); await expect(page.getByTestId("undo")).toBeEnabled(); }); test("a question that needs a date in Rows or Columns: the answer names the data's date field, Show me adds it first", async ({ page }) => { await open(page, "", "tickets"); await page.getByTestId("help").click(); await page.getByTestId("help-group-dates").click(); await expect(page.getByTestId("help-notice")).toHaveText("There is no date field in Rows or Columns yet. This data has one: “Created”. “Show me” first shows you how to add it to Rows."); await expect(page.getByTestId("help-none")).toHaveCount(0); await page.getByTestId("help-show").click(); const texts = await walk(page, "group-dates"); expect(texts).toEqual([ "Click the dots next to “Created” to open its menu.", `Choose “${textOf("addTo", { zone: TEXTS.zones.rows })}”. This adds the field to your report.`, expect.stringMatching(/^Click “Created.*” to open its menu\.$/), `Choose “${TEXTS.groupTopic}”.`, "Choose a unit, such as months or years." ]); await expect(page.locator('[data-zone="rows"] [data-chip^="Created"]')).toHaveCount(1); }); /** Show me of group-dates with Do it for me up to its last step, the units of the date's Group level marked. */ async function toUnits(page) { await page.getByTestId("help-group-dates").click(); await page.getByTestId("help-show").click(); for (let n = 1; !(await page.getByTestId("help-done").isVisible()); n++) { expect(n, "the steps of group-dates").toBeLessThan(10); await page.getByTestId("help-do").click(); await expect(page.getByTestId("help-card-count")).toHaveText(new RegExp(`^\\D*${n + 1}\\D`)); } } // a short window, the units' level as tall as the window: the card beside the menu slides clear of the // chip the menu opened from (#1166); above a bottom sheet with too little room for card and arrow, the // card goes over the page's top edge without its arrow, never over the sheet's Back and title (#1167) for (const viewport of [{ width: 1280, height: 500 }, { width: 390, height: 640 }]) { test(`Show me's card at a date's units covers neither the origin nor the menu's head, ${viewport.width} x ${viewport.height} (#1166, #1167)`, async ({ page }) => { await page.setViewportSize(viewport); await open(page, "", "tickets"); await openHelp(page); await toUnits(page); await expect(page.locator('.pk-popover [data-testid="level-group"][data-pk-guided]')).toHaveCount(1); await animationsSettled(page); await expect.poll(() => judge(page)).toBe("ok"); }); } // a window too short for the whole Group level: Show me's last step marks the level for its units, // and the level stays at its top, so the line "Data before filters" stays whole under the head (#1163) // (German at 1280 x 900: the range line takes two lines there) for (const [size, viewport, lang, range] of [["1280 px, de", { width: 1280, height: 900 }, "de", "Daten vor den Filtern:"], ["a phone", { width: 390, height: 640 }, "en", "Data before filters:"]]) { test(`Show me's units of a date's Group level keep the level's range line in view, ${size} (#1163)`, async ({ page }) => { await page.setViewportSize(viewport); await open(page, `&lang=${lang}`, "tickets"); await openHelp(page); await toUnits(page); const level = page.locator('.pk-popover [data-testid="level-group"]'); await expect(page.locator(".pk-popover [data-pk-guided]")).toHaveCount(1); await expect.poll(() => judge(page)).toBe("ok"); await animationsSettled(page); await twoFrames(page); const box = await level.evaluate((el) => { const intro = el.querySelector(":scope > .pk-menu-hint").getBoundingClientRect(); const view = el.getBoundingClientRect(); return { scrolls: el.scrollHeight > el.clientHeight + 1, scrollTop: el.scrollTop, introTop: intro.top, viewTop: view.top }; }); // the level is taller than its room here, or the test shows nothing expect(box.scrolls, "the level fits; make the window shorter").toBe(true); expect(box.scrollTop).toBe(0); expect(box.introTop).toBeGreaterThanOrEqual(box.viewTop); await expect(level.locator(":scope > .pk-menu-hint")).toContainText(range); }); } test("a question about a type of field the data does not have is not listed, nor under All questions", async ({ page }) => { await open(page, "", "countries"); await page.getByTestId("help").click(); await page.getByTestId("help-all").click(); await expect(page.getByTestId("help-filter")).toBeVisible(); await expect(page.getByTestId("help-group-dates")).toHaveCount(0); await expect(page.getByTestId("help-date-range")).toHaveCount(0); }); /** The data set a question's Show me needs: a number in Rows, for its ranges. */ const DATA = { "number-ranges": "earthquakes" }; /** The questions whose control is greyed out in the start view of the weather data, and the sentence that says why instead. */ const GREYED = { "start-over": "atStart", undo: "nothingToUndo", subtotals: "noSubtotals", "expand-collapse": "noGroups" }; for (const [size, viewport] of [["1280 px", { width: 1280, height: 900 }], ["390 px", PHONE]]) { for (const lang of ["en", "de"]) { for (const theme of ["light", "dark"]) { for (const group of HELP_GROUPS) { test(`every question's Show me walks to its last step, each control marked, enabled and in view: ${group}, ${size}, ${lang}, ${theme}`, async ({ page }) => { test.slow(); await page.setViewportSize(viewport); for (const topic of HELP_TOPICS.filter((t) => t.group === group)) { await open(page, `&lang=${lang}&theme=${theme}`, DATA[topic.id]); // a phone report first draws its field list, then folds it behind the Fields button // once it has measured its width: pick only after that, as a reader's tap comes if (viewport === PHONE) await expect(page.getByTestId("field-list")).toBeHidden(); await openHelp(page); // a question not listed first: by the search if (!(await page.getByTestId(`help-${topic.id}`).count())) await page.getByTestId("help-search").fill(topic.question[lang]); // full screen only where the browser can do it if (topic.needs === "fullScreen" && !(await page.evaluate(() => document.fullscreenEnabled))) { await expect(page.getByTestId(`help-${topic.id}`)).toHaveCount(0); continue; } await page.getByTestId(`help-${topic.id}`).click(); await expect(page.getByTestId("help-title")).toHaveText(topic.question[lang]); // a control greyed out now: the answer says why instead of marking it; any other question has Show me if (Object.hasOwn(GREYED, topic.id) && !DATA[topic.id]) { await expect(page.getByTestId("help-none"), topic.id).toHaveText(sentence([GREYED[topic.id]], lang)); await expect(page.getByTestId("help-show"), topic.id).toHaveCount(0); continue; } await expect(page.getByTestId("help-none"), topic.id).toHaveCount(0); await page.getByTestId("help-show").click(); await walk(page, topic.id, theme); } }); } } } } test("sorting by the numbers: Show me's last step marks the one entry the step names, Largest … first (H1 of the review)", async ({ page }) => { await open(page); await page.getByTestId("help").click(); await page.getByTestId("help-sort-value").click(); const step = page.getByTestId("help-steps").getByRole("listitem").nth(1); await expect(step).toHaveText(/^Choose “Largest (.+) first” or “Smallest \1 first”\. With two or more values, they are under “Sort by value”\. A click on the header of a value's column in the table sorts too\.$/); const said = await step.textContent(); await page.getByTestId("help-show").click(); await page.getByTestId("help-do").click(); const marked = page.locator("[data-pk-guided]"); await expect(marked).toHaveCount(1); await expect(marked).toHaveAttribute("role", "menuitemradio"); await expect(marked).toHaveText(/^Largest .+ first$/); await expect(page.getByTestId("help-card-text")).toHaveText(said); await expect(page.getByTestId("help-done")).toBeVisible(); }); test("a control that draws no mark of its own: Show me marks it, describes it and takes the mark away again", async ({ page }) => { await open(page); await page.getByTestId("help").click(); await page.getByTestId("help-all").click(); await page.getByTestId("help-swap").click(); await page.getByTestId("help-show").click(); const swap = page.getByTestId("swap"); await expect(swap).toHaveAttribute("data-pk-guided", ""); // one step: the step the answer says and Done, no count (UX review: how it ends) await expect(page.getByTestId("help-card-text")).toHaveText("Click “Swap rows and columns”."); await expect(page.getByTestId("help-card-count")).toHaveCount(0); await expect(page.getByTestId("help-done")).toBeVisible(); await expect.poll(() => swap.evaluate((el) => getComputedStyle(el).boxShadow)).toContain(RING.light); await expect(swap).toHaveAttribute("aria-describedby", await page.getByTestId("help-card").getByRole("status").getAttribute("id")); await page.keyboard.press("Escape"); await expect(page.getByTestId("help-card")).toHaveCount(0); await expect(swap).not.toHaveAttribute("data-pk-guided"); await expect(swap).not.toHaveAttribute("aria-describedby"); }); test("a control greyed out now is not marked: the answer says why (Reset at the start view, Undo before a change)", async ({ page }) => { await open(page); await page.getByTestId("help").click(); await page.getByTestId("help-all").click(); await page.getByTestId("help-start-over").click(); await expect(page.getByTestId("help-none")).toHaveText(`The report shows its start view now, so “${TEXTS.reset}” has nothing to do.`); await expect(page.getByTestId("help-show")).toHaveCount(0); await page.getByTestId("help-back").click(); await page.getByTestId("help-undo").click(); await expect(page.getByTestId("help-none")).toHaveText(`There is nothing to undo yet: “${TEXTS.undo}” works once the report has changed.`); // once the report changed: both are marked, enabled (Escape goes back to All questions, the list, then closes the help) for (let i = 0; i < 3; i++) await page.keyboard.press("Escape"); await expect(page.getByTestId("help-panel")).toHaveCount(0); await page.getByTestId("swap").click(); await page.getByTestId("help").click(); await page.getByTestId("help-all").click(); await page.getByTestId("help-undo").click(); await page.getByTestId("help-show").click(); await expect(page.getByTestId("undo")).toHaveAttribute("data-pk-guided", ""); await expect(page.getByTestId("undo")).toBeEnabled(); }); test("a question about the chart while the table shows: the tab Chart is the first step, then its settings", async ({ page }) => { await open(page); await page.getByTestId("help").click(); await page.getByTestId("help-all").click(); await page.getByTestId("help-legend").click(); const first = "The chart is not shown now: switch to the tab “Chart” first."; await expect(page.getByTestId("help-steps").getByRole("listitem").first()).toHaveText(first); await page.getByTestId("help-show").click(); await expect(page.locator("[data-pk-guided]")).toHaveAttribute("data-testid", "show-chart"); await expect(page.getByTestId("help-card-text")).toHaveText(first); // the reader switches by the keyboard: the settings' button next, then Legend await page.keyboard.press("Enter"); await expect(page.getByTestId("show-chart")).toHaveAttribute("aria-selected", "true"); await expect(page.getByTestId("help-card-count")).toHaveText("Step 2 of 3"); await expect(page.locator("[data-pk-guided]")).toHaveAttribute("data-testid", "view-settings"); await page.getByTestId("help-do").click(); await expect(page.locator("[data-pk-guided]")).toHaveAttribute("data-testid", "topic-legend"); await page.keyboard.press("Escape"); // on the chart: no tab step; Reference lines whole in the menu's window, not under the fade at its edge (UX review of round 3) await page.getByTestId("help").click(); await page.getByTestId("help-all").click(); await page.getByTestId("help-reference-line").click(); await expect(page.getByTestId("help-steps").getByRole("listitem")).toHaveCount(2); await page.getByTestId("help-show").click(); await expect(page.getByTestId("help-card-count")).toHaveText("Step 1 of 2"); await page.getByTestId("help-do").click(); const marked = page.locator("[data-pk-guided]"); await expect(marked).toHaveAttribute("data-testid", "topic-lines"); await expect .poll(() => marked.evaluate((el) => { const r = el.getBoundingClientRect(); const body = el.closest(".pk-level-first, .pk-level-body") ?? el.closest(".pk-popover"); const b = body.getBoundingClientRect(); // the fade covers the last 3.5em of a list that goes on const fade = body.hasAttribute("data-pk-more") ? 3.5 * parseFloat(getComputedStyle(body).fontSize) : 0; return r.top >= b.top - 1 && r.bottom <= b.bottom - fade + 1; }) ) .toBe(true); }); test("save or share: Show me saves, then walks on to Copy link by itself; without a link, the answer says so", async ({ page }) => { await open(page); await page.getByTestId("help").click(); await page.getByTestId("help-share").click(); await expect(page.getByTestId("help-note")).toHaveCount(0); await page.getByTestId("help-show").click(); await page.getByTestId("help-do").click(); await expect(page.locator("[data-pk-guided]")).toHaveAttribute("data-testid", "save-as"); // the reader's own click (UX review: it ended the guide where Do it for me did not) await page.getByTestId("save-as").click(); await expect(page.getByTestId("help-card-text")).toHaveText("Give the view a name and save it."); await expect(page.getByTestId("help-do")).toHaveCount(0); // the reader names the view and saves it: Views opens again at Copy link await page.getByTestId("saved-view-name").fill("Walked"); await page.keyboard.press("Enter"); await expect(page.locator("[data-pk-guided]")).toHaveAttribute("data-testid", "copy-link"); await expect(page.getByTestId("help-card-count")).toHaveText("Step 4 of 4"); await expect(page.locator('[data-testid="views"]')).toHaveAttribute("data-pk-guide-origin", ""); await page.getByTestId("help-done").click(); await expect(page.getByTestId("help-card")).toHaveCount(0); // a page that offers no link: saving alone, and a sentence await page.goto("pages/element-views.html"); const host = page.locator("#views"); await expect(host.locator(".pk-root")).toBeVisible(); await toolbar(host, "more"); await page.keyboard.press("Escape"); await host.getByTestId("help").click(); await host.getByTestId("help-share").click(); await expect(host.getByTestId("help-note")).toHaveText(HELP_TEXTS.en.noLink); await host.getByTestId("help-show").click(); await expect(host.getByTestId("help-card-count")).toHaveText("Step 1 of 3"); }); test("on a phone: the answer says first what is folded away or in More; opening it is a step; the sheet's head names the origin, the card is above the sheet", async ({ page }) => { await page.setViewportSize(PHONE); await open(page); await expect(page.getByTestId("field-list")).toBeHidden(); await openHelp(page); await page.getByTestId("help-filter").click(); await expect(page.getByTestId("help-steps").getByRole("listitem").first()).toHaveText("Rows, Columns and Values are folded away now: open “Fields in the report” first."); await page.getByTestId("help-show").click(); await expect(page.locator("[data-pk-guided]")).toHaveAttribute("data-testid", "layout-summary"); await expect(page.getByTestId("help-card-count")).toHaveText("Step 1 of 4"); await page.getByTestId("help-do").click(); await expect(page.locator("[data-pk-guided]")).toHaveAttribute("data-testid", "chip-menu-City"); await page.getByTestId("help-do").click(); // the sheet covers the chip: the origin's ring goes around the field's name in the sheet's head, // with the zone after it; the card stands above the sheet, over none of its entries; the scrim // dims, no second dimming const head = page.locator('.pk-sheet [data-testid="menu-head"]'); await expect(head).toHaveText("City"); await expect(page.getByTestId("help-origin")).toHaveText(`· ${TEXTS.zones.rows}`); await expect.poll(() => onOrigin(page, '.pk-sheet [data-testid="menu-head"]')).toBe(true); await expect(page.getByTestId("help-dim")).toHaveCount(0); await expect.poll(() => judge(page)).toBe("ok"); // once the sheet has slid in await expect.poll(() => page.evaluate(() => document.querySelector('[data-testid="help-card"]').getBoundingClientRect().bottom <= document.querySelector(".pk-sheet").getBoundingClientRect().top)).toBe(true); await page.keyboard.press("Escape"); await expect(head).toHaveCount(0); await expect(page.getByTestId("help-origin")).toHaveCount(0); // Views in More: the answer says so first await openHelp(page); await page.getByTestId("help-share").click(); await expect(page.getByTestId("help-steps").getByRole("listitem").first()).toHaveText("“Views” is under “More” now: open “More”, then “Views…”."); }); test("where there is nothing to show, one sentence says so instead of Show me", async ({ page }) => { await open(page, "&start=empty"); await page.getByTestId("help").click(); await page.getByTestId("help-filter").click(); await expect(page.getByTestId("help-show")).toHaveCount(0); await expect(page.getByTestId("help-none")).toHaveText("There is no field in Rows or Columns yet. Add one first."); // the link to the docs is still there await expect(page.getByTestId("help-docs")).toBeVisible(); }); test("the field list folded to its rail: opening it is Show me's first step for adding a field", async ({ page }) => { await open(page); await page.getByTestId("collapse-fields").click(); await expect(page.getByTestId("field-rail")).toBeVisible(); await page.getByTestId("help").click(); await page.getByTestId("help-add-field").click(); await page.getByTestId("help-show").click(); await expect(page.locator("[data-pk-guided]")).toHaveAttribute("data-testid", "expand-fields"); await page.getByTestId("help-do").click(); await expect(page.getByTestId("field-rail")).toHaveCount(0); await page.getByTestId("help-do").click(); await expect(page.locator("[data-pk-guided]")).toHaveText(textOf("addTo", { zone: TEXTS.zones.rows })); }); test("in forced colours the marks are outlines in the system's highlight, the dimming gone (#1138)", async ({ page, browserName }) => { test.skip(browserName !== "chromium", "Playwright emulates forced colours in Chromium only"); await page.emulateMedia({ forcedColors: "active" }); await open(page); await page.getByTestId("help").click(); await page.getByTestId("help-filter").click(); await page.getByTestId("help-show").click(); const origin = page.locator('[data-chip="City"]'); await expect(origin).toHaveAttribute("data-pk-guide-origin", ""); await page.getByTestId("help-do").click(); const marked = page.locator("[data-pk-guided]"); await expect(marked).toHaveAttribute("data-testid", "topic-filter"); const style = (el) => { const s = getComputedStyle(el); return { style: s.outlineStyle, width: s.outlineWidth }; }; await expect.poll(() => marked.evaluate(style)).toEqual({ style: "solid", width: "3px" }); await expect.poll(() => page.getByTestId("help-origin").evaluate(style)).toEqual({ style: "solid", width: "3px" }); // the outline's colour is the system's highlight, as the browser maps it const highlight = await page.evaluate(() => { const probe = document.createElement("span"); probe.style.color = "Highlight"; document.body.append(probe); const colour = getComputedStyle(probe).color; probe.remove(); return colour; }); await expect.poll(() => marked.evaluate((el) => getComputedStyle(el).outlineColor)).toBe(highlight); await expect(page.getByTestId("help-dim")).toBeHidden(); }); test("More: the group Tips and help; the button's switch moves the help into More, with a note the first time, kept in the browser", async ({ page }) => { await page.goto("?data=sales"); await expect(page.getByTestId("pivot-table")).toBeVisible(); await twoFrames(page); // a tip dismissed, so Show dismissed tips again has one to bring back await page.getByTestId("tip-cells").getByRole("button", { name: "Dismiss tip" }).click(); await page.getByTestId("more").click(); await expect(page.getByTestId("topic-title-tipsHelp")).toHaveText(textOf("tipsAndHelp")); await expect(page.getByTestId("topic-tipsHelp").locator("[data-testid]")).toHaveText([textOf("helpButton"), textOf("helpInToolbar"), textOf("showTips"), textOf("showSettingInfo"), textOf("resetTips")]); await expect(page.getByTestId("more-help")).toHaveAttribute("aria-haspopup", "dialog"); // the keyboard shortcuts are the help's now, not More's await expect(page.getByTestId("more").locator("..").getByTestId("shortcuts")).toHaveCount(0); const sw = page.getByTestId("help-in-toolbar"); await expect(sw).toHaveAttribute("aria-checked", "true"); await sw.click(); // off: More closes, the button is gone, the note on More says where the help went await expect(page.locator(".pk-popover:not(.pk-help-moved)")).toHaveCount(0); await expect(page.getByTestId("help")).toHaveCount(0); await expect(page.getByTestId("help-moved")).toHaveText("Help is now under More."); // once: the next key ends it await page.keyboard.press("Shift"); await expect(page.getByTestId("help-moved")).toHaveCount(0); // More's "How do I…?" opens the help at More await page.getByTestId("more").click(); await page.getByTestId("more-help").click(); await expect(page.getByTestId("help-list")).toBeVisible(); await page.keyboard.press("Escape"); await expect(page.getByTestId("more")).toBeFocused(); // kept with the tips: a reload, and Show dismissed tips again, keep it out await page.reload(); await expect(page.getByTestId("pivot-table")).toBeVisible(); await twoFrames(page); await expect(page.getByTestId("help")).toHaveCount(0); expect(await page.evaluate(() => JSON.parse(localStorage.getItem("pivotkit:tips:playground") ?? "[]"))).toContain("-help"); await toolbar(page, "help"); await page.getByTestId("reset-tips").click(); await expect(page.getByTestId("tip-cells")).toBeVisible(); await expect(page.getByTestId("help-in-toolbar")).toHaveAttribute("aria-checked", "false"); await expect(page.getByTestId("help")).toHaveCount(0); // back on: the button is there again, and More closes as it does when the button goes (M6 of the review) await page.getByTestId("help-in-toolbar").click(); await expect(page.getByTestId("help")).toBeVisible(); await expect(page.locator(".pk-popover")).toHaveCount(0); await page.getByTestId("more").click(); await expect(page.getByTestId("help-in-toolbar")).toHaveAttribute("aria-checked", "true"); // the note only the first time: out again, More closes, and nothing more is said await page.getByTestId("help-in-toolbar").click(); await expect(page.getByTestId("help")).toHaveCount(0); await expect(page.locator(".pk-popover")).toHaveCount(0); await expect(page.getByTestId("help-moved")).toHaveCount(0); expect(await page.evaluate(() => JSON.parse(localStorage.getItem("pivotkit:tips:playground") ?? "[]"))).toContain("-help-noted"); }); test("More's How do I…? with the button in the toolbar opens the help at its button", async ({ page }) => { await open(page); await page.getByTestId("more").click(); await page.getByTestId("more-help").click(); await expect(page.getByTestId("help-list")).toBeVisible(); await expect(page.getByTestId("help")).toHaveAttribute("aria-expanded", "true"); }); test("help={false}: no button, no group; More → Help with the tips' switches and the shortcuts, as before", async ({ page }) => { await open(page, "&help=off"); await expect(page.getByTestId("help")).toHaveCount(0); await page.getByTestId("more").click(); await expect(page.getByTestId("more-help")).toHaveText(textOf("helpAndShortcuts")); await expect(page.getByTestId("more-help")).toHaveAttribute("aria-haspopup", "menu"); await expect(page.getByTestId("topic-tipsHelp")).toHaveCount(0); await page.getByTestId("more-help").click(); await expect(page.getByTestId("level-help").locator("[data-testid]")).toHaveText([textOf("showTips"), textOf("showSettingInfo"), textOf("resetTips"), textOf("shortcutsTitle")]); await expect(page.locator("[data-pk-guided]")).toHaveCount(0); }); test('help="more": no button and no switch; More opens the help', async ({ page }) => { await open(page, "&help=more"); await expect(page.getByTestId("help")).toHaveCount(0); await page.getByTestId("more").click(); await expect(page.getByTestId("help-in-toolbar")).toHaveCount(0); await page.getByTestId("more-help").click(); await page.getByTestId("help-export").click(); await page.getByTestId("help-show").click(); await expect(page.locator("[data-pk-guided]")).toHaveAttribute("data-testid", "export"); await page.getByTestId("help-do").click(); await expect(page.locator("[data-pk-guided]")).toHaveAttribute("data-testid", "export-xlsx"); }); test("the web component: a host's docs-url in every link, a function as the property, Show me in its shadow root", async ({ page }) => { await page.goto("pages/element-views.html"); const host = page.locator("#views"); await expect(host.locator(".pk-root")).toBeVisible(); await page.evaluate(() => document.getElementById("views").setAttribute("docs-url", "https://docs.example.com/pivot/")); await toolbar(host, "more"); await page.keyboard.press("Escape"); await host.getByTestId("help").click(); // the list comes with the help's load group: wait for its options, evaluateAll does not wait const options = host.getByTestId("help-list").locator('[role="option"]'); await expect(options.first()).toBeVisible(); const ids = await options.evaluateAll((els) => els.map((e) => e.dataset.testid.slice(5)).filter((id) => id !== "shortcuts")); expect(ids.length).toBeGreaterThan(8); for (const id of ids) { await host.getByTestId(`help-${id}`).click(); const topic = HELP_TOPICS.find((t) => t.id === id); const [page_, anchor] = topic.docs.split("#"); await expect(host.getByTestId("help-docs")).toHaveAttribute("href", `https://docs.example.com/pivot/${page_.replace(/\.md$/, "/")}#${anchor}`); await host.getByTestId("help-back").click(); } // a function of the topic, or none await page.evaluate(() => { document.getElementById("views").docsUrl = (topic) => (topic === "export" ? `https://wiki.example/${topic}` : null); }); await host.getByTestId("help-export").click(); await expect(host.getByTestId("help-docs")).toHaveAttribute("href", "https://wiki.example/export"); await host.getByTestId("help-back").click(); await host.getByTestId("help-filter").click(); await expect(host.getByTestId("help-docs")).toHaveCount(0); await host.getByTestId("help-back").click(); await host.getByTestId("help-export").click(); await host.getByTestId("help-show").click(); // in its shadow root: the steps, the origin, the dimming and the card's press on Do it for me await expect(host.locator("[data-pk-guided]")).toHaveAttribute("data-testid", "export"); await expect(host.getByTestId("help-dim")).toBeVisible(); await host.getByTestId("help-do").click(); await expect(host.locator("[data-pk-guided]")).toHaveAttribute("data-testid", "export-xlsx"); await expect(host.getByTestId("export")).toHaveAttribute("data-pk-guide-origin", ""); await expect(host.getByTestId("help-card-count")).toHaveText("Step 2 of 2"); await page.keyboard.press("Escape"); await expect(host.getByTestId("help-card")).toHaveCount(0); await expect(host.locator("[data-pk-guide-origin]")).toHaveCount(0); await expect(host.getByTestId("export")).toBeFocused(); }); test.describe("a page's own questions", () => { // the wrong entry below is said in the console test.use({ ignoreConsole: [/^pivotkit: helpTopics\.own\[1\] "bad id" is left out: id must be/] }); test("the web component's helpTopics: own first, a built-in left out, past HELP_LIST only by the search, own links", async ({ page }) => { const warnings = []; page.on("console", (m) => m.type() === "warning" && warnings.push(m.text())); await page.goto("pages/element-views.html"); const host = page.locator("#views"); await expect(host.locator(".pk-root")).toBeVisible(); const builtIn = HELP_TOPICS.map((t) => t.id).filter((id) => id !== "percent"); // more own questions than the list shows, one in a group of its own with its own link, one wrong await page.evaluate((ids) => { const own = Array.from({ length: 13 }, (_, i) => ({ id: `q${i}`, question: `Own question ${i}?`, answer: `Answer ${i}.` })); own[0] = { id: "vpn", question: { en: "How do I reach the VPN?", de: "Wie erreiche ich das VPN?" }, answer: "Open the portal.\nSign in with your account.\n", group: { en: "Network", de: "Netzwerk" }, docs: "https://intranet.example/vpn" }; own.splice(1, 0, { id: "bad id", question: "Left out?", answer: "Yes." }); document.getElementById("views").helpTopics = { builtIn: ids, own }; }, builtIn); await toolbar(host, "more"); await page.keyboard.press("Escape"); await host.getByTestId("help").click(); const list = host.getByTestId("help-list"); const options = list.getByRole("option"); await expect(options.first()).toHaveText("How do I reach the VPN?"); // the first HELP_LIST questions, then the shortcuts; All questions holds the others await expect(options).toHaveCount(HELP_LIST + 1); await expect(list.getByRole("group").first()).toHaveText(/^Network/); await expect(host.getByTestId("help-all")).toBeVisible(); await expect(host.getByTestId("help-q12")).toHaveCount(0); await expect(host.getByTestId("help-export")).toHaveCount(0); // the built-in question left out is not found either; the others are, by the search await host.getByTestId("help-search").fill("percentages"); await expect(host.getByTestId("help-nothing")).toBeVisible(); await host.getByTestId("help-search").fill("Own question 12"); await expect(options).toHaveText(["Own question 12?"]); // a search shows every hit, more than the list shows first: "I" starts a word of every built-in question (#1150) await host.getByTestId("help-search").fill("i"); await expect(host.getByTestId("help-export")).toBeVisible(); expect(await options.count()).toBeGreaterThan(HELP_LIST); await host.getByTestId("help-search").fill("xlsx"); await expect(options).toHaveText(["How do I export to Excel?"]); await host.getByTestId("help-search").fill(""); // All questions: the own ones in their own group first, then the built-in ones; the one left out is not there await host.getByTestId("help-all").click(); await expect(list.getByRole("group").first()).toHaveText(/^Network/); await expect(host.getByTestId("help-q12")).toBeVisible(); await expect(host.getByTestId("help-percent")).toHaveCount(0); await host.getByTestId("help-back").click(); // an own question: its answer as text, a paragraph per line (none for the last line break), its own link, no Show me await host.getByTestId("help-vpn").click(); await expect(host.getByTestId("help-answer").locator("p")).toHaveText(["Open the portal.", "Sign in with your account."]); await expect(host.getByTestId("help-show")).toHaveCount(0); await expect(host.getByTestId("help-docs")).toHaveAttribute("href", "https://intranet.example/vpn"); await host.getByTestId("help-back").click(); // without a link of its own: the page's docsUrl function, else none await host.getByTestId("help-q2").click(); await expect(host.getByTestId("help-docs")).toHaveCount(0); await host.getByTestId("help-back").click(); await page.evaluate(() => { document.getElementById("views").docsUrl = (topic) => `https://wiki.example/${topic}`; }); await host.getByTestId("help-q2").click(); await expect(host.getByTestId("help-docs")).toHaveAttribute("href", "https://wiki.example/q2"); expect(warnings.filter((w) => w.startsWith("pivotkit: helpTopics"))).toEqual([expect.stringMatching(/^pivotkit: helpTopics\.own\[1\] "bad id" is left out: id must be/)]); }); test("a long own answer and a long word in it wrap inside the help, at any width (#1135)", async ({ page }) => { for (const width of [1440, 1000, 390]) { await page.setViewportSize({ width, height: 900 }); await page.goto("pages/element-views.html"); const host = page.locator("#views"); await expect(host.locator(".pk-root")).toBeVisible(); await page.evaluate(() => { const answer = `${"A long answer of the page's own question. ".repeat(12)}\nThe address: https://intranet.example/a/long/path/that/has/no/place/to/break/at/all/in/it`; document.getElementById("views").helpTopics = { own: [{ id: "long", question: "How do I ask about something that needs a long answer with many words?", answer }] }; }); await host.getByTestId("help").click(); await host.getByTestId("help-long").click(); // each paragraph inside the help's box, none cut off at its right const cut = await host.getByTestId("help-answer").evaluate((answer) => { const box = answer.closest(".pk-popover").getBoundingClientRect(); return [...answer.querySelectorAll("p")].filter((p) => p.scrollWidth > p.clientWidth + 1 || p.getBoundingClientRect().right > box.right - 4).length; }); expect(cut, `${width} px`).toBe(0); } }); test("in a German report: an own text in English alone is marked English, a group named like a built-in one joins it (#1133, #1134)", async ({ page }) => { await page.goto("pages/element-views.html"); const host = page.locator("#views"); await expect(host.locator(".pk-root")).toBeVisible(); await page.evaluate(() => { const el = document.getElementById("views"); el.setAttribute("locale", "de-DE"); el.helpTopics = { builtIn: ["add-field"], own: [ { id: "english", question: { en: "Where is the VPN?" }, answer: { en: "Open the portal." }, group: "Fields" }, { id: "both", question: { en: "Which printer?", de: "Welcher Drucker?" }, answer: "Room 2." } ] }; }); await expect(host.getByTestId("help")).toHaveText("Wie geht …?"); await host.getByTestId("help").click(); const list = host.getByTestId("help-list"); // one group Felder: the own question first in it, then the built-in one await expect(list.getByRole("group")).toHaveText([/^Allgemein/, /^Felder/, /Tastenkürzel/]); await expect(list.getByRole("group").nth(1).getByRole("option")).toHaveText(["Where is the VPN?", "Wie füge ich ein Feld hinzu?"]); // English alone: its row, title and answer say so; German text and one text for both do not await expect(host.getByTestId("help-english").locator(".pk-option-text")).toHaveAttribute("lang", "en"); await expect(host.getByTestId("help-both").locator(".pk-option-text")).not.toHaveAttribute("lang"); await host.getByTestId("help-english").click(); await expect(host.getByTestId("help-title")).toHaveAttribute("lang", "en"); await expect(host.getByTestId("help-answer")).toHaveAttribute("lang", "en"); await host.getByTestId("help-back").click(); await host.getByTestId("help-both").click(); await expect(host.getByTestId("help-title")).not.toHaveAttribute("lang"); await expect(host.getByTestId("help-answer")).not.toHaveAttribute("lang"); }); }); test.describe("an own question's Show me on an element of the page", () => { /** The element page with own questions that point at the page (pages/element/help.html), settled. */ async function openOwn(page, id) { await page.goto("pages/element-help.html"); const host = page.locator("#report"); await expect(host.locator(".pk-root")).toBeVisible(); await toolbar(host, "more"); await page.keyboard.press("Escape"); await host.getByTestId("help").click(); await host.getByTestId(`help-${id}`).click(); return host; } /** The target's and the ring's boxes, whether the target is in the window, and the ring's shadow. */ const boxes = (page) => page.evaluate(() => { const target = document.getElementById("access-form").getBoundingClientRect(); const ring = document.getElementById("report").shadowRoot.querySelector('[data-testid="help-ring"]'); const r = ring?.getBoundingClientRect(); const near = (a, b) => Math.abs(a - b) <= 1; return { // scrolled to the nearest edge: its bottom on the window's, up to a sub-pixel (Firefox, WebKit) inView: target.top >= 0 && target.bottom <= innerHeight + 1, ringOnTarget: Boolean(r && near(r.top, target.top) && near(r.left, target.left) && near(r.width, target.width) && near(r.height, target.height)), shadow: ring ? getComputedStyle(ring).boxShadow : "" }; }); test("Show me scrolls the page's element into view, rings it and says the answer's first paragraph; Escape ends both, the element untouched", async ({ page }) => { const host = await openOwn(page, "request"); const form = page.locator("#access-form"); const before = await form.evaluate((el) => el.outerHTML); expect((await boxes(page)).inView).toBe(false); await expect(host.getByTestId("help-none")).toHaveCount(0); await host.getByTestId("help-show").click(); await expect(host.getByTestId("help-panel")).toHaveCount(0); await expect(host.getByTestId("help-card")).toHaveText("Use the form Request access below the report."); await expect(host.getByTestId("help-card")).toHaveAttribute("role", "status"); // in the window, the ring over it in the ring's colour, the card beside it await expect.poll(() => boxes(page)).toEqual({ inView: true, ringOnTarget: true, shadow: expect.stringContaining(RING.light) }); // the report marks nothing of its own, and writes nothing into the page's element await expect(host.locator("[data-pk-guided]")).toHaveCount(0); expect(await form.evaluate((el) => el.outerHTML)).toBe(before); await page.keyboard.press("Escape"); await expect(host.getByTestId("help-card")).toHaveCount(0); await expect(host.getByTestId("help-ring")).toHaveCount(0); // a press anywhere ends it too; a question's own card text, in German as well await host.getByTestId("help").click(); await host.getByTestId("help-request-text").click(); await host.getByTestId("help-show").click(); await expect(host.getByTestId("help-card")).toHaveText("The form is here."); await expect(host.getByTestId("help-ring")).toBeVisible(); await page.mouse.click(5, 5); await expect(host.getByTestId("help-card")).toHaveCount(0); await expect(host.getByTestId("help-ring")).toHaveCount(0); await page.evaluate(() => document.getElementById("report").setAttribute("lang", "de-DE")); await host.getByTestId("help").click(); await host.getByTestId("help-request-text").click(); await host.getByTestId("help-show").click(); await expect(host.getByTestId("help-card")).toHaveText("Hier ist das Formular."); }); test("where the page has no such element, hides it or takes it away, one sentence says so instead of Show me", async ({ page }) => { const host = await openOwn(page, "missing"); await expect(host.getByTestId("help-show")).toHaveCount(0); await expect(host.getByTestId("help-none")).toHaveText(HELP_TEXTS.en.noTarget); await host.getByTestId("help-back").click(); await host.getByTestId("help-folded").click(); await expect(host.getByTestId("help-none")).toHaveText(HELP_TEXTS.en.noTarget); // without show: no Show me and no sentence await host.getByTestId("help-back").click(); await host.getByTestId("help-plain").click(); await expect(host.getByTestId("help-answer")).toHaveText("Your team lead."); await expect(host.getByTestId("help-show")).toHaveCount(0); await expect(host.getByTestId("help-none")).toHaveCount(0); // taken away while the answer shows: Show me says so instead of pointing at nothing await host.getByTestId("help-back").click(); await host.getByTestId("help-request").click(); await page.evaluate(() => document.getElementById("access-form").remove()); await host.getByTestId("help-show").click(); await expect(host.getByTestId("help-none")).toHaveText(HELP_TEXTS.en.noTarget); await expect(host.getByTestId("help-card")).toHaveCount(0); }); test("an element that takes the focus gets it; Enter there ends ring and card", async ({ page }) => { const host = await openOwn(page, "button"); await host.getByTestId("help-show").click(); await expect(host.getByTestId("help-card")).toHaveText("The Request button."); await expect(page.locator("#request")).toBeFocused(); await page.keyboard.press("Enter"); await expect(host.getByTestId("help-card")).toHaveCount(0); await expect(host.getByTestId("help-ring")).toHaveCount(0); }); for (const [how, change] of [["leaving the page", (el) => el.remove()], ["hidden", (el) => el.setAttribute("hidden", "")]]) { test(`the element ${how} ends ring and card`, async ({ page }) => { const host = await openOwn(page, "request"); await host.getByTestId("help-show").click(); await expect(host.getByTestId("help-ring")).toBeVisible(); await page.locator("#access-form").evaluate(change); await expect(host.getByTestId("help-card")).toHaveCount(0); await expect(host.getByTestId("help-ring")).toHaveCount(0); }); } test("an element inside a shadow root of the page: found from a pivot-report in that root, outwards from its own", async ({ page }) => { await page.goto("pages/element-help.html"); const inner = page.locator("#inner"); await expect(inner.locator(".pk-root")).toBeVisible(); await toolbar(inner, "more"); await page.keyboard.press("Escape"); await inner.getByTestId("help").click(); await inner.getByTestId("help-inner").click(); await expect(inner.getByTestId("help-none")).toHaveCount(0); await inner.getByTestId("help-show").click(); await expect(inner.getByTestId("help-card")).toHaveText("Next to the report."); const onNote = () => page.evaluate(() => { const frame = document.getElementById("frame").shadowRoot; const note = frame.getElementById("inner-target").getBoundingClientRect(); const ring = frame.getElementById("inner").shadowRoot.querySelector('[data-testid="help-ring"]')?.getBoundingClientRect(); return Boolean(ring && Math.abs(ring.top - note.top) <= 1 && Math.abs(ring.width - note.width) <= 1); }); await expect.poll(onNote).toBe(true); }); });