import { expect, test } from '@playwright/test'; import { createDepartmentByApi, createReportByApi, createUserByApi, loginByApi, uniqueId, } from './helpers'; test('admin only sees department reports, doctor only sees own reports, super sees all', async ({ page }) => { const suffix = uniqueId('perm'); const ownTitle = `外科本人报告 ${suffix}`; const otherSurgeryTitle = `外科他人报告 ${suffix}`; const internalTitle = `内科报告 ${suffix}`; await loginByApi(page, 'admin'); const internalDepartment = await createDepartmentByApi(page.request, `内科E2E ${suffix}`, `internal_${suffix}`); const internalAdmin = await createUserByApi(page.request, { username: `internal_admin_${suffix}`, name: '内科E2E管理员', role: 'admin', departmentId: internalDepartment.id, }); const otherSurgeryDoctor = await createUserByApi(page.request, { username: `surgery_doctor_${suffix}`, name: '外科E2E医生', role: 'user', department: '外科', }); await loginByApi(page, '0001'); await createReportByApi(page.request, { title: ownTitle, content: `
${ownTitle}
` }); await loginByApi(page, otherSurgeryDoctor.username); await createReportByApi(page.request, { title: otherSurgeryTitle, content: `${otherSurgeryTitle}
` }); await loginByApi(page, internalAdmin.username); await createReportByApi(page.request, { title: internalTitle, content: `${internalTitle}
` }); await loginByApi(page, 'manager'); await page.goto('/report-manage'); await expect(page.getByText(ownTitle)).toBeVisible(); await expect(page.getByText(otherSurgeryTitle)).toBeVisible(); await expect(page.getByText(internalTitle)).not.toBeVisible(); await loginByApi(page, '0001'); await page.goto('/report-manage'); await expect(page.getByText(ownTitle)).toBeVisible(); await expect(page.getByText(otherSurgeryTitle)).not.toBeVisible(); await expect(page.getByText(internalTitle)).not.toBeVisible(); await loginByApi(page, 'admin'); await page.goto('/report-manage'); await expect(page.getByText(ownTitle)).toBeVisible(); await expect(page.getByText(otherSurgeryTitle)).toBeVisible(); await expect(page.getByText(internalTitle)).toBeVisible(); });