| @@ -131,7 +131,16 @@ class SystemConfigurationMock { | |||
| headers: { 'Content-Type': 'text/html; charset=utf-8' }, | |||
| body: `<!doctype html><html><body style="margin:0;background:transparent"> | |||
| <button style="width:188px;height:56px">问数字教员</button> | |||
| <script>parent.postMessage({source:'virtual-instructor-widget',type:'resize',width:208,height:92}, '*')</script> | |||
| <script> | |||
| addEventListener('message', function (event) { | |||
| var data = event.data || {}; | |||
| if (data.source !== 'virtual-instructor-widget-host' || data.type !== 'theme') return; | |||
| document.body.dataset.hostTheme = data.theme && data.theme.scheme; | |||
| document.body.dataset.hostAccent = data.theme && data.theme.accent; | |||
| }); | |||
| parent.postMessage({source:'virtual-instructor-widget',type:'ready',protocolVersion:2,capabilities:['resize','drag','theme']}, '*'); | |||
| parent.postMessage({source:'virtual-instructor-widget',type:'resize',width:208,height:92}, '*'); | |||
| </script> | |||
| </body></html>`, | |||
| })) | |||
| } | |||
| @@ -394,7 +403,26 @@ test.describe('系统配置(状态化 Mock,不访问真实 API/数据库)' | |||
| await page.getByTestId('system-config-save-widget').click() | |||
| await expect(page.getByTestId('system-config-widget-drawer')).toBeHidden() | |||
| await expect(page.getByTestId('system-config-digital-human-widget-card')).toContainText('已接入数字教员') | |||
| await expect(page.getByTestId('global-digital-human-widget')).toHaveAttribute('src', /human\.example\.test\/embed\/dh-global-demo/) | |||
| const globalWidget = page.getByTestId('global-digital-human-widget') | |||
| await expect(globalWidget).toHaveAttribute('src', /human\.example\.test\/embed\/dh-global-demo/) | |||
| const globalWidgetBody = page.frameLocator('[data-testid="global-digital-human-widget"]').locator('body') | |||
| await expect(globalWidgetBody).toHaveAttribute('data-host-theme', 'light') | |||
| await expect(globalWidgetBody).toHaveAttribute('data-host-accent', '#197fc8') | |||
| const widgetBeforeDrag = await globalWidget.boundingBox() | |||
| const widgetHandle = await globalWidget.elementHandle() | |||
| const widgetContent = await widgetHandle?.contentFrame() | |||
| expect(widgetBeforeDrag).not.toBeNull() | |||
| expect(widgetContent).not.toBeNull() | |||
| await widgetContent!.evaluate(() => { | |||
| parent.postMessage({ source: 'virtual-instructor-widget', type: 'drag-start', handle: 'launcher' }, '*') | |||
| parent.postMessage({ source: 'virtual-instructor-widget', type: 'drag-move', handle: 'launcher', deltaX: -180, deltaY: -120 }, '*') | |||
| parent.postMessage({ source: 'virtual-instructor-widget', type: 'drag-end', handle: 'launcher' }, '*') | |||
| }) | |||
| await expect.poll(async () => (await globalWidget.boundingBox())?.x).toBeLessThan(widgetBeforeDrag!.x - 100) | |||
| const storedWidgetPosition = await page.evaluate(() => Object.entries(localStorage) | |||
| .find(([key]) => key.startsWith('unreal-tran:web:digital-human-widget-position:v1:'))?.[1] ?? '') | |||
| expect(storedWidgetPosition).toContain('offsetX') | |||
| await page.getByTestId('system-config-remove-widget').click() | |||
| await page.locator('.el-message-box:visible').getByRole('button', { name: '确认移除' }).click() | |||