修复bug

This commit is contained in:
2026-08-03 20:50:18 +08:00
parent d2370650e7
commit fa922ca96f
13 changed files with 357 additions and 736 deletions
@@ -3,12 +3,16 @@ import { createPinia, setActivePinia } from 'pinia'
import { enableAutoUnmount, flushPromises, mount } from '@vue/test-utils'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import {
approveEnterpriseReview,
downloadTenantQualification,
getPlatformTenant,
listEnterpriseReviews,
listPlatformTenants,
listTenantQualifications,
rejectEnterpriseReview,
updatePlatformTenant,
uploadPlatformTenantQualification,
type EnterpriseReview,
type PlatformTenantResource,
} from '@/modules/iam'
import { createPlatformExportTask } from '@/modules/downloads'
@@ -17,14 +21,17 @@ import { useAuthStore } from '@/core/auth/auth'
import CustomersView from './CustomersView.vue'
vi.mock('@/modules/iam', () => ({
approveEnterpriseReview: vi.fn(),
changePlatformTenantStatus: vi.fn(),
createPlatformTenant: vi.fn(),
downloadTenantQualification: vi.fn(),
getPlatformTenant: vi.fn(),
listEnterpriseReviews: vi.fn(),
listPlatformTenantOrderCounts: vi.fn(),
listPlatformTenants: vi.fn(),
listTenantQualifications: vi.fn(),
qualificationFileName: vi.fn((documentUrl: string) => documentUrl.split('/').at(-1) || '资质文件'),
rejectEnterpriseReview: vi.fn(),
submitPlatformTenantReview: vi.fn(),
updatePlatformTenant: vi.fn(),
uploadPlatformTenantQualification: vi.fn(),
@@ -48,6 +55,14 @@ const fullTenant: PlatformTenantResource = {
createdAt: '2026-08-01T10:00:00', approvedAt: null,
}
const pendingReview: EnterpriseReview = {
id: '190000000000000001',
tenantId: fullTenant.id,
tenantName: fullTenant.tenantName,
tenantCode: fullTenant.tenantCode,
status: 'PENDING',
}
function tableButtonByText(text: string) {
return [...document.querySelectorAll<HTMLButtonElement>('.el-table__body button')]
.find((button) => button.textContent?.trim() === text)
@@ -76,6 +91,7 @@ describe('CustomersView', () => {
})
vi.mocked(getPlatformTenant).mockResolvedValue(fullTenant)
vi.mocked(listTenantQualifications).mockResolvedValue([])
vi.mocked(listEnterpriseReviews).mockResolvedValue([])
vi.mocked(updatePlatformTenant).mockResolvedValue(fullTenant)
vi.mocked(uploadPlatformTenantQualification).mockResolvedValue({
qualificationId: 'qualification-1', reviewId: null, tenantStatus: 'PROFILE_REQUIRED', documentUrl: '/files/license.png',
@@ -181,4 +197,80 @@ describe('CustomersView', () => {
})
expect(listPlatformTenants).toHaveBeenCalledTimes(1)
})
it('approves a pending enterprise directly from the customer list', async () => {
const auth = useAuthStore()
auth.permissions = [...auth.permissions, 'platform:customer:review', 'platform:customer:approve']
useAccessPreviewStore().initializeAfterLogin()
vi.mocked(listPlatformTenants).mockResolvedValue({
records: [{ ...fullTenant, status: 'PENDING' }], page: 1, size: 10, total: 1, pages: 1,
})
vi.mocked(listEnterpriseReviews).mockResolvedValue([pendingReview])
vi.mocked(approveEnterpriseReview).mockResolvedValue({
tenantId: fullTenant.id,
administratorCreated: true,
administratorUsername: 'merchant_8_owner',
temporaryPassword: 'Temporary#2026',
})
mount(CustomersView, { attachTo: document.body, global: { plugins: [pinia, ElementPlus] } })
await flushPromises()
tableButtonByText('通过')?.click()
await flushPromises()
;[...document.querySelectorAll<HTMLButtonElement>('button')]
.find((button) => button.textContent?.trim() === '确认通过')?.click()
await flushPromises()
expect(approveEnterpriseReview).toHaveBeenCalledWith(pendingReview.id, '企业资料与必填资质完整、清晰,审核通过')
expect(rejectEnterpriseReview).not.toHaveBeenCalled()
expect(document.body.textContent).toContain('请立即保存以下一次性凭证')
expect(document.body.textContent).toContain('merchant_8_owner')
expect(document.body.textContent).toContain('Temporary#2026')
})
it('keeps review-only roles on the merged customer page without calling the customer list endpoint', async () => {
const auth = useAuthStore()
auth.permissions = ['platform:customer:review', 'platform:customer:approve']
useAccessPreviewStore().initializeAfterLogin()
vi.mocked(listEnterpriseReviews).mockResolvedValue([pendingReview])
mount(CustomersView, { attachTo: document.body, global: { plugins: [pinia, ElementPlus] } })
await flushPromises()
expect(listPlatformTenants).not.toHaveBeenCalled()
expect(document.body.textContent).toContain(fullTenant.tenantName)
expect(tableButtonByText('通过')).toBeDefined()
})
it('does not let an older review response restore stale actions', async () => {
const auth = useAuthStore()
auth.permissions = [...auth.permissions, 'platform:customer:review', 'platform:customer:approve']
useAccessPreviewStore().initializeAfterLogin()
let resolveFirst!: (value: EnterpriseReview[]) => void
let resolveSecond!: (value: EnterpriseReview[]) => void
vi.mocked(listEnterpriseReviews)
.mockImplementationOnce(() => new Promise((resolve) => { resolveFirst = resolve }))
.mockImplementationOnce(() => new Promise((resolve) => { resolveSecond = resolve }))
mount(CustomersView, { attachTo: document.body, global: { plugins: [pinia, ElementPlus] } })
await Promise.resolve()
;[...document.querySelectorAll<HTMLButtonElement>('.query-toolbar__actions button')]
.find((button) => button.textContent?.trim() === '查询')?.click()
await Promise.resolve()
resolveSecond([pendingReview])
await flushPromises()
expect(tableButtonByText('通过')).toBeDefined()
resolveFirst([])
await flushPromises()
expect(tableButtonByText('通过')).toBeDefined()
})
it('keeps the first operation column unfixed so it cannot cover a 320px table viewport', async () => {
mount(CustomersView, { attachTo: document.body, global: { plugins: [pinia, ElementPlus] } })
await flushPromises()
expect(document.querySelector('.el-table__fixed')).toBeNull()
})
})