mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-10-06 06:52:20 +02:00
test(document): use platform-correct input in the rich color test
test_rich_colors_follow_theme_and_undo_as_one_edit fails identically on every macOS run, timing out after 30s waiting for a span that never appears. It was written off as timing noise twice. It is not flaky - it is two Linux-only input conventions, and the product code is fine. Control+click: macOS delivers a Control-modified primary click as contextmenu, not click. Instrumenting the Lemon swatch shows the button receiving pointerdown, mousedown, contextmenu, pointerup, mouseup - and no click, so the menu item's handler never runs and no highlight is applied. Control was never meaningful here anyway; the palette item has no modifier behaviour. The two calls now use a plain click. Control+Z: the editor's undo accelerator is Cmd+Z on macOS. With the clicks fixed, both undo assertions still failed until the presses became ControlOrMeta+Z, which Playwright maps per platform. Both fixes are portable - a plain click and ControlOrMeta are unchanged on Linux, where this test already passes. pytest tests/test_document_rich_color_reset_and_contrast.py 2 passed in 2.11s (1 failed, 1 passed before) Not verified: Linux. I only have macOS here, so the claim that this stays green on CI rests on the modifier being a no-op there, not on a run.
This commit is contained in:
@@ -20,6 +20,12 @@ def test_color_controls_have_theme_reset_and_split_palettes():
|
||||
|
||||
|
||||
def test_rich_colors_follow_theme_and_undo_as_one_edit():
|
||||
# Two input conventions in here are platform-sensitive and must stay that
|
||||
# way. Palette entries are opened with a plain click: on macOS a
|
||||
# Control+click is delivered as `contextmenu`, so the menu item's `click`
|
||||
# handler never runs and nothing is applied. Undo uses Playwright's
|
||||
# `ControlOrMeta` alias because the editor's undo accelerator is Cmd+Z on
|
||||
# macOS and Ctrl+Z everywhere else.
|
||||
script = r"""
|
||||
import { chromium } from 'playwright';
|
||||
const browser = await chromium.launch({ headless: true });
|
||||
@@ -58,24 +64,24 @@ def test_rich_colors_follow_theme_and_undo_as_one_edit():
|
||||
labels: [...document.querySelectorAll('.rich-color-palette-label')].map(item => item.textContent),
|
||||
reset: document.querySelector('.rich-color-reset')?.textContent.trim(),
|
||||
}));
|
||||
await page.locator('#doc-md-dd-menu .doc-overflow-item').filter({ hasText: 'Lemon' }).click({ modifiers: ['Control'] });
|
||||
await page.locator('#doc-md-dd-menu .doc-overflow-item').filter({ hasText: 'Lemon' }).click();
|
||||
const highlighted = await page.locator('#doc-email-richbody p').nth(0).locator('span').evaluate(span => ({
|
||||
color: getComputedStyle(span).color,
|
||||
background: getComputedStyle(span).backgroundColor,
|
||||
}));
|
||||
await page.locator('#doc-email-richbody').press('Control+z');
|
||||
await page.locator('#doc-email-richbody').press('ControlOrMeta+z');
|
||||
const highlightUndone = await page.locator('#doc-email-richbody p').nth(0).innerHTML();
|
||||
|
||||
await selectParagraph(1);
|
||||
await openMenu('color');
|
||||
await page.locator('.rich-color-reset').click({ modifiers: ['Control'] });
|
||||
await page.locator('.rich-color-reset').click();
|
||||
const defaultColor = await page.locator('#doc-email-richbody p').nth(1).locator('span').evaluate(span => ({
|
||||
style: span.getAttribute('style'),
|
||||
color: getComputedStyle(span).color,
|
||||
}));
|
||||
await page.evaluate(() => document.documentElement.style.setProperty('--fg', '#88cc44'));
|
||||
const changedThemeColor = await page.locator('#doc-email-richbody p').nth(1).locator('span').evaluate(span => getComputedStyle(span).color);
|
||||
await page.locator('#doc-email-richbody').press('Control+z');
|
||||
await page.locator('#doc-email-richbody').press('ControlOrMeta+z');
|
||||
const colorUndone = await page.locator('#doc-email-richbody p').nth(1).innerHTML();
|
||||
console.log(JSON.stringify({ palette, highlighted, highlightUndone, defaultColor, changedThemeColor, colorUndone }));
|
||||
await browser.close();
|
||||
|
||||
Reference in New Issue
Block a user