command-line.e2e.ts
This file
Path
apps/web/e2e/command-line.e2e.ts
88 lines · 2.9 KiB · TypeScript
Last changed by
Merge redesign into mainoscabrielbefore adoptioncaedd21
History of this fileTake it
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889import { expect, test } from "@playwright/test";import { Config, Effect, Option } from "effect";
const web = Effect.runSync( Config.option(Config.NonEmptyString("WEB_URL")).pipe( Effect.map(Option.map((url) => url.replace(/\/+$/u, ""))) ));
const PAGES = ["/inbox", "/install"];
const WIDTHS = [390, 1280];
test.describe("the command line", () => { test.skip( Option.isNone(web), "WEB_URL is not set: point it at a web's origin to run this check" );
for (const width of WIDTHS) { test(`breaks no word that fits its line, at ${width} px`, ({ page: browser, }) => Effect.runPromise( Effect.gen(function* () { const origin = Option.getOrElse(web, () => "");
yield* Effect.promise(() => browser.setViewportSize({ height: 900, width }) );
const broken = yield* Effect.forEach(PAGES, (path) => Effect.gen(function* () { yield* Effect.promise(() => browser.goto(`${origin}${path}`));
yield* Effect.promise(() => expect(browser.locator("code.select-all").first()).toBeVisible() );
// Each word's own width, set on one row, against its row's // room: a word that fits and still takes two rows is broken. const words = yield* Effect.promise(() => browser.$$eval("code.select-all span.inline-block", (spans) => spans.map((span) => { const line = span.parentElement ?? span; const bounds = line.getBoundingClientRect();
const hang = Number( getComputedStyle(line).paddingLeft.replace("px", "") );
const word = span.getBoundingClientRect();
span.style.whiteSpace = "pre"; span.style.maxWidth = "none"; const natural = span.getBoundingClientRect().width; span.style.whiteSpace = ""; span.style.maxWidth = "";
return { natural, room: bounds.width - hang + (Math.abs(word.top - bounds.top) < 1 ? hang : 0), rows: Math.round( word.height / Number( getComputedStyle(line).lineHeight.replace("px", "") ) ), word: span.textContent, }; }) ) );
return words.flatMap(({ natural, room, rows, word }) => natural <= room && rows > 1 ? [`${path}: ${word}`] : [] ); }) );
expect(broken.flat()).toStrictEqual([]); }) )); }});