fix(editor): Task 1 review round 1, section back pops, scroll proof

This commit is contained in:
bchanot committed 2026-11-13 18:12:19 +01:00
1 parent 792394d3b2
commit 8e4f02620a
7 files changed
+251 -64

No files matched your search

+48 -3
View File
@@ -3,6 +3,7 @@ import type { Page, TestInfo } from '@playwright/test'
import { expect, test } from '../support/browser'
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
import {
backToDrawing,
editorActor,
openEditor,
openSection,
@@ -26,8 +27,9 @@ const tabName = (tab: string) =>
new RegExp(`^${dict[`editor.tab.${tab}`]}( |$)`)
/**
* The history follows a move from an effect, a few milliseconds after the click: wait for
* the entry on top to name the tab before pressing Back (a user cannot be that quick).
* Waits until the entry on top of the history names `tab`. The adapter writes from an
* effect a few milliseconds after a click, so a script pressing Back at once would land
* on the wrong entry (a user cannot be that quick): every Back below waits through this.
*/
async function written(page: Page, tab: string) {
await page.waitForFunction(
@@ -88,7 +90,7 @@ test.describe('editor browser history', () => {
await expect(selected(page)).toHaveText(tabName('references'))
})
test('an Annotations section is an entry of its own: Back shows the drawing, Forward the section', async ({
test('an Annotations section is an entry: Back shows the drawing, Forward it', async ({
page,
}) => {
await open(page)
@@ -118,6 +120,49 @@ test.describe('editor browser history', () => {
await expect(selected(page)).toHaveText(tabName('annotations'))
})
test('« Retour au dessin » pops the section: Back leaves the drawing', async ({
page,
}) => {
await open(page)
await selectTab(page, dict, 'general')
await written(page, 'general')
await selectTab(page, dict, 'annotations')
await written(page, 'annotations')
await openSection(page, dict, 'views')
await sectionWritten(page, 'views')
await backToDrawing(page, dict)
await sectionWritten(page, 'drawing')
// no duplicate drawing entry: this Back lands on Général
await page.goBack()
await expect(selected(page)).toHaveText(tabName('general'))
})
test('the scroll offset of a view comes back with Back and Forward', async ({
page,
}) => {
await open(page)
await page.evaluate(() => {
const spacer = document.createElement('div')
spacer.style.height = '4000px'
document.body.append(spacer)
window.scrollTo(0, 600)
})
// The keyboard: a real click would scroll the tab row into view first, and a script
// event carries no user activation (Chromium skips such entries on Back).
await page
.getByRole('tab', { name: tabName('findings') })
.evaluate((tab) => tab.focus({ preventScroll: true }))
await page.keyboard.press('Enter')
await written(page, 'findings')
await page.evaluate(() => window.scrollTo(0, 200))
await page.goBack()
await expect(selected(page)).toHaveText(tabName('annotations'))
await page.waitForFunction(() => Math.abs(window.scrollY - 600) <= 2)
await page.goForward()
await expect(selected(page)).toHaveText(tabName('findings'))
await page.waitForFunction(() => Math.abs(window.scrollY - 200) <= 2)
})
test('a reload reopens the view of the entry', async ({ page }) => {
await open(page)
await selectTab(page, dict, 'findings')