From 40905cbd04c2e332cd4bc2b9e0c5b3e1da9cccfa Mon Sep 17 00:00:00 2001
From: zhou zhou <3272660260@qq.com>
Date: 星期一, 30 三月 2026 08:17:32 +0800
Subject: [PATCH] feat: complete rsf-design phase 1 integration
---
rsf-design/tests/system-user-page-contract.test.mjs | 209 +++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 204 insertions(+), 5 deletions(-)
diff --git a/rsf-design/tests/system-user-page-contract.test.mjs b/rsf-design/tests/system-user-page-contract.test.mjs
index 3c09037..37da9ce 100644
--- a/rsf-design/tests/system-user-page-contract.test.mjs
+++ b/rsf-design/tests/system-user-page-contract.test.mjs
@@ -1,10 +1,209 @@
import assert from 'node:assert/strict'
import test from 'node:test'
-import { buildUserDialogModel } from '../src/views/system/user/userPage.helpers.js'
-test('buildUserDialogModel maps rsf-admin edit data into the dialog model', () => {
- assert.equal(
- buildUserDialogModel({ username: 'root', nickname: '绠$悊鍛�', deptId: 1, roles: [{ id: 3 }] }).username,
- 'root'
+import {
+ buildUserDialogModel,
+ buildUserPageQueryParams,
+ buildUserSavePayload,
+ buildUserSearchParams,
+ getUserStatusMeta,
+ mergeUserDetailRecord,
+ normalizeDeptTreeOptions,
+ normalizeRoleOptions,
+ normalizeUserListRow
+} from '../src/views/system/user/userPage.helpers.js'
+
+test('buildUserSearchParams keeps real user page search fields', () => {
+ assert.deepEqual(
+ buildUserSearchParams({
+ username: 'root',
+ nickname: '绠$悊鍛�',
+ phone: '13800000000',
+ email: 'root@example.com',
+ status: 1,
+ deptId: 0,
+ roleIds: [3, 8],
+ code: 'A001',
+ sex: 1,
+ realName: 'Vincent',
+ idCard: '330421199511233211',
+ condition: 'root'
+ }),
+ {
+ username: 'root',
+ nickname: '绠$悊鍛�',
+ phone: '13800000000',
+ email: 'root@example.com',
+ status: 1,
+ deptId: 0,
+ roleIds: [3, 8],
+ code: 'A001',
+ sex: 1,
+ realName: 'Vincent',
+ idCard: '330421199511233211',
+ condition: 'root'
+ }
)
})
+
+test('buildUserPageQueryParams merges paging and search fields', () => {
+ assert.deepEqual(
+ buildUserPageQueryParams({
+ current: 2,
+ size: 20,
+ username: 'root',
+ condition: 'manager'
+ }),
+ {
+ current: 2,
+ pageSize: 20,
+ username: 'root',
+ condition: 'manager'
+ }
+ )
+})
+
+test('buildUserDialogModel normalizes backend edit data into the form model', () => {
+ assert.deepEqual(
+ buildUserDialogModel({
+ id: 7,
+ username: 'root',
+ nickname: '绠$悊鍛�',
+ deptId: 1,
+ roles: [{ id: 3 }, { roleId: 8 }],
+ sex: 1,
+ code: 'A001',
+ phone: '13800000000',
+ email: 'root@example.com',
+ realName: 'Vincent',
+ idCard: '330421199511233211',
+ memo: 'memo',
+ status: 0
+ }),
+ {
+ id: 7,
+ username: 'root',
+ nickname: '绠$悊鍛�',
+ deptId: 1,
+ roleIds: [3, 8],
+ userRoleIds: [3, 8],
+ password: '',
+ confirmPassword: '',
+ sex: 1,
+ code: 'A001',
+ phone: '13800000000',
+ email: 'root@example.com',
+ realName: 'Vincent',
+ idCard: '330421199511233211',
+ memo: 'memo',
+ status: 0
+ }
+ )
+})
+
+test('buildUserSavePayload submits roleIds and password for the backend', () => {
+ assert.deepEqual(
+ buildUserSavePayload({
+ id: 7,
+ username: 'root',
+ nickname: '绠$悊鍛�',
+ deptId: 1,
+ userRoleIds: [3, 8],
+ password: 'secret',
+ confirmPassword: 'secret',
+ sex: 1,
+ code: 'A001',
+ phone: '13800000000',
+ email: 'root@example.com',
+ realName: 'Vincent',
+ idCard: '330421199511233211',
+ memo: 'memo',
+ status: 1
+ }),
+ {
+ id: 7,
+ username: 'root',
+ nickname: '绠$悊鍛�',
+ deptId: 1,
+ roleIds: [3, 8],
+ password: 'secret',
+ sex: 1,
+ code: 'A001',
+ phone: '13800000000',
+ email: 'root@example.com',
+ realName: 'Vincent',
+ idCard: '330421199511233211',
+ memo: 'memo',
+ status: 1
+ }
+ )
+})
+
+test('normalizeUserListRow exposes table friendly fields', () => {
+ const normalized = normalizeUserListRow({
+ username: 'root',
+ nickname: '绠$悊鍛�',
+ deptLabel: '鐮斿彂閮�',
+ deptId$: '鐮斿彂閮�',
+ roleNames: '瓒呯骇绠$悊鍛樸�丱PS',
+ roles: [{ name: '瓒呯骇绠$悊鍛�' }, { code: 'OPS' }],
+ status: 1,
+ createTime$: '2025-03-28 10:00:00',
+ updateTime: '2025-03-28 11:00:00'
+ })
+
+ assert.equal(normalized.username, 'root')
+ assert.equal(normalized.deptLabel, '鐮斿彂閮�')
+ assert.equal(normalized.roleNames, '瓒呯骇绠$悊鍛樸�丱PS')
+ assert.equal(normalized.statusBool, true)
+ assert.equal(normalized.statusText, '姝e父')
+ assert.equal(normalized.statusType, 'success')
+ assert.equal(normalized.createTimeText, '2025-03-28 10:00:00')
+ assert.equal(normalized.updateTimeText, '2025-03-28 11:00:00')
+})
+
+test('mergeUserDetailRecord keeps list row roles when detail omits them', () => {
+ assert.deepEqual(
+ mergeUserDetailRecord(
+ {
+ id: 7,
+ username: 'root',
+ nickname: '绠$悊鍛�'
+ },
+ {
+ id: 7,
+ deptLabel: '鐮斿彂閮�',
+ roleNames: '瓒呯骇绠$悊鍛�',
+ roles: [{ id: 3, name: '瓒呯骇绠$悊鍛�' }]
+ }
+ ),
+ {
+ id: 7,
+ username: 'root',
+ nickname: '绠$悊鍛�',
+ deptLabel: '鐮斿彂閮�',
+ roleNames: '瓒呯骇绠$悊鍛�',
+ roles: [{ id: 3, name: '瓒呯骇绠$悊鍛�' }]
+ }
+ )
+})
+
+test('normalizeDeptTreeOptions and normalizeRoleOptions adapt lookup data', () => {
+ assert.deepEqual(
+ normalizeDeptTreeOptions([{ id: 1, name: '鎬婚儴', children: [{ id: 2, name: '鐮斿彂閮�' }] }]),
+ [{ value: 1, label: '鎬婚儴', children: [{ value: 2, label: '鐮斿彂閮�', children: [] }] }]
+ )
+
+ assert.deepEqual(
+ normalizeRoleOptions([{ id: 3, name: '绠$悊鍛�' }, { roleId: 8, code: 'OPS' }]),
+ [
+ { value: 3, label: '绠$悊鍛�' },
+ { value: 8, label: 'OPS' }
+ ]
+ )
+})
+
+test('getUserStatusMeta maps enabled and disabled states', () => {
+ assert.deepEqual(getUserStatusMeta(1), { type: 'success', text: '姝e父', bool: true })
+ assert.deepEqual(getUserStatusMeta(0), { type: 'danger', text: '绂佺敤', bool: false })
+})
--
Gitblit v1.9.1