With Hide accounts (账号打码) on, the name a user gave an account (#1515) was blurred like the account, so faketrader's several Antigravity accounts couldn't be told apart; and an Antigravity account whose value is "Google" blurred "Google" of its plan "Google AI Pro" on Usage and on the Providers row. The name the user gave an account is shown text, not an identity. The account is. - provider: a card's Alias says whether it is the user's own name (SubscriptionQuota.Named, set by withAccountNames from AccountNameOf), since Alias is also a plugin's name for an account (PluginUserOf, a masked phone, #4416) or a seat's key plan, and the Usage page and tray panel may have no /api/providers to tell them apart. labelProvider is AccountLabelOf's "plugin:" lookup, shared. - app.js names(): the user's own names (accountNames) and named aliases are no longer accounts to hide; accountUsers, an unnamed alias and a seat still are (noteAccounts keeps an alias without named). - app.js mask(): labels are scoped by element, never by value (LESSONS: scope an exemption by where the value sits). In .own-name, .plan, .acct-plan (the Providers row's plan pill, new class), .model-value and .subscription-head > b only an address is hidden; a plan's and a model's tooltip too (TIPS). The own name's tooltip ("name · account") is masked in full. - .own-name is set only where the text is the user's own: the editor's rename span when it has one (else it shows the raw account and stays hidden), Usage's quota-alias and the panel's pq-user when q.named. From skygunner's patch (95c0511 on19253f67), changed: - Its .acct-who .rename exemption showed a raw non-email account (the rename span shows the account when it has no name of the user's). Now only an own-name span is exempt. - Its [title]:not(LABELS) skipped those elements' tooltips altogether, so the address in "alias · user" (quota-alias, rename) went unmasked. Tooltips are masked; only a plan's or model's hides just an address. - Dropping every alias from names() would have shown a plugin's name for an account (#4416 came after the patch's base). Named tells the user's own apart. - The n.data.length < 2 skip the patch removed is kept. - Its test is rewritten on the new fixtures: an unnamed plugin alias, an address in a plan, the editor with and without an own name, the panel, a model value, tooltips. account-alias.test.cjs and account-eye.test.cjs said Hide accounts hides the user's own name; they now say it stays in sight, the accounts still hidden. account-alias brings the window's page to the front before clicking #usageMask, and the panel's before waiting on it: behind the panel's page it gets no frames and the click waited for one, red 5 times in 2 runs atfb3942ee6(#2984's account-alias half), 0 in 100 after. Not changed: the tray panel card's tooltip is one string of account and plan, so a plan word that equals an account's value is still hidden there (#4677). OpenCode Zen's "Signed in as <account>" in the issue's screenshot is the raw account, hidden as before. Core scripts: app.js's own comments in the masking module are cut, so the core is 742 bytes under its budget at the pushed head (no raise). What was run: - At this on4c815ac2a, on mote (then rebased onto39bade71d, whose 8 commits change only i18n.js and plugins/gateway/settings.js; the budget measured again, 742 under): gofmt -l; go vet of provider, gui, usageapi; go test -tags nogui ./internal/provider ./internal/usageapi ok; TestCoreScriptBudget ok; the 19 masking GUI files (account-*, mask-*, masking-records, privacy-*, provider-mask, provider-unmasked, routing-masking, window-mask, click-scroll, i18n-keys), both engines: 539/540. The red was account-alias's panel wait behind the window's page, fixed by the panel bringToFront above. account-alias + account-mask-alias-plan after it: 4 runs, 159/160 (one red in "renamed in place", whose body this change doesn't touch, #4749). account-alias 6 more runs: 120/120 here, 117/120 on origin/main90c02326b(#2984). - account-mask-alias-plan: 20/20 on the fix (Chromium, WebKit; en, zh, zh-TW, ja, de; 1100 and 420), 20/20 red atfb3942ee6(the alias is masked); red with the plan selectors taken out of LABELS by hand. account_plugin_user_test red with Named always false by hand. - At 4eeba1ca6 (this on90c02326b): go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./..., go build for darwin, linux (nogui) and windows: ok. go test -tags nogui ./... on the Linux box: every package ok except internal/agent (8 install tests red the same on origin/main there, #4033, #3548) and internal/gui (TestSettingsSaveKeepsWhatItDoesNotSend, red on main, #4514; TestColdTurnsTaken on mote once, #4510). The whole GUI suite on the Linux box, 6 wide: 16857 pass, 491 fail in 100 files, none of them the masking files but account-every-reset; being run against origin/main to sort. Co-authored-by: skygunner <84759+skygunner@users.noreply.github.com> Co-authored-by: vincent <vincent@users.noreply.github.com> Co-authored-by: Fake Trader <9635792+faketrader@users.noreply.github.com>
322 lines
21 KiB
JavaScript
322 lines
21 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// One account shown while Hide accounts hides the rest (yogurt36 on
|
|
// Discord, for a screen share): with Hide accounts on, an account's name
|
|
// on the provider editor's row and on its Usage card has a quiet eye, in
|
|
// sight on hover or keyboard focus. A click shows that account, by its
|
|
// address wherever the window draws it, tooltips too; the others stay
|
|
// hidden. The name the user gave one is in sight throughout (#3656). The tray panel's Usage cards have
|
|
// the same eye. Each page's shown accounts are its own: one shown in the
|
|
// window stays hidden in the panel and the other way round. Closing the
|
|
// window (hideMain's closed) or putting the panel away hides them again. With Hide accounts off there is no eye. A click moves nothing;
|
|
// no native select, no border stripe; it fits at 360px. In every language.
|
|
const assert = require("node:assert/strict");
|
|
const fs = require("node:fs/promises");
|
|
const path = require("node:path");
|
|
const { test } = require("node:test");
|
|
const { chromium, webkit } = require("playwright");
|
|
|
|
const assets = path.resolve(__dirname, "../assets");
|
|
const SEAT = "某某·GLM高级版", TEAM = "3141592636@qq.com", ME = "me@example.com";
|
|
const inHours = (h) => new Date(Date.now() + h * 3600e3 + 60e3).toISOString();
|
|
const provider = () => ({
|
|
id: "zcode", name: "ZCode", icon: "zcode", chat: "", responses: "", anthropic: "", catalog: "",
|
|
models: [{ id: "glm-5", name: "", on: true }],
|
|
agents: [], fallback: [], headers: {}, keyList: [], proxy: "",
|
|
account: {
|
|
agent: "zcode", agentName: "ZCode", user: TEAM, plan: "Pro",
|
|
logins: [
|
|
{ user: TEAM, plan: "Pro", active: true, on: true },
|
|
{ user: ME, plan: "Lite", on: true },
|
|
],
|
|
},
|
|
accountNames: { [ME]: "Personal" },
|
|
accountSeats: { [TEAM]: SEAT },
|
|
});
|
|
const quotas = () => [
|
|
{ provider: "zcode", name: "ZCode", icon: "zcode", plan: "Pro", user: TEAM, alias: SEAT, seat: SEAT,
|
|
windows: [{ name: "5 hours", used: 20, resetsAt: inHours(3) }] },
|
|
{ provider: "zcode", name: "ZCode", icon: "zcode", plan: "Lite", user: ME, alias: "Personal", named: true,
|
|
windows: [{ name: "5 hours", used: 60, resetsAt: inHours(2) }] },
|
|
];
|
|
|
|
function serve(lang, panel = false) {
|
|
const settings = { theme: "light", lang, tray: "panel", quotaLeft: false, currency: "usd" };
|
|
const providers = { providers: [provider()], presets: [], excluded: [], gateway: { running: true, window: true } };
|
|
return async (route) => {
|
|
const url = new URL(route.request().url());
|
|
const json = (data) => route.fulfill({ json: data });
|
|
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:${!panel}};` });
|
|
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
|
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings });
|
|
if (url.pathname === "/api/settings") return json(settings);
|
|
if (url.pathname === "/api/providers") return json(providers);
|
|
if (url.pathname === "/api/usage/quotas") return json(quotas());
|
|
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
|
|
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
|
if (url.pathname === "/api/login/usage") return json({});
|
|
if (url.pathname.startsWith("/api/")) return json({});
|
|
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
|
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
|
|
try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
|
|
};
|
|
}
|
|
|
|
const KEYS = ["Show this account", "Hide this account"];
|
|
const LANGS = ["en", "zh", "zh-TW", "ja", "de"];
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
for (const lang of LANGS) {
|
|
const launch = async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
return browser;
|
|
};
|
|
const tr = (page, k) => page.evaluate((k) => t(k), k);
|
|
const scrolled = (page) => page.evaluate(() => [window.scrollY, ...[...document.querySelectorAll("*")].filter((e) => e.scrollTop > 0).map((e) => `${e.className}:${e.scrollTop}`)].join(" "));
|
|
const wide = (page) => page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth);
|
|
const stripes = (page, sel) => page.evaluate((sel) => [...document.querySelectorAll(sel)].map((e) => getComputedStyle(e).borderLeftWidth).filter((b) => parseFloat(b) > 1), sel);
|
|
const opacity = (loc) => loc.evaluate((e) => getComputedStyle(e).display === "none" ? "none" : getComputedStyle(e).opacity);
|
|
// what of an element is in sight: its text and every tooltip in it
|
|
const seen = (loc) => loc.evaluate((e) => [e.textContent, ...[e, ...e.querySelectorAll("[title]")].map((x) => x.title || "")].join(" | "));
|
|
// a sentence and a tooltip elsewhere in the window naming both accounts
|
|
const sample = (page) => page.evaluate(([me, team]) => {
|
|
const d = document.createElement("div");
|
|
d.id = "sample";
|
|
d.textContent = `Personal · ${me} · ${team}`;
|
|
d.title = `${me} · ${team}`;
|
|
document.querySelector("main, body").append(d);
|
|
}, [ME, TEAM]);
|
|
|
|
test(`${engine} ${lang}: the provider editor's eye shows one account while the others stay hidden`, async (t) => {
|
|
const browser = await launch(t);
|
|
for (const width of [900, 360]) {
|
|
const context = await browser.newContext({ viewport: { width, height: 760 }, reducedMotion: "reduce" });
|
|
const errors = [];
|
|
const open = async (url) => {
|
|
const page = await context.newPage();
|
|
page.setDefaultTimeout(5000);
|
|
page.setDefaultNavigationTimeout(60000);
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.route("**/*", serve(lang, url.includes("mode=panel")));
|
|
await page.goto(url);
|
|
return page;
|
|
};
|
|
const page = await open("http://magpie.test/?view=providers");
|
|
await page.locator(".row.provider", { hasText: "ZCode" }).first().click();
|
|
const row = (id) => page.locator(`.editor .accts .acc[data-account-id="${id}"]`);
|
|
await row(TEAM).locator(".acct-who").waitFor();
|
|
// the pointer off the rows: the click that opened the editor left it
|
|
// on ME's name at 360px
|
|
await page.mouse.move(0, 0);
|
|
const eye = (id) => row(id).locator(".acct-eye");
|
|
|
|
// Hide accounts off: no eye at all
|
|
assert.equal(await eye(ME).count(), 1);
|
|
assert.equal(await opacity(eye(ME)), "none", "no eye while Hide accounts is off");
|
|
|
|
await page.evaluate(() => hideAccounts.set(true, true));
|
|
await sample(page);
|
|
await page.waitForFunction(() => document.querySelectorAll("#sample .pii").length === 2);
|
|
await page.waitForFunction((me) => document.querySelector(`.editor .acc[data-account-id="${me}"] .acct-user .pii`), ME);
|
|
for (const id of [ME, TEAM]) assert.ok(!(await seen(row(id))).includes(id), `${id} is hidden first`);
|
|
|
|
// quiet until the name is pointed at; named for what it does
|
|
assert.equal(await opacity(eye(ME)), "0");
|
|
await row(ME).locator(".acct-who").hover();
|
|
assert.equal(await opacity(eye(ME)), "1", "the eye shows on hover");
|
|
assert.equal(await eye(ME).getAttribute("aria-label"), await tr(page, KEYS[0]));
|
|
assert.equal(await eye(ME).getAttribute("aria-pressed"), "false");
|
|
assert.equal(await eye(ME).getAttribute("title"), await tr(page, KEYS[0]));
|
|
|
|
// a click shows that one, by its address and its name, everywhere
|
|
// the window has it, its tooltips too; nothing moves
|
|
await eye(ME).scrollIntoViewIfNeeded();
|
|
await page.waitForTimeout(150);
|
|
const top = await row(ME).evaluate((e) => Math.round(e.getBoundingClientRect().top)), sc = await scrolled(page);
|
|
await eye(ME).click();
|
|
await page.waitForFunction((me) => !document.querySelector(`.editor .acc[data-account-id="${me}"] .pii`), ME);
|
|
assert.equal(await row(ME).evaluate((e) => Math.round(e.getBoundingClientRect().top)), top, "the row moved");
|
|
assert.equal(await scrolled(page), sc, "a click scrolled");
|
|
assert.equal(await row(ME).locator(".n.rename").textContent(), "Personal");
|
|
assert.equal(await row(ME).locator(".acct-user").textContent(), ME);
|
|
assert.ok((await row(ME).locator(".n.rename").getAttribute("title")).includes(ME), "its tooltip names it");
|
|
assert.equal(await eye(ME).getAttribute("aria-pressed"), "true");
|
|
assert.equal(await eye(ME).getAttribute("title"), await tr(page, KEYS[1]));
|
|
assert.equal(await opacity(eye(ME)), "1", "a shown account's eye stays in sight");
|
|
await page.waitForFunction(() => document.querySelectorAll("#sample .pii").length === 1);
|
|
assert.equal(await page.locator("#sample .pii").getAttribute("data-raw"), TEAM);
|
|
assert.ok((await page.locator("#sample").textContent()).startsWith(`Personal · ${ME} · `));
|
|
assert.ok(!(await page.locator("#sample").textContent()).includes(TEAM));
|
|
assert.equal(await page.locator("#sample").getAttribute("title"), `${ME} · ${"•".repeat(10)}@••.•••`);
|
|
// the other stays hidden, in its row and its tooltips
|
|
assert.ok(await row(TEAM).locator(".pii").count() > 0);
|
|
assert.ok(!(await seen(row(TEAM))).includes(TEAM), "the other account stays hidden");
|
|
assert.equal(await eye(TEAM).getAttribute("aria-pressed"), "false");
|
|
|
|
// from the keyboard: Tab from the name reaches its eye, which shows
|
|
await page.mouse.move(0, 0);
|
|
await row(TEAM).locator(".n.rename").focus();
|
|
// WebKit on macOS tabs to a button only with Option, as Safari does
|
|
await page.keyboard.press(engine === "webkit" && process.platform === "darwin" ? "Alt+Tab" : "Tab");
|
|
assert.ok(await eye(TEAM).evaluate((e) => e === document.activeElement), "Tab reaches the eye");
|
|
assert.equal(await opacity(eye(TEAM)), "1", "the eye shows on focus");
|
|
await page.keyboard.press("Enter");
|
|
await page.waitForFunction((id) => !document.querySelector(`.editor .acc[data-account-id="${id}"] .pii`), TEAM);
|
|
assert.ok((await seen(row(TEAM))).includes(TEAM));
|
|
await page.keyboard.press(" ");
|
|
await page.waitForFunction((id) => document.querySelector(`.editor .acc[data-account-id="${id}"] .pii`), TEAM);
|
|
assert.ok(!(await seen(row(TEAM))).includes(TEAM), "pressed again, hidden again");
|
|
|
|
// the tray panel follows the window's setting, not its eye: one
|
|
// shown in the window stays hidden in a screenshot of the panel
|
|
assert.equal(await eye(ME).getAttribute("aria-pressed"), "true", "still shown in the window");
|
|
const panel = await open("http://magpie.test/?mode=panel");
|
|
await panel.evaluate(() => setPanelTab("usage"));
|
|
await panel.locator("#panelQuota .pq-user").first().waitFor();
|
|
await panel.waitForFunction(() => document.querySelector("#panelQuota .pq-user .pii"));
|
|
const pq = await panel.evaluate(() => [...document.querySelectorAll("#panelQuota .pq-card")].map((c) => c.textContent + c.title).join(" "));
|
|
assert.ok(!pq.includes(ME), "the panel still hides it: " + pq);
|
|
await panel.close();
|
|
|
|
// the window closed: every account hidden again
|
|
await page.evaluate(() => hideAccounts.closed());
|
|
await page.waitForFunction(() => document.querySelectorAll("#sample .pii").length === 2);
|
|
for (const id of [ME, TEAM]) assert.ok(!(await seen(row(id))).includes(id), `${id} is hidden after the window closed`);
|
|
assert.equal(await eye(ME).getAttribute("aria-pressed"), "false");
|
|
|
|
// and Hide accounts off: the eyes go
|
|
await page.evaluate(() => hideAccounts.set(false, true));
|
|
assert.equal(await opacity(eye(ME)), "none");
|
|
|
|
assert.equal(await page.locator("select").count(), 0, "no native select");
|
|
assert.deepEqual(await stripes(page, ".accts .acct-who, .accts .acct-who *"), [], "no border stripes");
|
|
assert.equal(await wide(page), 0, `no sideways scroll at ${width}px`);
|
|
const missing = await page.evaluate(([keys, lang]) => lang === "en" ? [] : keys.filter((k) => !I18N[lang]?.[k]), [KEYS, lang]);
|
|
assert.deepEqual(missing, [], `every string has its ${lang}`);
|
|
assert.deepEqual(errors, []);
|
|
await context.close();
|
|
}
|
|
});
|
|
|
|
test(`${engine} ${lang}: the tray panel's eye shows one account there, until the panel is put away`, async (t) => {
|
|
const browser = await launch(t);
|
|
for (const width of [360, 440]) {
|
|
const context = await browser.newContext({ viewport: { width, height: 640 }, reducedMotion: "reduce" });
|
|
const errors = [];
|
|
const open = async (url) => {
|
|
const page = await context.newPage();
|
|
page.setDefaultTimeout(5000);
|
|
page.setDefaultNavigationTimeout(60000);
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.route("**/*", serve(lang, url.includes("mode=panel")));
|
|
await page.goto(url);
|
|
return page;
|
|
};
|
|
const panel = await open("http://magpie.test/?mode=panel");
|
|
await panel.evaluate(() => setPanelTab("usage"));
|
|
await panel.locator("#panelQuota .pq-user").first().waitFor();
|
|
// the group's second account is under its "more"
|
|
await panel.locator("#panelQuota .pq-group .pq-more:not(.pq-arrange)").first().click();
|
|
await panel.waitForFunction(() => document.querySelectorAll("#panelQuota .pq-card").length === 2);
|
|
const card = (u) => panel.locator(`#panelQuota .pq-card:has(.pq-user:text-is("${u}")), #panelQuota .pq-card:has(.pq-user .pii[data-raw="${u}"])`).first();
|
|
const eye = (u) => card(u).locator(".acct-eye");
|
|
assert.equal(await eye("Personal").count(), 1, "the panel's card has an eye");
|
|
assert.equal(await opacity(eye("Personal")), "none", "no eye while Hide accounts is off");
|
|
|
|
await panel.evaluate(() => hideAccounts.set(true));
|
|
await panel.waitForFunction(() => document.querySelectorAll("#panelQuota .pq-user .pii").length === 1);
|
|
await panel.waitForFunction((me) => [...document.querySelectorAll("#panelQuota .pq-card")].some((c) => c.querySelector(".pq-user").textContent === "Personal" && !c.title.includes(me)), ME);
|
|
await panel.mouse.move(0, 0);
|
|
assert.equal(await opacity(eye("Personal")), "0");
|
|
await card("Personal").hover();
|
|
assert.equal(await opacity(eye("Personal")), "1", "the eye shows on hover over its card");
|
|
assert.equal(await eye("Personal").getAttribute("aria-label"), await tr(panel, KEYS[0]));
|
|
assert.equal(await eye("Personal").getAttribute("title"), await tr(panel, KEYS[0]));
|
|
|
|
// a click shows that one, its card's tooltip too; the other stays hidden; nothing moves
|
|
const sc = await scrolled(panel);
|
|
await eye("Personal").click();
|
|
await panel.waitForFunction((me) => [...document.querySelectorAll("#panelQuota .pq-card")].some((c) => c.querySelector(".pq-user").textContent === "Personal" && c.title.includes(me)), ME);
|
|
assert.equal(await panel.locator("#panelQuota .pq-user .pii").count(), 1);
|
|
assert.equal(await scrolled(panel), sc, "a click scrolled");
|
|
assert.equal(await card("Personal").locator(".pq-user").textContent(), "Personal");
|
|
assert.ok((await card("Personal").getAttribute("title")).includes(ME), "its tooltip names it");
|
|
assert.equal(await eye("Personal").getAttribute("aria-pressed"), "true");
|
|
assert.equal(await eye("Personal").getAttribute("title"), await tr(panel, KEYS[1]));
|
|
assert.equal(await opacity(eye("Personal")), "1", "a shown account's eye stays in sight");
|
|
assert.ok(!(await seen(card(SEAT))).includes(TEAM) && !(await seen(card(SEAT))).includes(SEAT), "the other card stays hidden");
|
|
assert.equal(await eye(SEAT).getAttribute("aria-pressed"), "false");
|
|
// redrawn (a refresh, a tab), it stays shown
|
|
await panel.evaluate(() => renderPanelQuota());
|
|
assert.equal(await panel.locator("#panelQuota .pq-user .pii").count(), 1);
|
|
assert.equal(await eye("Personal").getAttribute("aria-pressed"), "true");
|
|
|
|
// the window has its own: the account shown in the panel stays hidden there
|
|
const win = await open("http://magpie.test/?view=usage");
|
|
await win.locator(".subscription-account .quota-alias").first().waitFor();
|
|
await win.waitForFunction(() => document.querySelectorAll(".subscription-account .quota-of .pii").length === 2);
|
|
const ws = await win.evaluate(() => [...document.querySelectorAll(".subscription-account")].map((c) => c.textContent).join(" "));
|
|
assert.ok(!ws.includes(ME) && ws.includes("Personal"), "the window still hides it, not its name: " + ws);
|
|
await win.close();
|
|
|
|
// put away (the panel's page goes hidden): hidden again
|
|
await panel.evaluate(() => {
|
|
Object.defineProperty(document, "hidden", { configurable: true, get: () => true });
|
|
document.dispatchEvent(new Event("visibilitychange"));
|
|
});
|
|
await panel.waitForFunction((me) => [...document.querySelectorAll("#panelQuota .pq-card")].some((c) => c.querySelector(".pq-user").textContent === "Personal" && !c.title.includes(me)), ME);
|
|
assert.ok(!(await seen(card("Personal"))).includes(ME), "hidden once the panel is put away");
|
|
assert.equal(await eye("Personal").getAttribute("aria-pressed"), "false");
|
|
|
|
assert.equal(await panel.locator("select").count(), 0, "no native select");
|
|
assert.deepEqual(await stripes(panel, ".pq-card, .pq-card *"), [], "no border stripes");
|
|
assert.equal(await wide(panel), 0, `no sideways scroll at ${width}px`);
|
|
const fits = await panel.evaluate(() => [...document.querySelectorAll("#panelQuota .pq-card")].every((c) => { const r = c.getBoundingClientRect(), e = c.querySelector(".acct-eye").getBoundingClientRect(); return e.right <= r.right && e.width > 0; }));
|
|
assert.ok(fits, "each eye sits inside its card");
|
|
assert.deepEqual(errors, []);
|
|
await context.close();
|
|
}
|
|
});
|
|
|
|
test(`${engine} ${lang}: a Usage card's eye shows its account, on the card and its tooltips`, async (t) => {
|
|
const browser = await launch(t);
|
|
for (const width of [900, 360]) {
|
|
const context = await browser.newContext({ viewport: { width, height: 760 }, reducedMotion: "reduce" });
|
|
const page = await context.newPage();
|
|
page.setDefaultTimeout(5000);
|
|
page.setDefaultNavigationTimeout(60000);
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.route("**/*", serve(lang));
|
|
await page.goto("http://magpie.test/?view=usage");
|
|
await page.locator(".subscription-account .quota-alias").first().waitFor();
|
|
const card = (id) => page.locator(".subscription-account", { has: page.locator(".quota-of", { hasText: id }) });
|
|
assert.equal(await opacity(card(ME).locator(".acct-eye")), "none");
|
|
|
|
await page.locator("#usageMask").click();
|
|
await page.waitForFunction(() => document.querySelectorAll(".subscription-account .quota-of .pii").length === 2);
|
|
const eye = (id) => page.locator(".subscription-account .acct-eye").nth(id === TEAM ? 0 : 1);
|
|
assert.equal(await opacity(eye(ME)), "0");
|
|
await page.locator(".subscription-account").nth(1).hover();
|
|
assert.equal(await opacity(eye(ME)), "1");
|
|
const sc = await scrolled(page);
|
|
await eye(ME).click();
|
|
await page.waitForFunction(() => document.querySelectorAll(".subscription-account .quota-of .pii").length === 1);
|
|
assert.equal(await scrolled(page), sc, "a click scrolled");
|
|
const mine = page.locator(".subscription-account").nth(1), team = page.locator(".subscription-account").nth(0);
|
|
assert.equal(await mine.locator(".quota-alias").textContent(), "Personal");
|
|
assert.equal(await mine.locator(".quota-alias").getAttribute("title"), "Personal · " + ME);
|
|
assert.equal(await mine.locator(".quota-of").textContent(), ME);
|
|
assert.ok(!(await seen(team)).includes(TEAM) && !(await seen(team)).includes(SEAT), "the other card stays hidden");
|
|
assert.equal(await eye(ME).getAttribute("aria-pressed"), "true");
|
|
|
|
assert.equal(await page.locator("select").count(), 0, "no native select");
|
|
assert.deepEqual(await stripes(page, ".subscription-account, .subscription-account *"), [], "no border stripes");
|
|
assert.equal(await wide(page), 0, `no sideways scroll at ${width}px`);
|
|
assert.deepEqual(errors, []);
|
|
await context.close();
|
|
}
|
|
});
|
|
}
|
|
}
|