gui tests: codex-credits measures the credits row it finds, after the panel's own read has drawn it (#1622)
codex-credits.test.cjs was red in Chromium now and then: "the say fits the panel's card" got a switch 0 wide. The cause, found by holding the tray panel's own allowances read (usage/quotas?asked=1) 0-300ms: picking the Allowances tab reads the accounts again, and its answer redraws the cards (renderPanelQuota replaces them) 100-400ms after the click. fits() found the row through a locator and measured it in a second step; a redraw between the two left it measuring a row out of the page, all zeros. Answered 0, 20 or 40ms late the old test failed every time; 60ms and later it passed. Nothing a reader sees: the redraw is synchronous and draws the same row. fits() now finds and measures the row in one page.evaluate, and the panel step waits for the tab's read to finish (quotasLoading) before measuring. Run: with the read held 0, 20, 40, 60, 80, 100, 150, 200, 300ms the test passes every time (en and de, Chromium); 20/20 green in Chromium and 20/20 in WebKit.
This commit is contained in:
@@ -151,12 +151,16 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
assert.deepEqual(await spot(), was, "the click moved the page");
|
||||
};
|
||||
// the row fits its card: the switch whole and inside it, the words
|
||||
// wrapping rather than cut off
|
||||
const fits = (page, row, card) => page.locator(row).evaluate((r, card) => {
|
||||
// wrapping rather than cut off. Found and measured in one go: a read
|
||||
// of the accounts landing between a locator finding the row and
|
||||
// measuring it draws the cards anew, and the row found is then out
|
||||
// of the page, all zeros (#1622)
|
||||
const fits = (page, row, card) => page.evaluate(([row, card]) => {
|
||||
const r = document.querySelector(row);
|
||||
const c = r.closest(card).getBoundingClientRect(), b = r.getBoundingClientRect(), s = r.querySelector(".use-credits").getBoundingClientRect();
|
||||
const say = r.querySelector(".ar-say");
|
||||
return b.right <= c.right + 0.5 && s.right <= c.right + 0.5 && s.width >= 27 && s.height >= 15 && say.scrollWidth <= say.clientWidth + 1;
|
||||
}, card);
|
||||
}, [row, card]);
|
||||
|
||||
for (const width of [900, 440]) {
|
||||
const posts = [];
|
||||
@@ -193,6 +197,9 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
const psel = '.pq-credits[data-user="Me@example.com"]';
|
||||
await panel.locator('#ptabs [data-ptab="usage"]').click();
|
||||
await panel.locator(psel).waitFor();
|
||||
// the tab, opened, reads the accounts again and draws its cards anew
|
||||
// when they come: what follows is about the cards drawn from that
|
||||
await panel.waitForFunction(() => !quotasLoading);
|
||||
assert.equal(await panel.locator(".pq-credits").count(), 1, "only the Codex account in sight has it");
|
||||
assert.equal(await text(panel.locator(psel + " .ar-say")), w.on);
|
||||
assert(await fits(panel, psel, ".pq-card"), `the say fits the panel's card at ${width}px`);
|
||||
|
||||
Reference in New Issue
Block a user