|
27 | 27 | sync_api = pytest.importorskip("playwright.sync_api", reason="Playwright is not installed") |
28 | 28 |
|
29 | 29 | WAIT_MS = 60_000 |
| 30 | +WIDE = {"width": 1440, "height": 900} |
| 31 | +NARROW = {"width": 390, "height": 844} |
30 | 32 | READY = "table.problems tbody tr" |
31 | 33 | VERSION_LINK = ".statusbar a.segment.version" |
32 | 34 | TOP_BAR_LINKS = "header.topbar nav a" |
@@ -72,6 +74,8 @@ class Seen: |
72 | 74 | license_requests_before_open: int = -1 |
73 | 75 | license_requests_after_open: int = -1 |
74 | 76 | license_text: str = "" |
| 77 | + wide: dict[str, Any] = field(default_factory=dict[str, Any]) |
| 78 | + narrow: dict[str, Any] = field(default_factory=dict[str, Any]) |
75 | 79 | uppercase: list[str] = field(default_factory=list[str]) |
76 | 80 | all_caps: list[str] = field(default_factory=list[str]) |
77 | 81 | brand_hash: str = "" |
@@ -108,6 +112,7 @@ def seen(engine: str, server: RunningServer) -> Seen: |
108 | 112 | page.wait_for_selector(FACTS) |
109 | 113 | _read_the_view(page, found, server) |
110 | 114 | found.requests_before_open = list(requests) |
| 115 | + _read_the_widths(page, found) |
111 | 116 | _read_the_licenses(page, found, requests) |
112 | 117 | found.requests_to_other_sites = [ |
113 | 118 | url for url in requests if not url.startswith(server.address) |
@@ -174,6 +179,38 @@ def _licenses_requested(requests: list[str]) -> int: |
174 | 179 | return sum(url.endswith(LICENSES_PATH) for url in requests) |
175 | 180 |
|
176 | 181 |
|
| 182 | +WIDTHS_PROBE = """() => { |
| 183 | + const lines = (element) => { |
| 184 | + const style = getComputedStyle(element); |
| 185 | + return Math.round(element.getBoundingClientRect().height / parseFloat(style.lineHeight)); |
| 186 | + }; |
| 187 | + const wraps = (element) => { |
| 188 | + const range = document.createRange(); |
| 189 | + range.selectNodeContents(element); |
| 190 | + return new Set([...range.getClientRects()].map((box) => Math.round(box.top))).size > 1; |
| 191 | + }; |
| 192 | + const names = [...document.querySelectorAll(".credit-name")]; |
| 193 | + return { |
| 194 | + author: lines(document.querySelector(".about-author")), |
| 195 | + sponsor: lines(document.querySelector(".about-sponsor")), |
| 196 | + intro: lines(document.querySelector(".about-credits > p")), |
| 197 | + wrapped_names: names.filter(wraps).map((name) => name.textContent), |
| 198 | + page_overflows: document.documentElement.scrollWidth > window.innerWidth, |
| 199 | + table_overflows: [...document.querySelectorAll(".credits-scroll")].some( |
| 200 | + (box) => box.getBoundingClientRect().right > window.innerWidth |
| 201 | + ), |
| 202 | + }; |
| 203 | +}""" |
| 204 | + |
| 205 | + |
| 206 | +def _read_the_widths(page: Any, found: Seen) -> None: |
| 207 | + page.set_viewport_size(WIDE) |
| 208 | + found.wide = page.evaluate(WIDTHS_PROBE) |
| 209 | + page.set_viewport_size(NARROW) |
| 210 | + found.narrow = page.evaluate(WIDTHS_PROBE) |
| 211 | + page.set_viewport_size(WIDE) |
| 212 | + |
| 213 | + |
177 | 214 | def _read_the_licenses(page: Any, found: Seen, requests: list[str]) -> None: |
178 | 215 | found.license_requests_before_open = _licenses_requested(requests) |
179 | 216 | page.click(LICENSES_SUMMARY) |
@@ -311,6 +348,30 @@ def test_the_author_link_has_the_static_utm_tags_and_opens_safely(seen): |
311 | 348 | } |
312 | 349 |
|
313 | 350 |
|
| 351 | +def test_the_sponsor_sentence_and_the_credits_introduction_stay_on_one_line_on_a_wide_window(seen): |
| 352 | + assert (seen.wide["author"], seen.wide["sponsor"], seen.wide["intro"]) == (1, 1, 1) |
| 353 | + |
| 354 | + |
| 355 | +def test_no_package_name_wraps_on_a_wide_window(seen): |
| 356 | + assert seen.wide["wrapped_names"] == [] |
| 357 | + |
| 358 | + |
| 359 | +def test_no_package_name_wraps_on_a_narrow_window(seen): |
| 360 | + assert seen.narrow["wrapped_names"] == [] |
| 361 | + |
| 362 | + |
| 363 | +def test_the_page_never_scrolls_sideways_on_a_narrow_window(seen): |
| 364 | + assert seen.narrow["page_overflows"] is False |
| 365 | + |
| 366 | + |
| 367 | +def test_a_credits_table_stays_inside_a_narrow_window(seen): |
| 368 | + assert seen.narrow["table_overflows"] is False |
| 369 | + |
| 370 | + |
| 371 | +def test_the_text_wraps_on_a_narrow_window(seen): |
| 372 | + assert seen.narrow["sponsor"] > 1 |
| 373 | + |
| 374 | + |
314 | 375 | def test_nothing_is_requested_from_another_site(seen): |
315 | 376 | assert seen.requests_to_other_sites == [] |
316 | 377 |
|
|
0 commit comments