feat(editor): the held reason shows in a bubble by its button

This commit is contained in:
bchanot committed 2026-11-19 20:50:56 +01:00
1 parent 031826dced
commit 49f0144729
11 files changed
+313 -79

No files matched your search

+61 -8
View File
@@ -1,5 +1,5 @@
import { fr } from '@/i18n/fr'
import type { Page, TestInfo } from '@playwright/test'
import type { Locator, Page, TestInfo } from '@playwright/test'
import { expect, expectAccessible, test } from '../support/browser'
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
import {
@@ -51,6 +51,32 @@ const tool = (page: Page, id: string) =>
exact: true,
})
const scrollWidth = (page: Page) =>
page.evaluate(() => document.documentElement.scrollWidth)
/** The bubble sits in the window, under the top bar, under its button and clear of the other. */
async function expectBubbleBeside(
page: Page,
bubble: Locator,
button: Locator,
other: Locator,
) {
const box = await bubble.boundingBox()
const own = await button.boundingBox()
const next = await other.boundingBox()
const bar = await page.locator('header').first().boundingBox()
const view = page.viewportSize()
if (!box || !own || !next || !bar || !view)
throw new Error('a box is missing')
expect(box.x).toBeGreaterThanOrEqual(0)
expect(box.x + box.width).toBeLessThanOrEqual(view.width)
expect(box.y + box.height).toBeLessThanOrEqual(view.height)
expect(box.y).toBeGreaterThanOrEqual(bar.y + bar.height)
expect(box.y).toBeGreaterThanOrEqual(own.y + own.height)
const apart = box.y >= next.y + next.height || box.x >= next.x + next.width
expect(apart).toBe(true)
}
interface Names {
fr: string
en: string
@@ -222,7 +248,7 @@ test.describe('editor annotations (A3)', () => {
).toBe('zone-a')
})
test('a held « Refaire » says why: description on focus, message on press, nothing moves', async ({
test('a held « Refaire » says why: description on focus, a bubble on press at three sizes, nothing moves', async ({
page,
requests,
}) => {
@@ -251,11 +277,38 @@ test.describe('editor annotations (A3)', () => {
dict['editor.history.hold_creation'],
)
await expectAccessible(page, 'a held « Refaire » during a creation')
await expectNoShift(page, async () => {
await pressAtBox(page, redo)
await expect(page.getByTestId('gesture-line')).toContainText(reason)
})
await expect(page.getByTestId('gesture-message')).toHaveCount(1)
const bubble = page.getByTestId('history-hold-bubble')
const undo = historyButton(page, dict, 'undo')
for (const [width, height] of [
[1024, 768],
[1180, 820],
[1280, 800],
]) {
await page.setViewportSize({ width, height })
// The resize's own reflow (a breakpoint) settles before the press is measured.
await page.waitForTimeout(300)
await redo.evaluate((el) => el.scrollIntoView({ block: 'center' }))
const widthBefore = await scrollWidth(page)
await expectNoShift(page, async () => {
await pressAtBox(page, redo)
await expect(bubble).toHaveText(reason)
})
await expectBubbleBeside(page, bubble, redo, undo)
expect(await scrollWidth(page)).toBe(widthBefore)
await expectAccessible(page, `the bubble open at ${width}`)
await expectNoShift(page, () => page.keyboard.press('Escape'))
await expect(bubble).toHaveCount(0)
}
await expect(page.getByTestId('gesture-message')).toHaveCount(0)
// Escape order: the bubble first, alone; the next Escape asks about the creation.
await redo.focus()
await page.keyboard.press('Enter')
await expect(bubble).toHaveText(reason)
await page.keyboard.press('Escape')
await expect(bubble).toHaveCount(0)
await expect(page.getByRole('dialog')).toHaveCount(0)
await page.keyboard.press('Escape')
await expect(page.getByRole('dialog')).toHaveCount(1)
})
test('a mouse click on « Refaire » during an arrow series says why; « Défaire » cancels and keeps the redo', async ({
@@ -293,7 +346,7 @@ test.describe('editor annotations (A3)', () => {
// bar, then press it at its box (the mouse events are real).
await redo.evaluate((el) => el.scrollIntoView({ block: 'center' }))
await pressAtBox(page, redo)
await expect(page.getByTestId('gesture-line')).toContainText(
await expect(page.getByTestId('history-hold-bubble')).toHaveText(
dict['editor.history.hold_pending'],
)
await expect(handle).toBeFocused()