feat: 完善客户列表管理操作

This commit is contained in:
2026-08-08 10:14:07 +08:00
parent 70b8289ff5
commit 6f709267b7
7 changed files with 334 additions and 10 deletions
@@ -4,12 +4,15 @@ import { enableAutoUnmount, flushPromises, mount } from '@vue/test-utils'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import {
approveEnterpriseReview,
archivePlatformTenant,
downloadTenantQualification,
createPlatformTenantImpersonation,
getPlatformTenant,
listEnterpriseReviews,
listPlatformTenants,
listTenantQualifications,
rejectEnterpriseReview,
resetPlatformTenantOwnerPassword,
updatePlatformTenant,
uploadPlatformTenantQualification,
uploadPlatformTenantRequiredQualificationPackage,
@@ -45,9 +48,11 @@ vi.mock('vue-router', async (importOriginal) => ({
vi.mock('@/modules/iam', () => ({
approveEnterpriseReview: vi.fn(),
archivePlatformTenant: vi.fn(),
changePlatformTenantStatus: vi.fn(),
checkPlatformTenantContactPhone: vi.fn().mockResolvedValue(true),
createPlatformTenant: vi.fn(),
createPlatformTenantImpersonation: vi.fn(),
downloadTenantQualification: vi.fn(),
getPlatformTenant: vi.fn(),
listEnterpriseReviews: vi.fn(),
@@ -56,6 +61,7 @@ vi.mock('@/modules/iam', () => ({
listTenantQualifications: vi.fn(),
qualificationFileName: vi.fn((documentUrl: string) => documentUrl.split('/').at(-1) || '资质文件'),
rejectEnterpriseReview: vi.fn(),
resetPlatformTenantOwnerPassword: vi.fn(),
submitPlatformTenantReview: vi.fn(),
updatePlatformTenant: vi.fn(),
uploadPlatformTenantQualification: vi.fn(),
@@ -349,7 +355,7 @@ describe('CustomersView', () => {
mount(CustomersView, { attachTo: document.body, global: { plugins: [pinia, ElementPlus] } })
await flushPromises()
tableButtonByText('通过')?.click()
tableButtonByText('审核')?.click()
await flushPromises()
;[...document.querySelectorAll<HTMLButtonElement>('button')]
.find((button) => button.textContent?.trim() === '确认通过')?.click()
@@ -379,7 +385,7 @@ describe('CustomersView', () => {
mount(CustomersView, { attachTo: document.body, global: { plugins: [pinia, ElementPlus] } })
await flushPromises()
tableButtonByText('通过')?.click()
tableButtonByText('审核')?.click()
await flushPromises()
;[...document.querySelectorAll<HTMLButtonElement>('button')]
.find((button) => button.textContent?.trim() === '确认通过')?.click()
@@ -402,7 +408,7 @@ describe('CustomersView', () => {
expect(listPlatformTenants).not.toHaveBeenCalled()
expect(document.body.textContent).toContain(fullTenant.tenantName)
expect(tableButtonByText('通过')).toBeDefined()
expect(tableButtonByText('审核')).toBeDefined()
})
it('does not let an older review response restore stale actions', async () => {
@@ -423,11 +429,65 @@ describe('CustomersView', () => {
resolveSecond([pendingReview])
await flushPromises()
expect(tableButtonByText('通过')).toBeDefined()
expect(tableButtonByText('审核')).toBeDefined()
resolveFirst([])
await flushPromises()
expect(tableButtonByText('通过')).toBeDefined()
expect(tableButtonByText('审核')).toBeDefined()
})
it('resets only the customer owner password through the tenant contract', async () => {
const auth = useAuthStore()
auth.permissions = [...auth.permissions, 'platform:customer:reset-password']
useAccessPreviewStore().initializeAfterLogin()
vi.mocked(listPlatformTenants).mockResolvedValue({ records: [{ ...fullTenant, status: 'ACTIVE' }], page: 1, size: 10, total: 1, pages: 1 })
vi.mocked(resetPlatformTenantOwnerPassword).mockResolvedValue()
mount(CustomersView, { attachTo: document.body, global: { plugins: [pinia, ElementPlus] } })
await flushPromises()
tableButtonByText('重置密码')?.click()
await flushPromises()
const password = document.querySelector<HTMLInputElement>('input[autocomplete="new-password"]')
const confirmation = document.querySelector<HTMLInputElement>('input[placeholder="请再次输入新密码"]')
password!.value = 'NewPassword#2026'
password!.dispatchEvent(new Event('input', { bubbles: true }))
confirmation!.value = 'NewPassword#2026'
confirmation!.dispatchEvent(new Event('input', { bubbles: true }))
await flushPromises()
;[...document.querySelectorAll<HTMLButtonElement>('button')]
.find((button) => button.textContent?.trim() === '确认重置')?.click()
await flushPromises()
expect(resetPlatformTenantOwnerPassword).toHaveBeenCalledWith(fullTenant.id, {
newPassword: 'NewPassword#2026', forceChangePassword: true,
})
})
it('archives a customer only after its customer ID is explicitly confirmed', async () => {
const auth = useAuthStore()
auth.permissions = [...auth.permissions, 'platform:customer:delete']
useAccessPreviewStore().initializeAfterLogin()
vi.mocked(archivePlatformTenant).mockResolvedValue({ ...fullTenant, status: 'DISABLED' })
mount(CustomersView, { attachTo: document.body, global: { plugins: [pinia, ElementPlus] } })
await flushPromises()
tableButtonByText('删除')?.click()
await flushPromises()
const confirmation = document.querySelector<HTMLInputElement>('input[placeholder="TEN8"]')
expect(confirmation).toBeTruthy()
expect([...document.querySelectorAll<HTMLButtonElement>('button')]
.find((button) => button.textContent?.trim() === '确认删除')?.disabled).toBe(true)
confirmation!.value = 'TEN8'
confirmation!.dispatchEvent(new Event('input', { bubbles: true }))
await flushPromises()
;[...document.querySelectorAll<HTMLButtonElement>('button')]
.find((button) => button.textContent?.trim() === '确认删除')?.click()
await flushPromises()
expect(archivePlatformTenant).toHaveBeenCalledWith(fullTenant.id)
})
it('keeps the first operation column unfixed so it cannot cover a 320px table viewport', async () => {