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
Merge build/1315-command-line into mainoscabrielbefore adoption252b871
lines 1–9why, one step back1import { expect, test } from "@playwright/test";2import { Config, Effect, Option } from "effect";34const web = Effect.runSync(5 Config.option(Config.NonEmptyString("WEB_URL")).pipe(6 Effect.map(Option.map((url) => url.replace(/\/+$/u, "")))7 )8);9Merge redesign into mainoscabrielbefore adoptioncaedd21
line 10why, one step back10const PAGES = ["/inbox", "/install"];Merge build/1315-command-line into mainoscabrielbefore adoption252b871
lines 11–88why, one step back1112const WIDTHS = [390, 1280];1314test.describe("the command line", () => {15 test.skip(16 Option.isNone(web),17 "WEB_URL is not set: point it at a web's origin to run this check"18 );1920 for (const width of WIDTHS) {21 test(`breaks no word that fits its line, at ${width} px`, ({22 page: browser,23 }) =>24 Effect.runPromise(25 Effect.gen(function* () {26 const origin = Option.getOrElse(web, () => "");2728 yield* Effect.promise(() =>29 browser.setViewportSize({ height: 900, width })30 );3132 const broken = yield* Effect.forEach(PAGES, (path) =>33 Effect.gen(function* () {34 yield* Effect.promise(() => browser.goto(`${origin}${path}`));3536 yield* Effect.promise(() =>37 expect(browser.locator("code.select-all").first()).toBeVisible()38 );3940 // Each word's own width, set on one row, against its row's41 // room: a word that fits and still takes two rows is broken.42 const words = yield* Effect.promise(() =>43 browser.$$eval("code.select-all span.inline-block", (spans) =>44 spans.map((span) => {45 const line = span.parentElement ?? span;46 const bounds = line.getBoundingClientRect();4748 const hang = Number(49 getComputedStyle(line).paddingLeft.replace("px", "")50 );5152 const word = span.getBoundingClientRect();5354 span.style.whiteSpace = "pre";55 span.style.maxWidth = "none";56 const natural = span.getBoundingClientRect().width;57 span.style.whiteSpace = "";58 span.style.maxWidth = "";5960 return {61 natural,62 room:63 bounds.width -64 hang +65 (Math.abs(word.top - bounds.top) < 1 ? hang : 0),66 rows: Math.round(67 word.height /68 Number(69 getComputedStyle(line).lineHeight.replace("px", "")70 )71 ),72 word: span.textContent,73 };74 })75 )76 );7778 return words.flatMap(({ natural, room, rows, word }) =>79 natural <= room && rows > 1 ? [`${path}: ${word}`] : []80 );81 })82 );8384 expect(broken.flat()).toStrictEqual([]);85 })86 ));87 }88});