Phone, notch and dark mode

A responsive page checked as a phone. The check switches the screen to a phone's with emulate, adds a notch and a home bar with safeArea, asks for less motion and then for dark mode, and checks the layout with expressions that measure the page.

Run it#

shell
cd examples/phone-dark
npx brokit check --verbose      # --verbose lists every step, as below
terminal
$ brokit check --verbose
brokit check: 1 scenario, Chrome 158.0.8127.36, software drawing
✓ checks/trips  11 steps, 0.9 s, 2 baselines written
    ✓ expect getComputedStyle(document.querySelector('.trips')).gridTempl… equals 2
    ✓ emulate {"size":"393x852","dpr":2,"mobile":true,"reducedMotion":"reduce"}  112 ms
    ✓ expect getComputedStyle(document.querySelector('.trips')).gridTempl… equals 1
    ✓ safeArea [59,0,34,0]
    ✓ expect document.querySelector('header h1').getBoundingClientRect().… ≥ 59
    ✓ expect innerHeight - document.querySelector('nav a').getBoundingCli… ≥ 34
    ✓ expect getComputedStyle(document.querySelector('.live')).animationN… equals "none"
    ✓ screenshot light → brokit-out/checks/trips/light.png (786×1704) [baseline: new]  286 ms
    ✓ emulate {"colorScheme":"dark"}
    ✓ expect getComputedStyle(document.body).backgroundColor equals "rgb(16, 18, 23)"
    ✓ screenshot dark → brokit-out/checks/trips/dark.png (786×1704) [baseline: new]  183 ms
1 scenario passed in 0.9 s

The first run writes the baselines (checks/baselines/trips/light.png and dark.png); the runs after it compare against them. In a real project you commit the baselines. They're not committed here, since they depend on the fonts of the machine that made them.

A list of four trips on a phone in light mode, the title below the notch The same trips page in dark mode

The baselines: light and dark, on a phone with a notch.

The page#

index.html is a list of trips with a header and a tab bar. style.css does four things a phone page often needs:

The check#

The check, checks/trips.check.json:

checks/trips.check.json
{
  "note": "The trips page, first on a laptop, then as a phone with a notch, in light and dark.",
  "url": "/index.html",
  "viewport": { "size": "1024x700" },
  "ready": "document.readyState === 'complete'",
  "steps": [
    {
      "expect": "getComputedStyle(document.querySelector('.trips')).gridTemplateColumns.split(' ').length",
      "equals": 2,
      "note": "on a laptop, two columns"
    },
    {
      "emulate": { "size": "393x852", "dpr": 2, "mobile": true, "reducedMotion": "reduce" },
      "note": "now a phone, whose user asked for less motion"
    },
    {
      "expect": "getComputedStyle(document.querySelector('.trips')).gridTemplateColumns.split(' ').length",
      "equals": 1,
      "note": "on a phone, one column"
    },
    { "safeArea": [59, 0, 34, 0], "note": "the notch at the top, the home bar at the bottom" },
    {
      "expect": "document.querySelector('header h1').getBoundingClientRect().top",
      "atLeast": 59,
      "note": "the title is clear of the notch"
    },
    {
      "expect": "innerHeight - document.querySelector('nav a').getBoundingClientRect().bottom",
      "atLeast": 34,
      "note": "the tab bar's buttons are clear of the home bar"
    },
    {
      "expect": "getComputedStyle(document.querySelector('.live')).animationName",
      "equals": "none",
      "note": "with reduced motion, the pulsing dot holds still"
    },
    { "screenshot": "light", "baseline": true },
    { "emulate": { "colorScheme": "dark" } },
    {
      "expect": "getComputedStyle(document.body).backgroundColor",
      "equals": "rgb(16, 18, 23)",
      "note": "the page follows the phone's dark mode"
    },
    { "screenshot": "dark", "baseline": true }
  ]
}

Learn more#

Edit this page on GitHub