diff --git a/e2e/error-detail.spec.ts b/e2e/error-detail.spec.ts index 6a2ef982..a362d196 100644 --- a/e2e/error-detail.spec.ts +++ b/e2e/error-detail.spec.ts @@ -336,6 +336,65 @@ test('移动端大图查看器关闭按钮在安全区内、锁定滚动、Esc expect((await page.request.delete(`/api/notebooks/${notebook.id}`)).ok()).toBeTruthy(); }); +test('手机竖屏动画进度条独占一行,浮层全屏预留安全区', async ({ page, scenario }) => { + test.setTimeout(90000); + await scenario.db.user.update({ where: { id: scenario.user.id }, data: { enableSvgAnimation: true } }); + const item = await scenario.db.errorItem.create({ + data: { + id: `item-${scenario.id}-svg`, + shortId: `${scenario.id.slice(0, 4)}SVG`, + userId: scenario.user.id, + subjectId: scenario.book.id, + originalImageUrl: '', + questionText: `动画讲解进度测试 ${scenario.marker}`, + answerText: '圆的半径随时间变化。', + analysis: '动画展示了半径的变化过程。', + svgAnimation: '', + }, + }); + await scenario.login(page); + await page.setViewportSize({ width: 375, height: 667 }); + await page.goto(`/error-items/${item.id}`); + await expect(page.locator('iframe[title="动画讲解"]')).toBeVisible({ timeout: 15000 }); + + // 375px 竖屏下进度条独占一行,宽度不再被 7 个控件挤到几十像素 + const ranges = page.locator('input[type="range"]'); + await expect(ranges).toHaveCount(2); + const mobileRange = ranges.first(); + await expect(mobileRange).toBeVisible(); + const rangeBox = await mobileRange.boundingBox(); + const playBox = await page.getByRole('button', { name: '播放', exact: true }).boundingBox(); + expect(rangeBox).not.toBeNull(); + expect(playBox).not.toBeNull(); + expect(rangeBox!.width).toBeGreaterThan(250); + expect(rangeBox!.y).toBeLessThan(playBox!.y); + + // 模拟不支持原生 Fullscreen 的手机浏览器,浮层全屏需落在视口内并预留安全区 + await page.evaluate(() => { + Object.defineProperty(Element.prototype, 'requestFullscreen', { value: undefined, configurable: true }); + }); + await page.getByRole('button', { name: '全屏', exact: true }).click(); + const container = page.getByTestId('svg-animation-player'); + await expect(container).toBeVisible(); + const containerBox = await container.boundingBox(); + expect(containerBox).not.toBeNull(); + expect(containerBox!.x).toBe(0); + expect(containerBox!.y).toBe(0); + expect(containerBox!.width).toBe(375); + expect(containerBox!.height).toBe(667); + const padding = await container.evaluate((element) => { + const style = getComputedStyle(element); + return { top: parseFloat(style.paddingTop), bottom: parseFloat(style.paddingBottom), left: parseFloat(style.paddingLeft), right: parseFloat(style.paddingRight) }; + }); + expect(padding.top).toBeGreaterThanOrEqual(16); + expect(padding.bottom).toBeGreaterThanOrEqual(16); + expect(padding.left).toBeGreaterThanOrEqual(16); + expect(padding.right).toBeGreaterThanOrEqual(16); + await expect(page.getByRole('button', { name: '退出全屏', exact: true })).toBeInViewport({ ratio: 1 }); + await page.keyboard.press('Escape'); + await expect(page.getByRole('button', { name: '退出全屏', exact: true })).toHaveCount(0); +}); + test('学生查看错题详情时答案与解析默认折叠,管理员视角展开', async ({ page }) => { test.setTimeout(60000); await login(page); diff --git a/src/__tests__/unit/svg-animation-player.test.tsx b/src/__tests__/unit/svg-animation-player.test.tsx index 238995f9..ad795c59 100644 --- a/src/__tests__/unit/svg-animation-player.test.tsx +++ b/src/__tests__/unit/svg-animation-player.test.tsx @@ -103,4 +103,18 @@ describe('SVG 动画必须手工播放', () => { expect(timeline.unpauseAnimations).toHaveBeenCalledOnce(); expect(cssAnimation.play).toHaveBeenCalledOnce(); }); + + it('窄屏进度行与桌面进度条共用同一时间轴', async () => { + await render(); + await load(); + const ranges = container.querySelectorAll('input[type="range"]'); + expect(ranges).toHaveLength(2); + expect(ranges[0].value).toBe('0'); + const setValue = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')!.set!; + await act(async () => { + setValue.call(ranges[0], '4'); + ranges[0].dispatchEvent(new Event('input', { bubbles: true })); + }); + expect(container.textContent).toContain('0:04 / 0:10'); + }); }); diff --git a/src/components/svg-animation-player.tsx b/src/components/svg-animation-player.tsx index 7b11e598..05e0d4c1 100644 --- a/src/components/svg-animation-player.tsx +++ b/src/components/svg-animation-player.tsx @@ -173,10 +173,12 @@ export function SvgAnimationPlayer({ svg, errorItemId }: SvgAnimationPlayerProps return (