优化
This commit is contained in:
@@ -15,11 +15,19 @@ import { useAccessPreviewStore } from '@/core/access/accessPreview'
|
||||
import { useAuthStore } from '@/core/auth/auth'
|
||||
import CustomerDetailView from './CustomerDetailView.vue'
|
||||
|
||||
const { routerPush } = vi.hoisted(() => ({ routerPush: vi.fn() }))
|
||||
const { routerPush, routeControl } = vi.hoisted(() => ({
|
||||
routerPush: vi.fn(),
|
||||
routeControl: { setTenantId: (_tenantId: string) => {} },
|
||||
}))
|
||||
|
||||
vi.mock('vue-router', async (importOriginal) => ({
|
||||
...await importOriginal<typeof import('vue-router')>(),
|
||||
useRoute: () => ({ params: { tenantId: '8' } }),
|
||||
...await (async () => {
|
||||
const { reactive } = await import('vue')
|
||||
const route = reactive({ params: { tenantId: '8' } })
|
||||
routeControl.setTenantId = (tenantId: string) => { route.params.tenantId = tenantId }
|
||||
return { useRoute: () => route }
|
||||
})(),
|
||||
useRouter: () => ({ push: routerPush }),
|
||||
}))
|
||||
|
||||
@@ -59,6 +67,7 @@ describe('CustomerDetailView', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
routeControl.setTenantId('8')
|
||||
vi.stubGlobal('ResizeObserver', ResizeObserverStub)
|
||||
Object.defineProperty(HTMLElement.prototype, 'scrollIntoView', { configurable: true, value: vi.fn() })
|
||||
Object.defineProperty(URL, 'createObjectURL', { configurable: true, value: vi.fn(() => 'blob:qualification-preview') })
|
||||
@@ -121,7 +130,7 @@ describe('CustomerDetailView', () => {
|
||||
.find((button) => button.textContent?.trim() === '计费规则')
|
||||
billingTab?.click()
|
||||
await flushPromises()
|
||||
expect(document.body.textContent).toContain('暂无计费规则查看权限')
|
||||
expect(document.body.textContent).toContain('暂无尺寸计算规则查看权限')
|
||||
expect(document.body.textContent).not.toContain('计费规则尚未接入')
|
||||
})
|
||||
|
||||
@@ -159,4 +168,28 @@ describe('CustomerDetailView', () => {
|
||||
expect(listPlatformFirstLegOrders).toHaveBeenCalledTimes(3)
|
||||
expect(listPlatformFirstLegOrders).toHaveBeenLastCalledWith({ tenantId: tenant.id, page: 1, size: 10 })
|
||||
})
|
||||
|
||||
it('reloads a reused detail view and ignores the previous customer response', async () => {
|
||||
const secondTenant = { ...tenant, id: '9', tenantCode: 'TEN9', tenantName: '远航供应链', legalName: '远航供应链有限公司' }
|
||||
let resolveFirstTenant!: (value: PlatformTenantResource) => void
|
||||
const firstTenantRequest = new Promise<PlatformTenantResource>((resolve) => { resolveFirstTenant = resolve })
|
||||
vi.mocked(getPlatformTenant).mockImplementation((tenantId) => tenantId === '8' ? firstTenantRequest : Promise.resolve(secondTenant))
|
||||
vi.mocked(listTenantQualifications).mockResolvedValue([])
|
||||
vi.mocked(listPlatformTenantMembers).mockResolvedValue([])
|
||||
vi.mocked(listPlatformTenantOrderCounts).mockImplementation(async (tenantIds) => [{ tenantId: tenantIds[0], orderCount: 0 }])
|
||||
vi.mocked(listPlatformFirstLegOrders).mockResolvedValue({ records: [], page: 1, size: 10, total: 0, pages: 0 })
|
||||
|
||||
mount(CustomerDetailView, { attachTo: document.body, global: { plugins: [pinia, ElementPlus] } })
|
||||
await flushPromises()
|
||||
routeControl.setTenantId('9')
|
||||
await flushPromises()
|
||||
|
||||
expect(getPlatformTenant).toHaveBeenCalledWith('9')
|
||||
expect(document.body.textContent).toContain('远航供应链')
|
||||
|
||||
resolveFirstTenant(tenant)
|
||||
await flushPromises()
|
||||
expect(document.body.textContent).toContain('远航供应链')
|
||||
expect(document.body.textContent).not.toContain('柏悦物流')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user