15b8e46af8
- 新后台新增「公司管理」页(列/新建/改名/启停,不提供删除),路由 menuKey 与 columns 表的 admin_companies 逐字一致,由用例钉住;操作指引补该菜单一条。 - 建号弹窗对超管必须显式选一家(后端对"不传"仍落操作者自己公司,是给旧后台兜底); admin 只能落自己公司,越权直接 403。账号列表显示 company_name,可按公司筛。 - 客户端登录后把 companyId/companyName 落到 localStorage 并在顶栏显示; 两个登出出口(handleKicked 与切号/登出)连公司名一起清 —— 残留会把上一个账号 的归属显示给下一个账号。 - 契约分层:列表端点用 snake_case(company_id/company_name),current-user 与登录 回包用 camelCase;解析器读到另一套写法必须忽略,防止前后端各猜一套。 admin-frontend-vue 1678/1678、frontend-vue 672/672,两边 build(含 vue-tsc --noEmit)干净。
86 lines
3.9 KiB
TypeScript
86 lines
3.9 KiB
TypeScript
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { readSource } from './helpers.ts'
|
|
import { normalizeUserPageParams, toUserListQuery } from '../src/api/users-dto.ts'
|
|
import { toAdminUserItem } from '../src/api/users-model.ts'
|
|
import {
|
|
createUserFilterState,
|
|
isFilterActive,
|
|
toUserListParams,
|
|
withFilterReset,
|
|
} from '../src/pages/account/users-filter.ts'
|
|
import { topbarUserOf } from '../src/layout/topbar-model.ts'
|
|
|
|
/** 公司维度进账号页(设计文档 §2.3/§5.1):列表列、按公司筛选(仅超管)、顶栏公司名。 */
|
|
|
|
test('company_user_list_item_reads_snake_case_company_columns', () => {
|
|
const item = toAdminUserItem({
|
|
id: 7,
|
|
username: '张三',
|
|
role: 'normal',
|
|
company_id: 2,
|
|
company_name: '福州数富',
|
|
})
|
|
assert.equal(item?.companyId, 2)
|
|
assert.equal(item?.companyName, '福州数富')
|
|
})
|
|
|
|
test('company_user_list_item_ignores_camel_case_company_keys', () => {
|
|
// 反向排他:后端 AdminUserItemVo 走 @JsonProperty snake_case,解析器若跟着读 camelCase 就是双向猜。
|
|
const item = toAdminUserItem({ id: 7, username: '张三', role: 'normal', companyId: 9, companyName: '别家' })
|
|
assert.equal(item?.companyId, undefined)
|
|
assert.equal(item?.companyName, undefined)
|
|
})
|
|
|
|
test('company_user_list_filter_state_defaults_to_no_company', () => {
|
|
assert.equal(createUserFilterState().companyId, null)
|
|
// 改了公司筛选要回第一页,与其他筛选条件同规则
|
|
const next = withFilterReset({ ...createUserFilterState(), page: 5 }, { companyId: 3 })
|
|
assert.equal(next.companyId, 3)
|
|
assert.equal(next.page, 1)
|
|
assert.equal(isFilterActive({ ...createUserFilterState(), companyId: 3 }), true)
|
|
})
|
|
|
|
test('company_user_list_query_sends_company_id_only_when_selected', () => {
|
|
const withCompany = toUserListQuery(normalizeUserPageParams({ page: 1, pageSize: 10, companyId: 3 }))
|
|
assert.equal(withCompany.company_id, 3)
|
|
assert.equal(
|
|
'company_id' in toUserListQuery(normalizeUserPageParams({ page: 1, pageSize: 10 })),
|
|
false,
|
|
'未选公司时不下发 company_id,否则后端会当成"只看这家公司"过滤',
|
|
)
|
|
})
|
|
|
|
test('company_user_list_params_adapter_carries_company_id', () => {
|
|
const params = toUserListParams({ ...createUserFilterState(), companyId: 2 })
|
|
assert.equal(params.companyId, 2)
|
|
})
|
|
|
|
test('company_topbar_shows_company_name', () => {
|
|
assert.equal(
|
|
topbarUserOf({ id: 1, username: 'admin', role: 'admin', companyName: ' 厦门米椿花 ' }).company,
|
|
'厦门米椿花',
|
|
)
|
|
// 未登录空态与"后端没带公司"都必须是不显示,而不是渲染出 undefined
|
|
assert.equal(topbarUserOf(null).company, '')
|
|
assert.equal(topbarUserOf({ id: 1, username: 'admin', role: 'admin' }).company, '')
|
|
})
|
|
|
|
test('company_user_list_page_ui_wiring', () => {
|
|
const page = readSource('src/pages/account/UsersPage.vue')
|
|
assert.match(page, /所属公司/, '账号页要有公司这一列/筛选的中文标签')
|
|
assert.match(page, /fetchCompanies/, '公司候选来自 /api/admin/companies')
|
|
assert.match(page, /:companies="companies"/, '整份公司目录交给弹窗,由弹窗按操作者收窄')
|
|
assert.match(page, /:operator="operatorScope"/, '弹窗要拿到操作者角色与归属才能判必选')
|
|
assert.match(page, /colspan="8"/, '加了公司列后空态横跨整表')
|
|
|
|
const dialog = readSource('src/pages/account/CreateUserDialog.vue')
|
|
assert.match(dialog, /selectableCompanies\(/, '下拉选项走同一条后端收窄规则')
|
|
assert.match(dialog, /initialCompanyId\(/, '打开弹窗时的默认公司走纯函数,不在模板里现写')
|
|
assert.match(dialog, /请选择所属公司/, '下拉占位与校验文案同源')
|
|
assert.match(dialog, /validateCreateUserForm\(form, props\.operator\)/, '校验必须带上操作者,否则"超管必选公司"永远不触发')
|
|
|
|
const layout = readSource('src/layout/AdminLayout.vue')
|
|
assert.match(layout, /userVm\.company/, '顶栏走同一条公司名视图模型')
|
|
})
|