Add Dock icon pack and polish controls and navigation geometry
This commit is contained in:
1 parent
ef98c2835b
commit
99156ed011
161 files changed
+1438
-54
No files matched your search
+164
@@ -0,0 +1,164 @@
|
||||
import { chromium } from "playwright";
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdir, writeFile } from "node:fs/promises";
|
||||
import { icons, iconNames } from "../icons/icons.js";
|
||||
const base = process.env.BASE_URL || "http://127.0.0.1:4173";
|
||||
const b = await chromium.launch({
|
||||
executablePath:
|
||||
process.env.PLAYWRIGHT_EXECUTABLE_PATH ||
|
||||
"C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe",
|
||||
headless: true,
|
||||
});
|
||||
const context = await b.newContext({ acceptDownloads: true });
|
||||
const p = await context.newPage();
|
||||
const errors = [];
|
||||
p.on("pageerror", (e) => errors.push(e.message));
|
||||
let passed = 0;
|
||||
await mkdir("references/icons", { recursive: true });
|
||||
try {
|
||||
assert.equal(iconNames.length, 64);
|
||||
assert.equal(new Set(iconNames).size, 64);
|
||||
await p.goto(base + "/icons/");
|
||||
await p.locator(".icon-tile").last().waitFor();
|
||||
const bounds = await p.locator(".icon-tile svg").evaluateAll((es) =>
|
||||
es.map((e) => {
|
||||
const box = e.getBBox();
|
||||
return {
|
||||
id: e.closest("button").dataset.icon,
|
||||
x: box.x,
|
||||
y: box.y,
|
||||
right: box.x + box.width,
|
||||
bottom: box.y + box.height,
|
||||
};
|
||||
}),
|
||||
);
|
||||
for (const box of bounds) {
|
||||
assert.ok(
|
||||
box.x >= 1 && box.y >= 1 && box.right <= 23 && box.bottom <= 23,
|
||||
JSON.stringify(box),
|
||||
);
|
||||
passed++;
|
||||
}
|
||||
for (const size of [16, 20, 24, 32, 48]) {
|
||||
await p.locator("#size").selectOption(String(size));
|
||||
assert.equal(
|
||||
await p
|
||||
.locator(".icon-tile svg")
|
||||
.first()
|
||||
.evaluate((e) => e.getBoundingClientRect().width),
|
||||
size,
|
||||
);
|
||||
passed++;
|
||||
}
|
||||
await p.locator("#search").fill("Безопасность");
|
||||
assert.equal(await p.locator(".icon-tile").count(), 1);
|
||||
await p.locator("#search").fill("nothing-matches");
|
||||
assert.equal(await p.locator("#empty").isVisible(), true);
|
||||
await p.locator("#search").fill("");
|
||||
await p.locator("#category").selectOption("actions");
|
||||
assert.equal(await p.locator(".icon-tile").count(), 8);
|
||||
passed++;
|
||||
await context.grantPermissions(["clipboard-read", "clipboard-write"], {
|
||||
origin: base,
|
||||
});
|
||||
await p.locator("[data-icon=copy]").click();
|
||||
const copied = await p.evaluate(() => navigator.clipboard.readText());
|
||||
assert.match(copied, /viewBox="0 0 24 24"/);
|
||||
assert.match(copied, /width="48"/);
|
||||
passed++;
|
||||
const packDownload = p.waitForEvent("download");
|
||||
await p.locator(".download-pack").click();
|
||||
await (await packDownload).saveAs("test-results/anidev-dock-icons.zip");
|
||||
passed++;
|
||||
await p.locator("#category").selectOption("");
|
||||
await p.locator("#size").selectOption("24");
|
||||
for (const theme of ["light", "dark"])
|
||||
for (const width of [1440, 768, 390]) {
|
||||
await p.setViewportSize({ width, height: 900 });
|
||||
if ((await p.locator("body").getAttribute("data-theme")) !== theme)
|
||||
await p.locator("#theme").click();
|
||||
assert.ok(
|
||||
await p.evaluate(
|
||||
() => document.documentElement.scrollWidth <= innerWidth,
|
||||
),
|
||||
);
|
||||
await p.screenshot({
|
||||
path: `references/icons/catalog-${theme}-${width}.png`,
|
||||
fullPage: true,
|
||||
});
|
||||
passed++;
|
||||
}
|
||||
for (const theme of ["light", "dark"])
|
||||
for (const width of [1440, 768, 390])
|
||||
for (const locale of ["ru", "en"]) {
|
||||
await p.setViewportSize({ width, height: 900 });
|
||||
await p.goto(`${base}/?page=security&theme=${theme}&locale=${locale}`);
|
||||
await p.locator(".nav-icon").first().waitFor();
|
||||
const nav = await p.locator(".navigation").boundingBox();
|
||||
for (const button of await p.locator(".nav-links button").all()) {
|
||||
const rect = await button.boundingBox(),
|
||||
glyph = await button.locator("svg").boundingBox();
|
||||
assert.equal(glyph.width, 24);
|
||||
assert.equal(glyph.height, 24);
|
||||
assert.ok(Math.abs(glyph.x + 12 - (rect.x + rect.width / 2)) < 0.1);
|
||||
assert.ok(Math.abs(glyph.y + 12 - (rect.y + rect.height / 2)) < 0.1);
|
||||
assert.ok(Math.abs(glyph.x + 12 - (nav.x + nav.width / 2)) < 0.1);
|
||||
}
|
||||
const avatar = await p.locator(".dock-account .avatar").boundingBox();
|
||||
assert.ok(
|
||||
Math.abs(avatar.x + avatar.width / 2 - (nav.x + nav.width / 2)) < 0.1,
|
||||
);
|
||||
// Keyboard modality, rather than programmatic focus after a mouse click.
|
||||
await p.keyboard.press("Tab");
|
||||
await p.locator(".nav-links [aria-current=page]").focus();
|
||||
assert.equal(
|
||||
await p
|
||||
.locator(".nav-links [aria-current=page]")
|
||||
.evaluate((e) => getComputedStyle(e).outlineOffset),
|
||||
"-2px",
|
||||
);
|
||||
if (locale === "ru") await p.waitForTimeout(300);
|
||||
if (locale === "ru")
|
||||
await p.screenshot({
|
||||
path: `references/icons/dock-${theme}-${width}.png`,
|
||||
});
|
||||
await p.locator(".dock-brand").click();
|
||||
await p.waitForTimeout(300);
|
||||
const after = await p
|
||||
.locator(".nav-links button svg")
|
||||
.first()
|
||||
.boundingBox();
|
||||
assert.ok(Math.abs(after.x + 12 - (nav.x + nav.width / 2)) < 0.1);
|
||||
await p.keyboard.press("Escape");
|
||||
passed++;
|
||||
}
|
||||
await p.setViewportSize({ width: 960, height: 1140 });
|
||||
for (const theme of ["light", "dark"]) {
|
||||
await p.goto(`${base}/icons/preview-${theme}.svg`);
|
||||
await p.screenshot({ path: `references/icons/preview-${theme}.png` });
|
||||
}
|
||||
// Full design export must include the icon module and a valid binary icon ZIP.
|
||||
await p.goto(base + "/?page=tokens");
|
||||
const exported = p.waitForEvent("download");
|
||||
await p.locator("[data-action=download-system]").click();
|
||||
await (await exported).saveAs("test-results/icons-system-export.zip");
|
||||
passed++;
|
||||
assert.deepEqual(errors, []);
|
||||
await writeFile(
|
||||
"references/icons/qa.json",
|
||||
JSON.stringify(
|
||||
{
|
||||
passed,
|
||||
errors,
|
||||
iconCount: iconNames.length,
|
||||
checks:
|
||||
"SVG bounds; five sizes; catalog search/filter/copy/download; both themes; RU/EN; desktop/tablet/mobile; nav and avatar centering; inset keyboard focus; stable icon position when Dock expands; binary export",
|
||||
},
|
||||
null,
|
||||
2,
|
||||
) + "\n",
|
||||
);
|
||||
console.log(`Icons: ${passed} checks passed, no runtime errors`);
|
||||
} finally {
|
||||
await b.close();
|
||||
}
|
||||
Reference in new issue
Block a user