58 lines
2.1 KiB
TypeScript
58 lines
2.1 KiB
TypeScript
import { test, expect } from '@playwright/test'
|
|
import { uiLogin } from '../utils/auth'
|
|
import { createIssueViaApi, deleteIssueViaApi, changeStatusViaApi } from '../utils/api-helpers'
|
|
|
|
test.describe('指摘 CRUD', () => {
|
|
let apiToken = ''
|
|
let issueId = 0
|
|
let issueNo = ''
|
|
|
|
test.beforeEach(async ({ page, request }) => {
|
|
const created = await createIssueViaApi(request)
|
|
issueId = created.issue.id
|
|
issueNo = created.issue.issueNo
|
|
apiToken = created.token
|
|
await uiLogin(page)
|
|
})
|
|
|
|
test.afterEach(async ({ request }) => {
|
|
if (issueId) {
|
|
await deleteIssueViaApi(request, issueId, apiToken).catch(() => {})
|
|
}
|
|
})
|
|
|
|
test('列表页显示新建的指摘', async ({ page }) => {
|
|
await page.goto('/issues')
|
|
await expect(page.getByText('指摘列表')).toBeVisible()
|
|
await expect(page.getByText(issueNo)).toBeVisible()
|
|
})
|
|
|
|
test('详情页显示完整信息与状态流转历史', async ({ page }) => {
|
|
await page.goto(`/issues/${issueId}`)
|
|
await expect(page.getByText(issueNo)).toBeVisible()
|
|
await expect(page.getByText('状态流转历史')).toBeVisible()
|
|
await expect(page.getByText('创建指摘').first()).toBeVisible()
|
|
})
|
|
|
|
test('合法状态流转 draft -> open', async ({ page }) => {
|
|
await page.goto(`/issues/${issueId}`)
|
|
const dialog = page.getByRole('dialog')
|
|
await page.getByRole('button', { name: /更改状态/i }).click()
|
|
await expect(dialog).toBeVisible()
|
|
await dialog.locator('.ant-select-input').click()
|
|
const opt = page.locator('.ant-select-item-option[title="待处理"]')
|
|
await expect(opt).toBeVisible()
|
|
await opt.click()
|
|
await expect(dialog.locator('.ant-select-content')).toContainText('待处理')
|
|
await dialog.getByRole('button', { name: /确认变更/i }).click()
|
|
await expect(page.getByText('状态已更新')).toBeVisible()
|
|
})
|
|
|
|
test('非法状态流转返回 400 错误提示', async ({ request }) => {
|
|
const ok = await changeStatusViaApi(request, issueId, apiToken, 'open')
|
|
expect(ok.status()).toBe(200)
|
|
const illegal = await changeStatusViaApi(request, issueId, apiToken, 'closed')
|
|
expect(illegal.status()).toBe(400)
|
|
})
|
|
})
|