style: 全站接入深色主题,按新规则整改界面取值

This commit is contained in:
2026-11-20 09:42:47 +08:00
parent 15d84decfb
commit 7627f0651d
32 changed files with 960 additions and 267 deletions
+49 -5
View File
@@ -37,6 +37,9 @@ const mockApiResponse = (code = 200, data: any = null, message = '请求成功')
test.describe('StartTask - 暂停后继续', () => {
test.beforeEach(async ({ page }) => {
// Match business endpoints only, never Vite's /src/api/*.ts modules.
await page.route(url => url.pathname.startsWith('/api/'), route => route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(mockApiResponse()) }));
await page.route('**/api/study-sessions/SESSION_001', route => route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(mockSessionPaused) }));
// mock 音频权限(阻止 audio.play() 弹窗阻塞会话加载)
await page.addInitScript(() => {
HTMLAudioElement.prototype.play = () => Promise.resolve();
@@ -83,6 +86,26 @@ test.describe('StartTask - 暂停后继续', () => {
);
});
test('记录知识碎片一次保存,结束总结前暂停,取消恢复原进行中状态', async ({ page }) => {
const calls: string[] = [];
await page.route('**/api/report-fragments', route => { calls.push('record'); return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(mockApiResponse()) }); });
await page.route('**/api/study-sessions/SESSION_001/study-sessions/pause', route => { calls.push('pause'); return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(mockApiResponse()) }); });
await page.route('**/api/study-sessions/SESSION_001/study-sessions/continue', route => { calls.push('continue'); return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(mockApiResponse()) }); });
await page.goto('/start-task/T001');
await expect(page.locator('.task-info-bar')).toContainText('学习 Vue3');
await page.getByRole('button', { name: '记录知识碎片', exact: true }).click();
await page.getByRole('dialog').locator('textarea').fill('整体提交或回滚');
await page.getByRole('button', { name: '保存记录', exact: true }).click();
await expect.poll(() => calls.filter(call => call === 'record').length).toBe(1);
await expect(page.getByRole('dialog')).toHaveCount(0);
await page.getByRole('button', { name: '结束会话', exact: true }).click();
await expect(page.getByRole('dialog', { name: '结束会话总结' })).toBeVisible();
expect(calls).toContain('pause');
await expect(page.locator('.status-text')).toContainText('已暂停');
await page.getByRole('button', { name: '取消并继续学习' }).click();
await expect.poll(() => calls.includes('continue')).toBe(true);
});
test('暂停后点击开始,应触发 continue API', async ({ page }) => {
// 记录 API 调用
const apiCalls: string[] = [];
@@ -194,15 +217,36 @@ test.describe('StartTask - 暂停后继续', () => {
await page.getByRole('button', { name: '结束会话' }).click();
// 在弹窗中输入总结内容
await page.locator('.el-dialog textarea').fill('测试总结');
await page.getByRole('dialog').locator('textarea').first().fill('测试总结');
await page.getByRole('dialog').getByRole('button', { name: '确认结束' }).click();
// 确认第二个弹窗("确定要结束本次学习会话吗?")
const confirmBtn = page.getByRole('dialog').getByRole('button', { name: '确定' });
await confirmBtn.waitFor({ timeout: 5000 });
await confirmBtn.click();
await expect(page.getByText('确定要结束本次学习会话吗?')).toHaveCount(0);
// 应看到 warning 提示(有效时间不足)
await expect(page.locator('.el-message--warning')).toBeVisible({ timeout: 5000 });
});
test('旧标准图原生编辑Enter后可连续Tab/Enter新增并以原outline契约保存', async ({ page }) => {
let savedOutline = '';
await page.route('**/api/review/standard-mind-map/T001', async route => {
if (route.request().method() === 'PUT') savedOutline = (route.request().postDataJSON() as { outline: string }).outline;
await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(mockApiResponse(200, null)) });
});
await page.goto('/start-task/T001');
await expect(page.locator('.task-info-bar')).toContainText('学习 Vue3');
const card = page.locator('.mindmap-card');
await card.getByRole('button', { name: '新建导图', exact: true }).click();
await card.locator('me-root > me-tpc').click();
await card.locator('.map-container').press('F2');
await card.locator('#input-box').fill('标准根修改'); await card.locator('#input-box').press('Enter');
await expect(card.locator('me-tpc.selected')).toHaveCount(1);
await card.locator('.map-container').press('Tab'); await expect(card.locator('#input-box')).toHaveText('New Node');
await card.locator('#input-box').fill('第一个子节点'); await card.locator('#input-box').press('Enter');
await card.locator('.map-container').press('Enter');
await card.locator('#input-box').fill('第二个子节点'); await card.locator('#input-box').press('Enter');
await card.locator('.map-container').press('Tab');
await card.locator('#input-box').fill('下一级'); await card.locator('#input-box').press('Enter');
await card.getByRole('button', { name: '保存', exact: true }).click();
await expect.poll(() => savedOutline).toBe('标准根修改\n - 第一个子节点\n - 第二个子节点\n - 下一级');
});
});
+1 -1
View File
@@ -79,7 +79,7 @@ test.describe('Task form', () => {
await expect(page.getByRole('button', { name: '更新', exact: true })).toBeVisible();
await page.getByPlaceholder('例如:Vue3 组件通信实践').fill('更新后的任务');
await page.getByRole('button', { name: '添加', exact: true }).click();
await page.getByRole('button', { name: '更新', exact: true }).click();
await expect(page).toHaveURL(/\/study/, { timeout: 10_000 });
});
+38
View File
@@ -0,0 +1,38 @@
import { test, expect } from '@playwright/test';
test.describe('深色模式', () => {
test('没有手动选择时跟随系统', async ({ page }) => {
await page.emulateMedia({ colorScheme: 'dark' });
await page.goto('/login');
await expect(page.locator('html')).toHaveClass(/dark/);
const solid = await page.getByRole('button', { name: '进入系统' }).evaluate((node) => {
const style = getComputedStyle(node);
return { background: style.backgroundColor, color: style.color };
});
expect(solid.background).toBe('rgb(127, 216, 180)');
expect(solid.color).toBe('rgb(17, 26, 22)');
await page.emulateMedia({ colorScheme: 'light' });
await expect(page.locator('html')).not.toHaveClass(/dark/);
});
test('手动切换覆盖系统并在刷新后保持', async ({ page }) => {
await page.emulateMedia({ colorScheme: 'dark' });
await page.goto('/login');
await expect(page.locator('html')).toHaveClass(/dark/);
await page.getByRole('button', { name: '切到浅色' }).click();
await expect(page.locator('html')).not.toHaveClass(/dark/);
expect(await page.evaluate(() => localStorage.getItem('theme'))).toBe('light');
await page.reload();
await expect(page.locator('html')).not.toHaveClass(/dark/);
await expect(page.getByRole('button', { name: '切到深色' })).toBeVisible();
});
test('手动选择后不再跟随系统变化', async ({ page }) => {
await page.emulateMedia({ colorScheme: 'light' });
await page.goto('/login');
await page.getByRole('button', { name: '切到深色' }).click();
await expect(page.locator('html')).toHaveClass(/dark/);
await page.emulateMedia({ colorScheme: 'light' });
await expect(page.locator('html')).toHaveClass(/dark/);
});
});
+1 -1
View File
@@ -39,7 +39,7 @@ test.describe('Welcome page', () => {
taskNum: `T${i + 1}`,
taskName: `任务 ${i + 1}`,
sourceType: 'FRAGMENT',
content: `第 ${i + 1} 条学习残片内容,用来撑起首页滚动区域。`,
content: `第 ${i + 1} 条知识碎片内容,用来撑起首页滚动区域。`,
createdTime: `2026-08-01 10:00:${String(i).padStart(2, '0')}`,
}));