diff --git a/e2e/work-companion.playwright.ts b/e2e/work-companion.playwright.ts index 5898250..d3e7211 100644 --- a/e2e/work-companion.playwright.ts +++ b/e2e/work-companion.playwright.ts @@ -125,6 +125,41 @@ test('keeps one expanded ordinary summary when the desktop work pane opens', asy expect(state.errors).toEqual([]) }) +test('preserves the selected material, physical scroll and focus when background work finishes', async ({ page }) => { + await page.setViewportSize({ width: 1440, height: 960 }) + const tabbed = work('work1', 'active', { body: [...progress.body!, { + type: 'tabs', id: 'materials', tabs: { tabs: [ + { id: 'first', label: '第一份材料', nodes: [{ type: 'markdown', markdown: '第一份材料的范围' }] }, + { id: 'second', label: '第二份材料', nodes: [{ type: 'markdown', markdown: Array.from({ length: 70 }, (_, i) => `待核对事项 ${i + 1}`).join('\n\n') }] }, + ] }, + }] }) + const state = await fixture(page, [tabbed, work('peer', 'active', { body: [] })]) + await page.getByRole('button', { name: '打开工作', exact: true }).click() + const card = page.locator('.right-panel [data-card-id="work1"]') + await card.getByRole('button', { name: '查看依据与范围', exact: true }).click() + const tab = card.getByRole('tab', { name: '第二份材料', exact: true }) + await tab.click() + await tab.focus() + const details = card.locator('.acard-detail-body') + await expect.poll(() => details.evaluate(element => element.clientHeight)).toBe(420) + const physical = await details.evaluate(element => { + Object.assign(window, { __workReading: element }) + element.scrollTop = 137 + return { height: element.clientHeight, scrollHeight: element.scrollHeight, top: element.scrollTop } + }) + expect(physical.scrollHeight).toBeGreaterThan(physical.height) + expect(physical.top).toBe(137) + await state.emit('card.status', { cardId: 'work1', status: 'done' }, 12) + await expect(card.locator('.acard-status')).toHaveText('已完成') + await expect(tab).toHaveAttribute('aria-selected', 'true') + expect(await details.evaluate(element => ({ + retained: (window as typeof window & { __workReading: Element }).__workReading === element, + top: element.scrollTop, + }))).toEqual({ retained: true, top: 137 }) + expect(await tab.evaluate(element => document.activeElement === element)).toBe(true) + expect(state.errors).toEqual([]) +}) + test('shares submitting feedback between conversation and work confirmations', async ({ page }) => { const state = await fixture(page, [confirmation]) await page.getByRole('button', { name: '打开工作', exact: true }).click()