Files
Academic-Affairs-System/web/e2e/approval-center.spec.ts
T

224 lines
16 KiB
TypeScript

import { expect, test } from '@playwright/test'
test.use({ serviceWorkers: 'block' })
test('pending items warn when holiday data is missing', async ({ page }) => {
const user = { id: 'reviewer', userName: 'reviewer', displayName: '审核员', roles: ['AcademicAdmin'], permissions: [], effectiveDataScope: 'All' }
await page.addInitScript(savedUser => {
localStorage.setItem('jiaowu_token', 'test-token')
localStorage.setItem('jiaowu_user', JSON.stringify(savedUser))
localStorage.setItem('jiaowu_access_expires_at', '2099-01-01T00:00:00Z')
localStorage.setItem('jiaowu_session_expires_at', '2099-01-01T00:00:00Z')
}, user)
await page.route(url => url.pathname.startsWith('/api/'), async route => {
const path = new URL(route.request().url()).pathname
if (path === '/api/approvals/pending') return route.fulfill({ json: { items: [{ id: 'item-1', type: 'CourseExemption', title: '测试申请', desc: '申请事由', time: '2026-12-31T08:00:00Z', deadlineUtc: '2027-01-01T04:00:00Z', missingHolidayYears: [2026, 2027], college: '学院' }], total: 1, page: 1, pageSize: 20, counts: { CourseExemption: 1 }, timelinessEnabled: true } })
if (path === '/api/auth/me') return route.fulfill({ json: user })
if (path === '/api/approvals/reviewed') return route.fulfill({ json: { items: [], total: 0 } })
if (path === '/api/student-leaves/pending' || path === '/api/plugins/runtime' || path === '/api/approvals/grade-records') return route.fulfill({ json: [] })
return route.fulfill({ json: {} })
})
await page.goto('/approvals?tab=pending')
const card = page.locator('.appr-card').filter({ hasText: '测试申请' })
await expect(card.getByText('未发现 2026, 2027 年的已启用节假日同步数据,处理目标可能不准确,请联系管理员核查校历。')).toBeVisible()
await expect(card.getByText(/北京时间/)).toBeVisible()
})
test('a teacher can open a specific attendance appeal and return to all pending items', async ({ page }) => {
const user = { id: 'teacher', userName: 'teacher', displayName: '教师', roles: ['Teacher'], permissions: [], effectiveDataScope: 'Self' }
await page.addInitScript(savedUser => {
localStorage.setItem('jiaowu_token', 'test-token')
localStorage.setItem('jiaowu_user', JSON.stringify(savedUser))
localStorage.setItem('jiaowu_access_expires_at', '2099-01-01T00:00:00Z')
localStorage.setItem('jiaowu_session_expires_at', '2099-01-01T00:00:00Z')
}, user)
await page.route(url => url.pathname.startsWith('/api/'), async route => {
const url = new URL(route.request().url())
if (url.pathname === '/api/approvals/pending/AttendanceAppeal/student-1') {
expect(url.searchParams.get('secondaryId')).toBe('sheet-1')
return route.fulfill({ json: { id: 'student-1', secondaryId: 'sheet-1', type: 'AttendanceAppeal', title: '指定的申诉', desc: '理由', time: '2026-11-01T00:00:00Z', college: '学院' } })
}
if (url.pathname === '/api/approvals/pending') return route.fulfill({ json: { items: [], total: 0, counts: {} } })
if (url.pathname === '/api/approvals/reviewed') return route.fulfill({ json: { items: [], total: 0 } })
if (url.pathname === '/api/approvals/grade-records' || url.pathname === '/api/plugins/runtime') return route.fulfill({ json: [] })
if (url.pathname === '/api/auth/me') return route.fulfill({ json: user })
return route.fulfill({ json: {} })
})
await page.goto('/approvals?tab=pending&type=AttendanceAppeal&id=student-1&secondaryId=sheet-1')
await expect(page.getByText('指定的申诉')).toBeVisible()
await page.getByRole('button', { name: '查看全部待办' }).click()
await expect(page.getByText('指定的申诉')).toHaveCount(0)
await expect(page).toHaveURL(/\/approvals\?tab=pending$/)
})
test('an unavailable notification target offers a way back to all pending items', async ({ page }) => {
const user = { id: 'reviewer', userName: 'reviewer', displayName: '审核员', roles: ['CollegeAdmin'], permissions: [], effectiveDataScope: 'College' }
await page.addInitScript(savedUser => {
localStorage.setItem('jiaowu_token', 'test-token')
localStorage.setItem('jiaowu_user', JSON.stringify(savedUser))
localStorage.setItem('jiaowu_access_expires_at', '2099-01-01T00:00:00Z')
localStorage.setItem('jiaowu_session_expires_at', '2099-01-01T00:00:00Z')
}, user)
await page.route(url => url.pathname.startsWith('/api/'), async route => {
const path = new URL(route.request().url()).pathname
if (path.startsWith('/api/approvals/pending/ClassroomReservation/')) return route.fulfill({ status: 404 })
if (path === '/api/approvals/pending') return route.fulfill({ json: { items: [], total: 0, counts: {} } })
if (path === '/api/approvals/reviewed') return route.fulfill({ json: { items: [], total: 0 } })
if (path === '/api/student-leaves/pending' || path === '/api/plugins/runtime') return route.fulfill({ json: [] })
if (path === '/api/auth/me') return route.fulfill({ json: user })
return route.fulfill({ json: {} })
})
await page.goto('/approvals?tab=pending&type=ClassroomReservation&id=old-item')
await expect(page.getByText('该事项已处理、不存在或当前账号无权处理。')).toBeVisible()
await page.getByRole('button', { name: '查看全部待办' }).click()
await expect(page).toHaveURL(/\/approvals\?tab=pending$/)
})
const cases: { type: string; stage: string | null; secondaryId?: string; endpoint: string; body: Record<string, unknown> | null; reject?: boolean; progress?: boolean }[] = [
{ type: 'AttendanceAppeal', stage: null, secondaryId: 'sheet-1', endpoint: '/api/attendance/appeals/sheet-1/item-1/review', body: { approve: true, comment: null } },
{ type: 'StudentStatusChange', stage: 'final', endpoint: '/api/student-status-changes/item-1/review', body: { approved: true, comment: null }, progress: true },
{ type: 'StudentStatusChange', stage: 'receivingCollege', endpoint: '/api/student-status-changes/item-1/receiving-college-review', body: { approved: true, comment: null }, progress: true },
{ type: 'AssessmentDeclaration', stage: 'counselor', endpoint: '/api/comprehensive-assessments/declarations/item-1/review', body: { approved: true, comment: null }, progress: true },
{ type: 'TeacherCourseApplication', stage: null, endpoint: '/api/teacher-course-applications/item-1/review', body: { status: 'Approved', reviewComment: null }, progress: true },
{ type: 'ClassroomReservation', stage: null, endpoint: '/api/classroom-reservations/item-1/approve', body: { comment: null }, progress: true },
{ type: 'CampusRegistration', stage: null, endpoint: '/api/campus-registrations/applications/item-1/review', body: { approved: true, comment: null } },
{ type: 'DormitoryApplication', stage: 'counselor', endpoint: '/api/dormitory-services/applications/item-1/counselor-review', body: { approved: true, comment: null }, progress: true },
{ type: 'AttendanceAppeal', stage: null, secondaryId: 'sheet-1', endpoint: '/api/attendance/appeals/sheet-1/item-1/review', body: { approve: false, comment: '理由不充分' }, reject: true },
{ type: 'TeacherCourseApplication', stage: null, endpoint: '/api/teacher-course-applications/item-1/review', body: { status: 'Rejected', reviewComment: '理由不充分' }, reject: true },
{ type: 'CourseExemption', stage: null, endpoint: '/api/approvals/exemptions/item-1/approve', body: { comment: '' }, progress: true },
{ type: 'CourseAdjustment', stage: null, endpoint: '/api/course-adjustments/item-1/approve', body: null, progress: true },
]
for (const scenario of cases) test(`${scenario.type} ${scenario.stage ?? 'review'} can be ${scenario.reject ? 'rejected' : 'approved'} from the approval center`, async ({ page }) => {
if (scenario.type === 'StudentStatusChange') await page.setViewportSize({ width: 360, height: 800 })
const pageErrors: string[] = []
page.on('pageerror', error => pageErrors.push(error.message))
const roles = scenario.type === 'AssessmentDeclaration' ? ['Counselor'] : scenario.stage === 'receivingCollege' ? ['CollegeAdmin'] : ['AcademicAdmin']
const user = { id: 'reviewer', userName: 'reviewer', displayName: '审核员', roles, permissions: [], effectiveDataScope: 'All' }
await page.addInitScript((savedUser) => {
localStorage.setItem('jiaowu_token', 'test-token')
localStorage.setItem('jiaowu_user', JSON.stringify(savedUser))
localStorage.setItem('jiaowu_access_expires_at', '2099-01-01T00:00:00Z')
localStorage.setItem('jiaowu_session_expires_at', '2099-01-01T00:00:00Z')
}, user)
let reviewed = false
let overdueRequested = false
await page.route(url => url.pathname.startsWith('/api/'), async route => {
const url = new URL(route.request().url())
if (url.pathname === '/api/approvals/reviewed') return route.fulfill({ json: { items: [], total: 0 } })
if (url.pathname === '/api/student-leaves/pending') return route.fulfill({ json: [] })
if (url.pathname === '/api/approvals/pending') {
if (url.searchParams.has('overdueHours')) {
expect(url.searchParams.get('overdueHours')).toBe('72')
overdueRequested = true
}
const items = reviewed ? [] : [{ id: 'item-1', secondaryId: scenario.secondaryId, type: scenario.type, stage: scenario.stage, label: '申请', title: '学生 — 《课程》', desc: '申请事由', time: '2026-11-01T00:00:00Z', college: '学院' }]
return route.fulfill({ json: { items, total: items.length, page: 1, pageSize: 20, counts: reviewed ? {} : { [scenario.type]: 1 } } })
}
if (url.pathname === scenario.endpoint) {
expect(route.request().method()).toBe('POST')
expect(route.request().postDataJSON()).toEqual(scenario.body)
reviewed = true
return route.fulfill({ status: 204 })
}
if (url.pathname === `/api/approvals/progress/${scenario.type}/item-1`)
return route.fulfill({ json: { type: scenario.type, id: 'item-1', historyIncomplete: scenario.type === 'StudentStatusChange', steps: [{ kind: scenario.type === 'TeacherCourseApplication' ? 'started' : 'submitted', time: '2026-11-01T00:00:00Z', comment: null }] } })
if (url.pathname === '/api/auth/me') return route.fulfill({ json: user })
if (url.pathname === '/api/plugins/runtime') return route.fulfill({ json: [] })
return route.fulfill({ json: {} })
})
await page.goto('/approvals')
const card = page.locator('.appr-card').filter({ hasText: '申请事由' })
await expect(card).toBeVisible()
if (scenario.type === 'StudentStatusChange') {
const cardBox = await card.boundingBox()
expect(cardBox).not.toBeNull()
for (const button of await card.locator('.appr-actions button').all()) {
const box = await button.boundingBox()
expect(box).not.toBeNull()
expect(box!.x + box!.width).toBeLessThanOrEqual(cardBox!.x + cardBox!.width + 1)
}
}
if (scenario.type === 'AttendanceAppeal' && !scenario.reject) {
await page.locator('.approval-overdue-filter .el-switch').click()
await expect.poll(() => overdueRequested).toBe(true)
await expect(page.getByText('按每条事项显示的时间计算,阈值保存在当前浏览器。')).toBeVisible()
}
if (scenario.progress) {
await card.getByRole('button', { name: '办理进度' }).click()
const dialog = page.getByRole('dialog')
await expect(dialog.getByText(scenario.type === 'TeacherCourseApplication' ? '本次申报开始' : '已提交')).toBeVisible()
if (scenario.type === 'StudentStatusChange') await expect(dialog.getByText('该申请部分办理详情未留存。')).toBeVisible()
await dialog.locator('.el-dialog__headerbtn').click()
await expect(dialog).toBeHidden()
}
if (scenario.reject) {
await card.getByRole('button', { name: '驳回' }).click()
const dialog = page.getByRole('dialog')
await dialog.locator('textarea').fill('理由不充分')
await dialog.getByRole('button', { name: '确认驳回' }).click()
} else {
await card.getByRole('button', { name: '通过' }).click()
if (scenario.type === 'CourseExemption') await page.getByRole('dialog').getByRole('button', { name: '通过', exact: true }).click()
}
await expect(card).toHaveCount(0)
expect(reviewed).toBe(true)
expect(pageErrors).toEqual([])
})
test('a student can open status change progress from a link', async ({ page }) => {
const user = { id: 'student', userName: 'student', displayName: '学生', roles: ['Student'], permissions: [], effectiveDataScope: 'Self' }
await page.addInitScript((savedUser) => {
localStorage.setItem('jiaowu_token', 'test-token')
localStorage.setItem('jiaowu_user', JSON.stringify(savedUser))
localStorage.setItem('jiaowu_access_expires_at', '2099-01-01T00:00:00Z')
localStorage.setItem('jiaowu_session_expires_at', '2099-01-01T00:00:00Z')
}, user)
await page.route(url => url.pathname.startsWith('/api/'), async route => {
const path = new URL(route.request().url()).pathname
if (path === '/api/approvals/progress/StudentStatusChange/item-1')
return route.fulfill({ json: { type: 'StudentStatusChange', id: 'item-1', historyIncomplete: false, steps: [{ kind: 'submitted', time: '2026-11-01T00:00:00Z' }, { kind: 'counselorApproved', time: '2026-11-02T00:00:00Z', comment: '同意' }] } })
if (path === '/api/auth/me') return route.fulfill({ json: user })
if (path === '/api/plugins/runtime' || path.startsWith('/api/approvals/')) return route.fulfill({ json: [] })
return route.fulfill({ json: {} })
})
await page.goto('/approvals?progressType=StudentStatusChange&progressId=item-1')
const dialog = page.getByRole('dialog')
await expect(dialog.getByText('辅导员审核通过')).toBeVisible()
await expect(dialog.getByText('同意')).toBeVisible()
})
for (const scenario of [
{ type: 'GradeSheet', kind: 'returned', label: '已退回修改', cycle: true },
{ type: 'GradeSubmissionBatch', kind: 'approved', label: '审核通过', cycle: true },
{ type: 'ExperimentGradeSheet', kind: 'published', label: '已发布', cycle: true },
{ type: 'AssessmentDeclaration', kind: 'counselorApproved', label: '辅导员审核通过', cycle: true },
{ type: 'AssessmentAppeal', kind: 'rejected', label: '审核驳回', cycle: false },
]) test(`${scenario.type} shows its recorded progress`, async ({ page }) => {
const user = { id: 'reviewer', userName: 'reviewer', displayName: '审核员', roles: ['AcademicAdmin'], permissions: [], effectiveDataScope: 'All' }
await page.addInitScript((savedUser) => {
localStorage.setItem('jiaowu_token', 'test-token')
localStorage.setItem('jiaowu_user', JSON.stringify(savedUser))
localStorage.setItem('jiaowu_access_expires_at', '2099-01-01T00:00:00Z')
localStorage.setItem('jiaowu_session_expires_at', '2099-01-01T00:00:00Z')
}, user)
await page.route(url => url.pathname.startsWith('/api/'), async route => {
const path = new URL(route.request().url()).pathname
if (path === '/api/approvals/pending') {
const item = { id: 'item-1', type: scenario.type, label: '申请', title: '课程', desc: '测试进度', time: '2026-11-01T00:00:00Z', college: '学院' }
return route.fulfill({ json: { items: [item], total: 1, page: 1, pageSize: 20, counts: { [scenario.type]: 1 } } })
}
if (path === `/api/approvals/progress/${scenario.type}/item-1`)
return route.fulfill({ json: { type: scenario.type, id: 'item-1', historyIncomplete: false, steps: [{ kind: 'submitted', time: '2026-11-01T00:00:00Z' }, { kind: scenario.kind, time: '2026-11-02T00:00:00Z', comment: '审核意见' }] } })
if (path === '/api/auth/me') return route.fulfill({ json: user })
if (path === '/api/plugins/runtime') return route.fulfill({ json: [] })
return route.fulfill({ json: {} })
})
await page.goto('/approvals')
await page.locator('.appr-card').filter({ hasText: '测试进度' }).getByRole('button', { name: '办理进度' }).click()
const dialog = page.getByRole('dialog')
await expect(dialog.getByText(scenario.label)).toBeVisible()
await expect(dialog.getByText('审核意见')).toBeVisible()
if (scenario.cycle) await expect(dialog.getByText('这里只展示当前提交轮次。')).toBeVisible()
})