mirror of
https://github.com/Zakkaus/doona.git
synced 2026-12-05 16:02:03 +00:00
A Kv label set its help button inline with vertical-align: middle, which lands on the x-height midpoint and sits low beside CJK text; the label and its button now share a .rp-help-row flex line like every other help button. A light took its baseline from the dot, which has none, so inside a line box it sat on the dot's bottom edge. The text now gives the baseline.
51 lines
2.8 KiB
TypeScript
51 lines
2.8 KiB
TypeScript
import {expect, test} from './fixtures';
|
|
|
|
// A help button and a status light sit inside a line of text; each must share the text's vertical centre rather
|
|
// than hang off its baseline. Text is measured by its glyph box, so the check is about what the eye sees.
|
|
for (const width of [1440, 390]) {
|
|
test.describe(`${width}px`, () => {
|
|
test.use({viewport: {width, height: width === 390 ? 844 : 900}, storage: {'doona-lang': 'zh-TW', 'doona-scheme': 'dark'}});
|
|
|
|
test('the overview meta row keeps its help button and status light level with the text', async ({page}) => {
|
|
await page.goto('/#/overview');
|
|
const help = page.locator('.rp-kv.row .k .rp-help').first();
|
|
await expect(help).toBeVisible();
|
|
await expect(page.locator('.rp-kv.row ~ * .rp-light')).toBeVisible();
|
|
|
|
const centres = await page.evaluate(() => {
|
|
const middle = (rect: DOMRect) => rect.top + rect.height / 2;
|
|
const glyphs = (element: Element) => {
|
|
const range = document.createRange();
|
|
range.selectNodeContents(element);
|
|
return middle(range.getBoundingClientRect());
|
|
};
|
|
const label = document.querySelector('.rp-kv.row .k .rp-help-row')!;
|
|
const text = [...label.childNodes].find(node => node.nodeType === Node.TEXT_NODE)!;
|
|
const labelRange = document.createRange();
|
|
labelRange.selectNodeContents(text);
|
|
const light = document.querySelector('.rp-kv.row ~ * .rp-light')!;
|
|
// The reload status follows the time of the last reload, the last value in the row.
|
|
const values = document.querySelectorAll('.rp-kv.row .v');
|
|
const time = values[values.length - 1].getBoundingClientRect();
|
|
const lightBox = light.getBoundingClientRect();
|
|
return {
|
|
// On a phone the row wraps and the light may start a line of its own, with no time beside it to match.
|
|
shared: lightBox.top < time.bottom && time.top < lightBox.bottom,
|
|
label: middle(labelRange.getBoundingClientRect()),
|
|
help: middle(label.querySelector('.rp-help')!.getBoundingClientRect()),
|
|
time: glyphs(values[values.length - 1]),
|
|
// The dot is centred in the light's box, so the box's centre is the dot's.
|
|
dot: middle(light.getBoundingClientRect()),
|
|
status: glyphs(light.querySelector('span')!)
|
|
};
|
|
});
|
|
expect(Math.abs(centres.help - centres.label), 'help button against its label').toBeLessThanOrEqual(1);
|
|
expect(Math.abs(centres.dot - centres.status), 'light dot against its text').toBeLessThanOrEqual(1);
|
|
if (centres.shared) {
|
|
expect(Math.abs(centres.status - centres.time), 'light text against the time').toBeLessThanOrEqual(1);
|
|
expect(Math.abs(centres.dot - centres.time), 'light dot against the time').toBeLessThanOrEqual(1);
|
|
}
|
|
});
|
|
});
|
|
}
|