2026-08-04 13:32:08 +08:00
|
|
|
import ElementPlus from 'element-plus'
|
|
|
|
|
import { createPinia, setActivePinia } from 'pinia'
|
|
|
|
|
import { enableAutoUnmount, flushPromises, mount } from '@vue/test-utils'
|
|
|
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
|
import {
|
|
|
|
|
downloadTenantQualification,
|
|
|
|
|
getPlatformTenant,
|
2026-08-07 09:06:22 +08:00
|
|
|
listPlatformTenantMembers,
|
2026-08-04 13:32:08 +08:00
|
|
|
listPlatformTenantOrderCounts,
|
|
|
|
|
listTenantQualifications,
|
|
|
|
|
type PlatformTenantResource,
|
|
|
|
|
} from '@/modules/iam'
|
|
|
|
|
import { useAccessPreviewStore } from '@/core/access/accessPreview'
|
|
|
|
|
import { useAuthStore } from '@/core/auth/auth'
|
|
|
|
|
import CustomerDetailView from './CustomerDetailView.vue'
|
|
|
|
|
|
|
|
|
|
const { routerPush } = vi.hoisted(() => ({ routerPush: vi.fn() }))
|
|
|
|
|
|
|
|
|
|
vi.mock('vue-router', async (importOriginal) => ({
|
|
|
|
|
...await importOriginal<typeof import('vue-router')>(),
|
|
|
|
|
useRoute: () => ({ params: { tenantId: '8' } }),
|
|
|
|
|
useRouter: () => ({ push: routerPush }),
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
vi.mock('@/modules/iam', () => ({
|
|
|
|
|
changePlatformTenantStatus: vi.fn(),
|
|
|
|
|
downloadTenantQualification: vi.fn(),
|
|
|
|
|
getPlatformTenant: vi.fn(),
|
2026-08-07 09:06:22 +08:00
|
|
|
listPlatformTenantMembers: vi.fn(),
|
2026-08-04 13:32:08 +08:00
|
|
|
listPlatformTenantOrderCounts: vi.fn(),
|
|
|
|
|
listTenantQualifications: vi.fn(),
|
|
|
|
|
qualificationFileName: vi.fn((documentUrl: string) => documentUrl.split('/').at(-1) || '资质文件'),
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
class ResizeObserverStub implements ResizeObserver {
|
|
|
|
|
observe() {}
|
|
|
|
|
unobserve() {}
|
|
|
|
|
disconnect() {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const tenant: PlatformTenantResource = {
|
|
|
|
|
id: '8', tenantCode: 'TEN8', tenantName: '柏悦物流', status: 'ACTIVE', legalName: '柏悦物流有限公司',
|
|
|
|
|
legalRepresentative: '张三', unifiedSocialCreditCode: '91440300MA5ABCDE12', contactName: '张三',
|
|
|
|
|
contactPhone: '13800138000', contactEmail: 'ops@example.com', servicePackage: '基础版', contactWechat: 'baiyue-ops',
|
|
|
|
|
salesOwnerName: '李四', paymentTermDays: 30, enterpriseType: '有限责任公司', establishedDate: '2020-01-01',
|
|
|
|
|
registeredCapital: 1000, registeredCapitalCurrency: 'CNY', registeredAddress: '深圳市宝安区', internalRemark: '重点客户',
|
|
|
|
|
createdAt: '2026-08-01T10:00:00', approvedAt: '2026-08-02T10:00:00',
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enableAutoUnmount(afterEach)
|
|
|
|
|
|
|
|
|
|
describe('CustomerDetailView', () => {
|
|
|
|
|
let pinia: ReturnType<typeof createPinia>
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
vi.clearAllMocks()
|
|
|
|
|
vi.stubGlobal('ResizeObserver', ResizeObserverStub)
|
2026-08-05 15:54:59 +08:00
|
|
|
Object.defineProperty(HTMLElement.prototype, 'scrollIntoView', { configurable: true, value: vi.fn() })
|
2026-08-04 13:32:08 +08:00
|
|
|
Object.defineProperty(URL, 'createObjectURL', { configurable: true, value: vi.fn(() => 'blob:qualification-preview') })
|
|
|
|
|
Object.defineProperty(URL, 'revokeObjectURL', { configurable: true, value: vi.fn() })
|
|
|
|
|
document.body.innerHTML = ''
|
|
|
|
|
pinia = createPinia()
|
|
|
|
|
setActivePinia(pinia)
|
|
|
|
|
const auth = useAuthStore()
|
|
|
|
|
auth.token = 'token'
|
|
|
|
|
auth.permissions = ['platform:customer:view', 'platform:user:list', 'platform:order:list']
|
|
|
|
|
useAccessPreviewStore().initializeAfterLogin()
|
|
|
|
|
vi.mocked(getPlatformTenant).mockResolvedValue(tenant)
|
|
|
|
|
vi.mocked(listTenantQualifications).mockResolvedValue([{
|
|
|
|
|
id: 'qualification-1', tenantId: tenant.id, qualificationType: 'BUSINESS_LICENSE', certificateNo: tenant.unifiedSocialCreditCode,
|
|
|
|
|
documentUrl: '/files/license.png', status: 'SUPERSEDED', reviewComment: '已替换', validTo: null,
|
|
|
|
|
}])
|
2026-08-07 09:06:22 +08:00
|
|
|
vi.mocked(listPlatformTenantMembers).mockResolvedValue([{
|
|
|
|
|
membershipId: 'member-1', userId: 'user-1', authUserId: 'auth-1', username: 'merchant_admin', displayName: '张三',
|
|
|
|
|
phone: '13800138000', email: 'ops@example.com', memberType: 'OWNER', memberNo: null, status: 'ACTIVE', roleIds: [], roleNames: ['企业管理员'],
|
|
|
|
|
}])
|
2026-08-04 13:32:08 +08:00
|
|
|
vi.mocked(listPlatformTenantOrderCounts).mockResolvedValue([{ tenantId: tenant.id, orderCount: 12 }])
|
|
|
|
|
vi.mocked(downloadTenantQualification).mockResolvedValue(new Blob(['image'], { type: 'image/png' }))
|
|
|
|
|
})
|
|
|
|
|
|
2026-08-07 09:06:22 +08:00
|
|
|
it('renders enterprise users and includes the owner in customer statistics', async () => {
|
2026-08-04 13:32:08 +08:00
|
|
|
mount(CustomerDetailView, { attachTo: document.body, global: { plugins: [pinia, ElementPlus] } })
|
|
|
|
|
await flushPromises()
|
|
|
|
|
|
|
|
|
|
expect([...document.querySelectorAll('.detail-tabs button')].map((button) => button.textContent?.trim())).toEqual([
|
|
|
|
|
'基本信息', '业务概况', '运单记录', '财务账单', '操作日志', '计费规则',
|
|
|
|
|
])
|
2026-08-07 09:06:22 +08:00
|
|
|
expect(document.body.textContent).toContain('企业用户1人')
|
|
|
|
|
expect(document.body.textContent).toContain('1 人正常使用')
|
|
|
|
|
expect(document.body.textContent).toContain('merchant_admin')
|
|
|
|
|
expect(document.body.textContent).toContain('企业管理员')
|
|
|
|
|
expect(listPlatformTenantMembers).toHaveBeenCalledWith(tenant.id)
|
2026-08-04 13:32:08 +08:00
|
|
|
expect(document.body.textContent).toContain('已替换')
|
|
|
|
|
expect(document.body.textContent).toContain('12票')
|
2026-08-05 15:54:59 +08:00
|
|
|
|
|
|
|
|
const billingTab = [...document.querySelectorAll<HTMLButtonElement>('.detail-tabs button')]
|
|
|
|
|
.find((button) => button.textContent?.trim() === '计费规则')
|
|
|
|
|
billingTab?.click()
|
|
|
|
|
await flushPromises()
|
|
|
|
|
expect(document.body.textContent).toContain('暂无计费规则查看权限')
|
|
|
|
|
expect(document.body.textContent).not.toContain('计费规则尚未接入')
|
2026-08-04 13:32:08 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('opens an authenticated qualification preview', async () => {
|
|
|
|
|
mount(CustomerDetailView, { attachTo: document.body, global: { plugins: [pinia, ElementPlus] } })
|
|
|
|
|
await flushPromises()
|
|
|
|
|
|
|
|
|
|
const fileButton = document.querySelector<HTMLButtonElement>('.qualification-list button')
|
|
|
|
|
fileButton?.click()
|
|
|
|
|
await flushPromises()
|
|
|
|
|
|
|
|
|
|
expect(downloadTenantQualification).toHaveBeenCalledWith(tenant.id, '/files/license.png')
|
|
|
|
|
expect(document.querySelector('img[alt="license.png预览"]')).not.toBeNull()
|
|
|
|
|
})
|
|
|
|
|
})
|