69 lines
3.5 KiB
TypeScript
69 lines
3.5 KiB
TypeScript
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { readSource } from './helpers.ts'
|
|
import { createUserFilterState, toUserListParams } from '../src/pages/account/users-filter.ts'
|
|
import { deleteConfirmMessage } from '../src/pages/account/user-delete-model.ts'
|
|
|
|
// module 13 task 250:用户管理列表页对齐 admin panel-users(页头描述/筛选含所属管理员/角色中文/分页)。
|
|
|
|
test('test_task_250_users_list_normal_primary_path', () => {
|
|
const page = readSource('src/pages/account/UsersPage.vue')
|
|
assert.match(page, /roleLabel/, '角色列需走中文 roleLabel 映射')
|
|
assert.match(page, /所属管理员/, '需展示“所属管理员”列/筛选项')
|
|
assert.match(page, /无开放注册|开放注册入口/, '页头应有“无开放注册入口”说明')
|
|
})
|
|
|
|
test('test_task_250_users_list_normal_variant_input', () => {
|
|
// 正常变体:删除确认与不可删原因复用用户模型文案。
|
|
const page = readSource('src/pages/account/UsersPage.vue')
|
|
assert.match(page, /deleteConfirmMessage/, '删除确认应复用 deleteConfirmMessage')
|
|
assert.match(page, /deleteBlockReason/, '不可删原因应复用 deleteBlockReason')
|
|
assert.match(page, /creatorUsername/, '列表应含所属管理员列')
|
|
})
|
|
|
|
test('test_task_250_users_list_normal_repeated_operation_is_idempotent', () => {
|
|
// 筛选映射:createdByAdminId -> created_by_id。
|
|
const state = { ...createUserFilterState(), createdByAdminId: 7 }
|
|
const params = toUserListParams(state)
|
|
assert.equal(params.createdById, 7)
|
|
const plain = toUserListParams(createUserFilterState())
|
|
assert.equal(plain.createdById, null)
|
|
})
|
|
|
|
test('test_task_250_users_list_boundary_empty_input', () => {
|
|
// 边界:空结果应有明确空态占位。
|
|
const page = readSource('src/pages/account/UsersPage.vue')
|
|
assert.match(page, /el-empty|暂无用户|userListEmptyHint|empty-text/, '空态需有用户可读提示')
|
|
})
|
|
|
|
test('test_task_250_users_list_boundary_single_item', () => {
|
|
// 边界:分页/合计形态为“共 N 条”,查询后回第一页。
|
|
const page = readSource('src/pages/account/UsersPage.vue')
|
|
assert.match(page, /OldPagination/, '分页走共享组件')
|
|
const comp = readSource('src/components/OldPagination.vue')
|
|
assert.match(comp, /共 \{\{ total \}\} 条/, '共享分页含“共 N 条”合计')
|
|
assert.match(page, /filters\.page = 1/, '查询需重置回第一页')
|
|
})
|
|
|
|
test('test_task_250_users_list_boundary_limit_or_missing_field', () => {
|
|
// 边界上限:所属管理员筛选仅超管可见(非超管隐藏)。
|
|
const page = readSource('src/pages/account/UsersPage.vue')
|
|
assert.match(page, /isSuperAdmin|super_admin|createdByAdminId/, '需按超管身份控制管理员筛选项')
|
|
assert.ok(deleteConfirmMessage({ id: 1, username: 'demo', role: 'normal' }).includes('确定删除用户 "demo" 吗?'))
|
|
})
|
|
|
|
test('test_task_250_users_list_invalid_input_rejected', () => {
|
|
// 异常:不得再直出英文角色码(已改中文)。
|
|
const page = readSource('src/pages/account/UsersPage.vue')
|
|
assert.equal(/prop="role"/.test(page), false, '角色列不得再直出 prop=role 英文')
|
|
assert.equal(/admin-user-role/.test(page), false)
|
|
})
|
|
|
|
test('test_task_250_users_list_dependency_failure_returns_actionable_message', () => {
|
|
// 依赖:列表响应解析 admins(供所属管理员下拉)。
|
|
const model = readSource('src/api/users-model.ts')
|
|
assert.match(model, /record\.admins/, 'users-model 需解析 admins')
|
|
const dto = readSource('src/api/users-dto.ts')
|
|
assert.match(dto, /admins\?:/, 'DTO 需声明 admins')
|
|
})
|