Skip to content

Commit 94fe5d9

Browse files
committed
test: 更新跨账号合并导入 E2E
Refs: #10
1 parent 52b9891 commit 94fe5d9

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

‎e2e/data-backup.spec.ts‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { openSettings } from './support/flows';
55
import { FIGURE } from './support/mock-ai.mjs';
66
import { acceptConfirmDialog } from './helpers';
77

8-
test('[E2E-M07] 拒绝跨邮箱导入并在同邮箱空账号恢复备份', async ({ page, browser, scenario }) => {
8+
test('[E2E-M07] 其他账号备份合并到当前账号并在同邮箱空账号恢复备份', async ({ page, browser, scenario }) => {
99
const secondBook = await scenario.db.subject.create({ data: { name: '第二套体系', userId: scenario.user.id, stage: 'junior_high', subjectKey: 'math', tagSet: 'e2e-secondary' } });
1010
const leafIds: string[] = [];
1111
for (const [index, tagSet] of ['default', 'e2e-secondary'].entries()) {
@@ -43,20 +43,22 @@ test('[E2E-M07] 拒绝跨邮箱导入并在同邮箱空账号恢复备份', asyn
4343
await scenario.login(foreign, true);
4444
await foreign.goto('/');
4545
const settings = await openSettings(foreign, '危险');
46-
// 新账号可自动初始化默认空本和默认卷别,核对导入前后集合完全相同。
46+
// 新账号可自动初始化默认空本和默认卷别,再导入其他账号的备份。
4747
expect((await foreign.request.get('/api/notebooks')).ok()).toBeTruthy();
4848
expect((await foreign.request.get('/api/paper-groups')).ok()).toBeTruthy();
49-
const booksBefore = await scenario.db.subject.findMany({ where: { userId: scenario.otherUser.id }, orderBy: { id: 'asc' } });
50-
const groupsBefore = await scenario.db.paperGroup.findMany({ where: { userId: scenario.otherUser.id }, orderBy: { id: 'asc' } });
5149
await settings.locator('input[type="file"]').setInputFiles(file);
5250
await settings.getByRole('button', { name: '导入数据', exact: true }).click();
53-
const rejected = foreign.waitForResponse((response) => response.url().endsWith('/api/import') && response.request().method() === 'POST');
51+
const merged = foreign.waitForResponse((response) => response.url().includes('/api/import') && response.request().method() === 'POST');
52+
// 导入成功后页面会自动刷新,等待本次刷新完成再关闭页面。
53+
const foreignReloaded = foreign.waitForEvent('load');
5454
await acceptConfirmDialog(foreign);
55-
expect((await rejected).status()).toBe(400);
56-
expect(await scenario.db.errorItem.count({ where: { userId: scenario.otherUser.id } })).toBe(0);
57-
expect(await scenario.db.subject.findMany({ where: { userId: scenario.otherUser.id }, orderBy: { id: 'asc' } })).toEqual(booksBefore);
58-
expect(await scenario.db.practiceRecord.count({ where: { userId: scenario.otherUser.id } })).toBe(0);
59-
expect(await scenario.db.paperGroup.findMany({ where: { userId: scenario.otherUser.id }, orderBy: { id: 'asc' } })).toEqual(groupsBefore);
55+
expect((await merged).ok()).toBeTruthy();
56+
await foreignReloaded;
57+
const mergedItems = await scenario.db.errorItem.findMany({ where: { userId: scenario.otherUser.id } });
58+
expect(mergedItems).toHaveLength(2);
59+
expect(mergedItems.every((item) => item.subjectId !== null)).toBe(true);
60+
expect(await scenario.db.subject.count({ where: { userId: scenario.otherUser.id, name: '第二套体系' } })).toBe(1);
61+
expect(await scenario.db.practiceRecord.count({ where: { userId: scenario.otherUser.id } })).toBe(1);
6062
expect(await scenario.db.errorItem.count({ where: { userId: scenario.user.id } })).toBe(2);
6163
} finally { await foreign.close(); }
6264
// 仅在本次临时库重建同邮箱账号,模拟新设备上的空账号,保留身份校验。
@@ -67,7 +69,7 @@ test('[E2E-M07] 拒绝跨邮箱导入并在同邮箱空账号恢复备份', asyn
6769
const settings = await openSettings(receiver, '危险');
6870
await settings.locator('input[type="file"]').setInputFiles(file);
6971
await settings.getByRole('button', { name: '导入数据', exact: true }).click();
70-
const imported = receiver.waitForResponse((response) => response.url().endsWith('/api/import') && response.request().method() === 'POST');
72+
const imported = receiver.waitForResponse((response) => response.url().includes('/api/import') && response.request().method() === 'POST');
7173
// 导入成功后页面会自动刷新,等待本次刷新完成再进行后续导航。
7274
const reloaded = receiver.waitForEvent('load');
7375
await acceptConfirmDialog(receiver);

0 commit comments

Comments
 (0)