Public: anyone can read this; the crew can change it.
Full suite red: test/palette-tell.test.ts #12673
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/12652-full-suite-red-test-palette-tell-test-ts → main 1 commit fork
1 file
changed +8
−6
test/palette-tell.test.ts +8 −6
| @@ -29,23 +29,25 @@ if (chromium === undefined) | ||
| 29 | 29 | /** Open the palette, type `text`, and report the rows; with `pick`, choose the tell row. */ |
| 30 | 30 | const drive = (text: string, pick: boolean): string => `(async () => { try { |
| 31 | 31 | const wait = (ms) => new Promise((r) => setTimeout(r, ms)); |
| 32 | // Poll for the thing itself instead of sleeping a fixed time: the common case is a few ms. | |
| 33 | const until = async (fn, ms) => { for (let t = 0; t < ms; t += 5) { const v = fn(); if (v) return v; await wait(5); } return fn(); }; | |
| 32 | 34 | const opener = document.querySelector("[data-palette]"); |
| 33 | 35 | if (!opener) return JSON.stringify({ error: "no palette button on " + location.href + ": " + document.title }); |
| 34 | 36 | opener.click(); |
| 35 | await wait(100); | |
| 36 | const dlg = document.getElementById("palette"); | |
| 37 | const dlg = await until(() => { const d = document.getElementById("palette"); return d && d.open ? d : null; }, 1000) || document.getElementById("palette"); | |
| 37 | 38 | const input = dlg.querySelector(".palette-input"); |
| 38 | 39 | input.value = ${JSON.stringify(text)}; |
| 39 | 40 | input.dispatchEvent(new Event("input")); |
| 40 | await wait(100); | |
| 41 | const rows = [...dlg.querySelectorAll(".palette-item")]; | |
| 41 | const rowsNow = () => [...dlg.querySelectorAll(".palette-item")]; | |
| 42 | // A tell row, when there is to be one, is drawn after the first rows: wait for it, briefly. | |
| 43 | await until(() => { const r = rowsNow(); const l = r[r.length - 1]; return l && l.hasAttribute("data-tell"); }, ${pick} || ${JSON.stringify(text)}.length >= 3 ? 300 : 40); | |
| 44 | const rows = rowsNow(); | |
| 42 | 45 | const last = rows[rows.length - 1]; |
| 43 | 46 | const tellRow = last && last.hasAttribute("data-tell") ? last.textContent : null; |
| 44 | 47 | let toast = null; |
| 45 | 48 | if (${pick} && last) { |
| 46 | 49 | last.click(); |
| 47 | await wait(800); | |
| 48 | const t = document.querySelector(".toast[data-palette-tell]"); | |
| 50 | const t = await until(() => document.querySelector(".toast[data-palette-tell]"), 3000); | |
| 49 | 51 | toast = t ? { text: t.querySelector(".toast-body").textContent, link: t.querySelector("a")?.getAttribute("href") ?? null } : null; |
| 50 | 52 | } |
| 51 | 53 | return JSON.stringify({ tellRow, rows: rows.length, open: dlg.open, toast }); |
new above
offline