Files
buzz/desktop/tests/helpers/css.ts
3f2f32641f Polish desktop onboarding flow (#5310)
## Summary
- standardize onboarding navigation and horizontal step transitions
- refine the avatar editor with live preview, segmented modes, search,
skin tones, and reduced-motion-safe feedback
- simplify harness/default-model actions and supporting copy

## Testing
- desktop typecheck and static guards
- desktop E2E build
- 9 focused onboarding smoke tests
- 4 focused onboarding/profile integration walkthroughs
- 4,535 desktop unit tests

---------

Signed-off-by: kenny lopez <klopez4212@gmail.com>
Signed-off-by: Kenny Lopez <klopez4212@gmail.com>
Co-authored-by: Carl <3c4caeafb646d23867f1c4832e68211d77e2561946171625f75c3ce1a3f2670f@buzz.block.builderlab.xyz>
2026-08-10 14:33:23 -07:00

113 lines
3.3 KiB
TypeScript

import { expect, type Locator } from "@playwright/test";
export async function expectCornerRadiusPx(
locator: Locator,
expectedRadiusPx: number,
) {
const measurement = await locator.evaluate((element) => {
const style = window.getComputedStyle(element);
const rootFontSize = Number.parseFloat(
window.getComputedStyle(document.documentElement).fontSize,
);
const resolveLength = (value: string) => {
const probe = document.createElement("div");
for (const sourceStyle of [
window.getComputedStyle(document.documentElement),
style,
]) {
for (let i = 0; i < sourceStyle.length; i += 1) {
const name = sourceStyle.item(i);
if (name.startsWith("--")) {
probe.style.setProperty(name, sourceStyle.getPropertyValue(name));
}
}
}
probe.style.position = "absolute";
probe.style.visibility = "hidden";
probe.style.pointerEvents = "none";
probe.style.width = value;
document.body.append(probe);
const resolved = window.getComputedStyle(probe).width;
probe.remove();
return resolved;
};
const toPx = (value: string): number => {
const trimmed = value.trim();
if (/^-?\d+(?:\.\d+)?px$/.test(trimmed)) {
return Number.parseFloat(trimmed);
}
if (/^-?\d+(?:\.\d+)?rem$/.test(trimmed)) {
return Number.parseFloat(trimmed) * rootFontSize;
}
const resolved = resolveLength(trimmed);
if (resolved !== trimmed) {
return toPx(resolved);
}
return Number.parseFloat(resolved);
};
const rawRadius =
style.borderTopLeftRadius ||
style.getPropertyValue("border-top-left-radius") ||
style.borderRadius ||
style.getPropertyValue("border-radius") ||
(element instanceof HTMLElement
? element.style.borderTopLeftRadius || element.style.borderRadius
: "");
const radius = toPx(rawRadius);
if (!Number.isFinite(radius)) {
throw new Error(`Could not resolve border radius from "${rawRadius}".`);
}
return {
className: element.getAttribute("class") ?? "",
radius,
rawRadius,
};
});
expect(
measurement.radius,
`Expected ${expectedRadiusPx}px corner radius, got ${measurement.rawRadius} on class "${measurement.className}".`,
).toBeCloseTo(expectedRadiusPx, 0);
}
export async function expectSmoothCorners(
locator: Locator,
expectedSmoothing = 0.6,
) {
await expect
.poll(async () =>
locator.evaluate((element, smoothing) => {
if (!(element instanceof HTMLElement)) {
return false;
}
const clipPath =
element.style.clipPath ||
element.style.getPropertyValue("-webkit-clip-path");
return (
element.dataset.smoothCorners === "" &&
element.dataset.smoothCornersSmoothing === String(smoothing) &&
clipPath.startsWith('path("M ') &&
clipPath.includes(" a ")
);
}, expectedSmoothing),
)
.toBe(true);
}
/** Wait for the Buzz overrides to be installed in Emoji Mart's shadow root. */
export async function expectEmojiMartStylesInstalled(picker: Locator) {
await expect
.poll(async () =>
picker.evaluate((element) =>
Boolean(element.shadowRoot?.querySelector("#buzz-emoji-mart-style")),
),
)
.toBe(true);
}