优化
This commit is contained in:
@@ -40,9 +40,9 @@ function createMemoryStorage(): Storage {
|
||||
|
||||
const user: PlatformManagedUser = {
|
||||
membershipId: '30', userId: '20', authUserId: '10', username: 'zhangwei', displayName: '张伟',
|
||||
phone: '13800138000', email: 'zhangwei@example.com', tenantId: '10001', tenantName: '华远贸易',
|
||||
memberType: 'EMPLOYEE', memberNo: 'MEMBER-30', status: 'ACTIVE', roleIds: ['40'],
|
||||
roleNames: ['租户管理员'], lastLoginAt: '2026-06-01T10:30:00',
|
||||
phone: '13800138000', email: 'zhangwei@example.com', tenantId: '0', tenantName: '平台',
|
||||
memberType: 'INTERNAL', memberNo: 'PLATFORM-30', status: 'ACTIVE', roleIds: ['40'],
|
||||
roleNames: ['运营管理员'], lastLoginAt: '2026-06-01T10:30:00',
|
||||
protectedAccount: false,
|
||||
}
|
||||
|
||||
@@ -69,39 +69,47 @@ async function mountView() {
|
||||
enableAutoUnmount(afterEach)
|
||||
afterAll(() => vi.unstubAllGlobals())
|
||||
|
||||
describe('InternalUsersView unified platform user management', () => {
|
||||
describe('InternalUsersView platform internal user management', () => {
|
||||
beforeEach(() => {
|
||||
vi.stubGlobal('ResizeObserver', ResizeObserverStub)
|
||||
document.body.innerHTML = ''
|
||||
vi.mocked(listPlatformManagedUsers).mockReset().mockResolvedValue([user])
|
||||
vi.mocked(listPlatformManagedUsers).mockReset().mockResolvedValue({
|
||||
records: [user], page: 1, size: 10, total: 21, pages: 3,
|
||||
})
|
||||
vi.mocked(getPlatformUserOptions).mockReset().mockResolvedValue({
|
||||
tenants: [
|
||||
{ id: '0', name: '平台', status: 'ACTIVE' },
|
||||
{ id: '10001', name: '华远贸易', status: 'ACTIVE' },
|
||||
],
|
||||
roles: [{ id: '40', tenantId: '10001', name: '租户管理员', status: 'ACTIVE' }],
|
||||
roles: [
|
||||
{ id: '40', tenantId: '0', name: '运营管理员', status: 'ACTIVE' },
|
||||
{ id: '41', tenantId: '10001', name: '租户管理员', status: 'ACTIVE' },
|
||||
],
|
||||
})
|
||||
})
|
||||
|
||||
it('loads and renders prototype fields from the unified API', async () => {
|
||||
it('loads a server page and only renders internal-user fields', async () => {
|
||||
const wrapper = await mountView()
|
||||
|
||||
expect(listPlatformManagedUsers).toHaveBeenCalledOnce()
|
||||
expect(listPlatformManagedUsers).toHaveBeenCalledWith({ page: 1, size: 10 })
|
||||
expect(getPlatformUserOptions).toHaveBeenCalledOnce()
|
||||
expect(wrapper.text()).toContain('zhangwei')
|
||||
expect(wrapper.text()).toContain('张伟')
|
||||
expect(wrapper.text()).toContain('华远贸易')
|
||||
expect(wrapper.text()).toContain('租户管理员')
|
||||
expect(wrapper.text()).toContain('运营管理员')
|
||||
expect(wrapper.text()).toContain('2026-06-01 10:30')
|
||||
expect(wrapper.find('[aria-label="用户筛选"]').exists()).toBe(true)
|
||||
expect(wrapper.find('[aria-label="用户列表"]').exists()).toBe(true)
|
||||
expect(wrapper.find('[aria-label="内部用户列表"]').exists()).toBe(true)
|
||||
expect(wrapper.text()).toContain('共 21 条')
|
||||
expect(wrapper.text()).toContain('查询')
|
||||
expect(wrapper.text()).toContain('重置')
|
||||
expect(wrapper.text()).not.toContain('认证用户 ID')
|
||||
expect(wrapper.text()).not.toContain('成员编号')
|
||||
expect(wrapper.text()).not.toContain('所属租户')
|
||||
expect(wrapper.text()).not.toContain('华远贸易')
|
||||
})
|
||||
|
||||
it('opens the complete prototype create form', async () => {
|
||||
it('opens an internal-user form without a tenant selector', async () => {
|
||||
const wrapper = await mountView()
|
||||
const createButton = wrapper.findAll('button').find((button) => button.text().trim() === '新增用户')
|
||||
await createButton?.trigger('click')
|
||||
@@ -111,11 +119,26 @@ describe('InternalUsersView unified platform user management', () => {
|
||||
expect(document.querySelector('input[placeholder="真实姓名"]')).not.toBeNull()
|
||||
expect(document.querySelector('input[placeholder="手机号码"]')).not.toBeNull()
|
||||
expect(document.querySelector('input[placeholder="邮箱地址"]')).not.toBeNull()
|
||||
expect(document.body.textContent).toContain('所属租户')
|
||||
expect(document.body.textContent).not.toContain('所属租户')
|
||||
expect(document.body.textContent).toContain('初始密码')
|
||||
expect(document.body.textContent).toContain('确认添加')
|
||||
})
|
||||
|
||||
it('requests server-side pages and filters instead of slicing locally', async () => {
|
||||
const wrapper = await mountView()
|
||||
await wrapper.find('button[aria-label="第 2 页"]').trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(listPlatformManagedUsers).toHaveBeenLastCalledWith({ page: 2, size: 10 })
|
||||
|
||||
await wrapper.find('input[aria-label="用户关键词"]').setValue(' 张伟 ')
|
||||
const searchButton = wrapper.findAll('button').find((button) => button.text().trim() === '查询')
|
||||
await searchButton?.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(listPlatformManagedUsers).toHaveBeenLastCalledWith({ page: 1, size: 10, keyword: '张伟' })
|
||||
})
|
||||
|
||||
it('shows a recoverable API error without fake users', async () => {
|
||||
vi.mocked(listPlatformManagedUsers).mockRejectedValueOnce(new Error('Gateway unavailable'))
|
||||
const wrapper = await mountView()
|
||||
|
||||
Reference in New Issue
Block a user