Files
wrong-notebook/e2e/notebook-sharing.spec.ts
margrop 805dc62460 fix: 共享错题本只读成员在详情页隐藏全部写操作入口
- GET /api/error-items/[id] 返回当前角色与 canWrite,前端据此判定只读
- 只读成员隐藏删除、难度调整、修复 LaTeX、重生成答案/解析配图、编辑题干/答案/解析/笔记/标签/题目信息
- 隐藏配图比例与来源调整、小问编辑、SVG 动画生成/删除、GeoGebra 生成与编辑;保留查看、原图与举一反三
- 集成测试断言只读/可编辑角色的 API 返回;E2E 补充只读成员错题详情页写入口断言
2026-12-04 05:22:29 +08:00

127 lines
7.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { test, expect } from './support/fixtures';
import type { BrowserContext, Page } from '@playwright/test';
import { acceptConfirmDialog } from './helpers';
/**
* 错题本共享与权限流 E2E:
* 覆盖邀请、接受/拒绝、只读限制、权限升级(只读 → 可编辑)、成员移除,以及共享错题本参与原题组卷。
*/
test.describe('错题本共享与权限', () => {
test('[E2E-S01] 邀请只读成员 → 接受 → 只读限制 → 升级可编辑 → 移除成员', async ({ browser, page, scenario }) => {
const questionText = `共享错题测试题。${scenario.marker}`;
const item = await scenario.item('A', { questionText });
// 1. 所有者(学生 A)登录并进入错题本详情页,邀请学生 B(默认只读)
await scenario.login(page, false);
await page.goto(`/notebooks/${scenario.book.id}`);
await expect(page.getByText(questionText)).toBeVisible();
await page.locator('#share-email').fill(scenario.otherUser.email);
await page.locator('#share-role').selectOption('read');
await page.getByRole('button', { name: '邀请', exact: true }).click();
await expect(page.getByText('E2E 学生 B')).toBeVisible();
await expect(page.getByText('待接受')).toBeVisible();
// 2. 成员(学生 B)在独立浏览器上下文登录,在 /notebooks 看到邀请并接受
const memberContext: BrowserContext = await browser.newContext();
const memberPage: Page = await memberContext.newPage();
await scenario.guardPage(memberPage);
try {
await scenario.login(memberPage, true);
await memberPage.goto('/notebooks');
await expect(memberPage.getByText('共享邀请')).toBeVisible();
await expect(memberPage.getByText(/共享自 E2E 学生 A.*只读/)).toBeVisible();
await memberPage.getByRole('button', { name: '接受', exact: true }).click();
await expect(memberPage.getByText('共享邀请')).toHaveCount(0);
// 3. 成员进入共享错题本:能看到题目,但只读模式下没有「多选」「添加错题」按钮
await memberPage.goto(`/notebooks/${scenario.book.id}`);
await expect(memberPage.getByText(questionText)).toBeVisible();
await expect(memberPage.getByText('只读成员可以查看题目,但不能修改')).toBeVisible();
await expect(memberPage.getByRole('button', { name: '多选', exact: true })).toHaveCount(0);
await expect(memberPage.getByRole('button', { name: '添加错题' })).toHaveCount(0);
// 只读成员进入错题详情:可查看原图与练习,但没有删除、编辑、重生成等写入口
await memberPage.goto(`/error-items/${item.id}`);
await expect(memberPage.getByText(questionText)).toBeVisible();
await expect(memberPage.getByRole('button', { name: '删除', exact: true })).toHaveCount(0);
await expect(memberPage.getByRole('button', { name: /编辑/ })).toHaveCount(0);
await expect(memberPage.getByRole('button', { name: '重新生成完整解答' })).toHaveCount(0);
await expect(memberPage.getByRole('button', { name: '举一反三' })).toBeVisible();
await memberPage.goto(`/notebooks/${scenario.book.id}`);
// 4. 所有者刷新后看到成员已生效,将权限升级为「可编辑」
await page.reload();
await expect(page.getByText('已生效')).toBeVisible();
const memberRow = page.locator('div', { hasText: 'E2E 学生 B' }).filter({ has: page.getByRole('button', { name: '移除' }) }).last();
await memberRow.getByLabel('权限').selectOption('edit');
// 5. 成员刷新后获得编辑权限:可见「多选」和「添加错题」
await memberPage.reload();
await expect(memberPage.getByRole('button', { name: '多选', exact: true })).toBeVisible();
await expect(memberPage.getByRole('button', { name: '添加错题' })).toBeVisible();
// 6. 所有者移除成员,成员失去访问权限
await memberRow.getByRole('button', { name: '移除' }).click();
await acceptConfirmDialog(page);
await expect(page.getByText('还没有共享成员')).toBeVisible();
await memberPage.goto('/notebooks');
await expect(memberPage.getByText('共享自 E2E 学生 A')).toHaveCount(0);
} finally {
await memberContext.close();
}
});
test('[E2E-S02] 拒绝邀请不生效;接受共享后可用共享错题本原题组卷', async ({ browser, page, scenario }) => {
await scenario.item('A', { questionText: `共享组卷题一。${scenario.marker}` });
await scenario.item('B', { questionText: `共享组卷题二。${scenario.marker}` });
// 所有者邀请学生 B
await scenario.login(page, false);
await page.goto(`/notebooks/${scenario.book.id}`);
await page.locator('#share-email').fill(scenario.otherUser.email);
await page.getByRole('button', { name: '邀请', exact: true }).click();
await expect(page.getByText('待接受')).toBeVisible();
const memberContext: BrowserContext = await browser.newContext();
const memberPage: Page = await memberContext.newPage();
await scenario.guardPage(memberPage);
try {
await scenario.login(memberPage, true);
await memberPage.goto('/notebooks');
await expect(memberPage.getByText('共享邀请')).toBeVisible();
// 先拒绝邀请
await memberPage.getByRole('button', { name: '拒绝', exact: true }).click();
await expect(memberPage.getByText('共享邀请')).toHaveCount(0);
await expect(memberPage.getByText('共享自 E2E 学生 A')).toHaveCount(0);
// 所有者重新邀请,成员接受
await page.reload();
await page.locator('#share-email').fill(scenario.otherUser.email);
await page.getByRole('button', { name: '邀请', exact: true }).click();
await expect(page.getByText('待接受')).toBeVisible();
await memberPage.reload();
await memberPage.getByRole('button', { name: '接受', exact: true }).click();
await expect(memberPage.getByText('共享邀请')).toHaveCount(0);
// 成员在 /exams 使用共享错题本创建原题试卷(含 2 题的共享数学本)
await memberPage.goto('/exams');
await memberPage.getByRole('checkbox', { name: '数学 2' }).check();
await memberPage.getByRole('button', { name: '原题', exact: true }).click();
await memberPage.locator('#exam-count').fill('2');
await memberPage.getByRole('button', { name: '创建原题试卷', exact: true }).click();
await memberPage.waitForURL(/\/exams\/[^/]+$/);
const paperId = new URL(memberPage.url()).pathname.split('/').pop()!;
const questions = await scenario.db.examQuestion.findMany({ where: { paperId } });
expect(questions).toHaveLength(2);
} finally {
await memberContext.close();
}
});
});