69 lines
3.4 KiB
TypeScript
69 lines
3.4 KiB
TypeScript
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { readSource } from './helpers.ts'
|
|
import {
|
|
eligibleGroupMembers,
|
|
groupMemberCandidateHint,
|
|
} from '../src/pages/account/shop-group-model.ts'
|
|
|
|
/** 对齐 admin.js:3020-3028 getEligibleShopManageGroupUsers 与 3179-3182 帮助文案。 */
|
|
|
|
const USERS = [
|
|
{ id: 1, username: '组长A', role: 'admin', createdById: null },
|
|
{ id: 2, username: '员工A1', role: 'normal', createdById: 1 },
|
|
{ id: 3, username: '员工A2', role: 'normal', createdById: 1 },
|
|
{ id: 4, username: '别人员工', role: 'normal', createdById: 9 },
|
|
{ id: 5, username: '另一个管理员', role: 'admin', createdById: null },
|
|
{ id: 6, username: '超管本人', role: 'super_admin', createdById: null },
|
|
]
|
|
|
|
test('align_group_eligible_super_admin_sees_all_except_leader', () => {
|
|
// 超管:候选 = 全部用户(除组长本人),不区分归属。
|
|
const result = eligibleGroupMembers(USERS, 1, 'super_admin')
|
|
assert.deepEqual(result.map((u) => u.id), [2, 3, 4, 5, 6])
|
|
})
|
|
|
|
test('align_group_eligible_non_super_only_own_normal_employees', () => {
|
|
// 管理员/组长:候选 = created_by=组长本人的普通账号,别人名下/管理员/超管不可选。
|
|
const result = eligibleGroupMembers(USERS, 1, 'admin')
|
|
assert.deepEqual(result.map((u) => u.id), [2, 3])
|
|
})
|
|
|
|
test('align_group_eligible_excludes_leader_self', () => {
|
|
// 组长本人永不进候选(即使是 normal 且归属自己)。
|
|
const withSelf = [{ id: 1, username: '组长', role: 'normal', createdById: 1 }, ...USERS]
|
|
const result = eligibleGroupMembers(withSelf, 1, 'super_admin')
|
|
assert.equal(result.some((u) => u.id === 1), false)
|
|
})
|
|
|
|
test('align_group_eligible_null_leader_means_own_created_only_for_non_super', () => {
|
|
// 组长 id 缺失时按字符串比较兜底,不误匹配。
|
|
const result = eligibleGroupMembers(USERS, null, 'admin')
|
|
assert.equal(result.length, 0)
|
|
})
|
|
|
|
test('align_group_candidate_hint_with_candidates', () => {
|
|
assert.match(groupMemberCandidateHint(3, 'admin'), /可添加当前组长创建的普通员工账号/)
|
|
})
|
|
|
|
test('align_group_candidate_hint_empty_for_normal', () => {
|
|
assert.match(groupMemberCandidateHint(0, 'normal'), /普通账号没有下属普通员工时,这里会为空;当前账号只能作为组长使用。/)
|
|
})
|
|
|
|
test('align_group_candidate_hint_empty_for_admin', () => {
|
|
assert.match(groupMemberCandidateHint(0, 'admin'), /当前组长名下暂无可添加的普通员工账号。/)
|
|
})
|
|
|
|
test('align_group_editor_dialog_ui_wiring', () => {
|
|
// UI 接线:候选请求 page_size=999;新建时组长恒为当前登录用户(无改选下拉);候选/提示走新模型。
|
|
const dialog = readSource('src/pages/account/GroupEditorDialog.vue')
|
|
assert.match(dialog, /pageSize:\s*999/, '候选列表按参考 page_size=999 拉取')
|
|
assert.doesNotMatch(dialog, /组长(创建人)/, '新建弹窗不再提供组长改选下拉')
|
|
assert.match(dialog, /当前登录用户/, '新建时组长只读显示当前登录用户')
|
|
assert.match(dialog, /eligibleGroupMembers/, '组员候选走归属过滤')
|
|
assert.match(dialog, /groupMemberCandidateHint/, '候选提示文案走对齐逻辑')
|
|
const page = readSource('src/pages/account/GroupsPage.vue')
|
|
assert.match(page, /创建时间/, '列表补创建时间列')
|
|
assert.doesNotMatch(page, /slice\(0,\s*10\)/, '组员 chips 全量渲染不再收 +N')
|
|
})
|