84 lines
3.3 KiB
TypeScript
84 lines
3.3 KiB
TypeScript
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 {
|
||
|
|
getPlatformTenant,
|
||
|
|
listPlatformTenants,
|
||
|
|
listTenantQualifications,
|
||
|
|
type PlatformTenantResource,
|
||
|
|
} from '@/api/platformIam'
|
||
|
|
import { useAccessPreviewStore } from '@/stores/accessPreview'
|
||
|
|
import { useAuthStore } from '@/stores/auth'
|
||
|
|
import CustomersView from './CustomersView.vue'
|
||
|
|
|
||
|
|
vi.mock('@/api/platformIam', () => ({
|
||
|
|
changePlatformTenantStatus: vi.fn(),
|
||
|
|
createPlatformTenant: vi.fn(),
|
||
|
|
getPlatformTenant: vi.fn(),
|
||
|
|
listPlatformTenantOrderCounts: vi.fn(),
|
||
|
|
listPlatformTenants: vi.fn(),
|
||
|
|
listTenantQualifications: vi.fn(),
|
||
|
|
submitPlatformTenantReview: vi.fn(),
|
||
|
|
updatePlatformTenant: vi.fn(),
|
||
|
|
uploadPlatformTenantQualification: vi.fn(),
|
||
|
|
}))
|
||
|
|
|
||
|
|
class ResizeObserverStub implements ResizeObserver {
|
||
|
|
observe() {}
|
||
|
|
unobserve() {}
|
||
|
|
disconnect() {}
|
||
|
|
}
|
||
|
|
|
||
|
|
const fullTenant: PlatformTenantResource = {
|
||
|
|
id: '8', tenantCode: 'TEN8', tenantName: '柏悦物流', status: 'PROFILE_REQUIRED',
|
||
|
|
legalName: '柏悦物流有限公司', 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: null,
|
||
|
|
}
|
||
|
|
|
||
|
|
function tableButtonByText(text: string) {
|
||
|
|
return [...document.querySelectorAll<HTMLButtonElement>('.el-table__body button')]
|
||
|
|
.find((button) => button.textContent?.trim() === text)
|
||
|
|
}
|
||
|
|
|
||
|
|
enableAutoUnmount(afterEach)
|
||
|
|
|
||
|
|
describe('CustomersView', () => {
|
||
|
|
let pinia: ReturnType<typeof createPinia>
|
||
|
|
|
||
|
|
beforeEach(() => {
|
||
|
|
vi.stubGlobal('ResizeObserver', ResizeObserverStub)
|
||
|
|
document.body.innerHTML = ''
|
||
|
|
pinia = createPinia()
|
||
|
|
setActivePinia(pinia)
|
||
|
|
const auth = useAuthStore()
|
||
|
|
auth.token = 'token'
|
||
|
|
auth.permissions = ['platform:customer:list', 'platform:customer:view', 'platform:customer:edit']
|
||
|
|
useAccessPreviewStore().initializeAfterLogin()
|
||
|
|
vi.mocked(listPlatformTenants).mockResolvedValue({
|
||
|
|
records: [{ ...fullTenant, contactPhone: '138****8000', contactEmail: 'o***@example.com' }],
|
||
|
|
page: 1, size: 10, total: 1, pages: 1,
|
||
|
|
})
|
||
|
|
vi.mocked(getPlatformTenant).mockResolvedValue(fullTenant)
|
||
|
|
vi.mocked(listTenantQualifications).mockResolvedValue([])
|
||
|
|
})
|
||
|
|
|
||
|
|
it('loads the complete customer detail before editing masked list fields', async () => {
|
||
|
|
mount(CustomersView, { attachTo: document.body, global: { plugins: [pinia, ElementPlus] } })
|
||
|
|
await flushPromises()
|
||
|
|
|
||
|
|
tableButtonByText('编辑')?.click()
|
||
|
|
await flushPromises()
|
||
|
|
|
||
|
|
expect(getPlatformTenant).toHaveBeenCalledWith(fullTenant.id)
|
||
|
|
const phone = document.querySelector<HTMLInputElement>('input[placeholder="请输入手机号或固定电话"]')
|
||
|
|
const email = document.querySelector<HTMLInputElement>('input[placeholder="如:contact@example.com"]')
|
||
|
|
expect(phone?.value).toBe(fullTenant.contactPhone)
|
||
|
|
expect(email?.value).toBe(fullTenant.contactEmail)
|
||
|
|
})
|
||
|
|
})
|