优化
This commit is contained in:
@@ -188,4 +188,31 @@ describe('PartnersView real API integration', () => {
|
||||
expect(wrapper.text()).toContain('重新加载')
|
||||
expect(wrapper.text()).not.toContain('深圳示例贸易有限公司')
|
||||
})
|
||||
|
||||
it('keeps the latest detail when an older partner request finishes last', async () => {
|
||||
const secondPartner = { ...partner, id: '19002', partnerCode: 'CUS-002', partnerName: '上海示例贸易有限公司' }
|
||||
let resolveFirst!: (value: PlatformPartnerResource) => void
|
||||
let resolveSecond!: (value: PlatformPartnerResource) => void
|
||||
vi.mocked(getPlatformPartner).mockImplementation((partnerId) => new Promise((resolve) => {
|
||||
if (String(partnerId) === String(partner.id)) resolveFirst = resolve
|
||||
else resolveSecond = resolve
|
||||
}))
|
||||
const wrapper = await mountView()
|
||||
const vm = wrapper.vm as unknown as {
|
||||
detailOpen: boolean
|
||||
detail: PlatformPartnerResource | null
|
||||
openDetail(row: PlatformPartnerResource): Promise<void>
|
||||
}
|
||||
|
||||
void vm.openDetail(partner)
|
||||
vm.detailOpen = false
|
||||
await wrapper.vm.$nextTick()
|
||||
void vm.openDetail(secondPartner)
|
||||
resolveSecond(secondPartner)
|
||||
await flushPromises()
|
||||
resolveFirst(partner)
|
||||
await flushPromises()
|
||||
|
||||
expect(vm.detail?.partnerCode).toBe('CUS-002')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -40,6 +40,7 @@ const total = ref(0)
|
||||
const loadError = ref<ApiErrorDetails | null>(null)
|
||||
const statusLoadingIds = ref(new Set<string>())
|
||||
let loadSequence = 0
|
||||
let detailSequence = 0
|
||||
|
||||
type PartnerFilters = QueryModel & {
|
||||
keyword: string
|
||||
@@ -261,17 +262,21 @@ function savePayload(): SavePlatformPartnerRequest {
|
||||
}
|
||||
|
||||
async function openDetail(row: PlatformPartnerResource) {
|
||||
const sequence = ++detailSequence
|
||||
detailOpen.value = true
|
||||
detailLoading.value = true
|
||||
detail.value = null
|
||||
try {
|
||||
detail.value = await getPlatformPartner(row.id)
|
||||
const result = await getPlatformPartner(row.id)
|
||||
if (sequence !== detailSequence || !detailOpen.value) return
|
||||
detail.value = result
|
||||
} catch (error) {
|
||||
if (sequence !== detailSequence) return
|
||||
const meta = getApiErrorDetails(error, '往来单位详情加载失败')
|
||||
ElMessage.error(meta.requestId ? `${meta.message}(requestId: ${meta.requestId})` : meta.message)
|
||||
detailOpen.value = false
|
||||
} finally {
|
||||
detailLoading.value = false
|
||||
if (sequence === detailSequence) detailLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -335,6 +340,12 @@ function formatUpdatedAt(value?: string | null) {
|
||||
}
|
||||
|
||||
watch([page, pageSize], () => { void loadPartners() })
|
||||
watch(detailOpen, (open) => {
|
||||
if (open) return
|
||||
detailSequence += 1
|
||||
detailLoading.value = false
|
||||
detail.value = null
|
||||
})
|
||||
onMounted(() => {
|
||||
void loadPartners()
|
||||
})
|
||||
|
||||
@@ -2,13 +2,14 @@ import ElementPlus from 'element-plus'
|
||||
import { createPinia, setActivePinia } from 'pinia'
|
||||
import { enableAutoUnmount, flushPromises, mount } from '@vue/test-utils'
|
||||
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { listPlatformExpressCompanies, type PlatformExpressCompanyResource } from '@/modules/master-data/express-companies/api/platformExpressCompanies'
|
||||
import { getPlatformExpressCompany, listPlatformExpressCompanies, type PlatformExpressCompanyResource } from '@/modules/master-data/express-companies/api/platformExpressCompanies'
|
||||
import { useAccessPreviewStore } from '@/core/access/accessPreview'
|
||||
import { useAuthStore } from '@/core/auth/auth'
|
||||
import ExpressCompaniesView from './ExpressCompaniesView.vue'
|
||||
|
||||
vi.mock('@/modules/master-data/express-companies/api/platformExpressCompanies', () => ({
|
||||
listPlatformExpressCompanies: vi.fn(),
|
||||
getPlatformExpressCompany: vi.fn(),
|
||||
createPlatformExpressCompany: vi.fn(),
|
||||
downloadPlatformExpressCompanyImportTemplate: vi.fn(),
|
||||
importPlatformExpressCompanies: vi.fn(),
|
||||
@@ -74,6 +75,7 @@ describe('ExpressCompaniesView query and table migration', () => {
|
||||
vi.mocked(listPlatformExpressCompanies).mockReset().mockResolvedValue({
|
||||
records: [company], page: 1, size: 20, total: 1, pages: 1,
|
||||
})
|
||||
vi.mocked(getPlatformExpressCompany).mockReset().mockResolvedValue(company)
|
||||
})
|
||||
|
||||
it('renders the shared toolbar and data table without a summary strip', async () => {
|
||||
@@ -110,4 +112,28 @@ describe('ExpressCompaniesView query and table migration', () => {
|
||||
expect(document.body.textContent).toContain('新增快递公司')
|
||||
expect(document.body.textContent).not.toContain('请先在筛选条件中选择所属企业')
|
||||
})
|
||||
|
||||
it('keeps the latest express company selected for editing', async () => {
|
||||
const secondCompany = { ...company, id: '19002', companyCode: 'JD', companyName: '京东物流' }
|
||||
let resolveFirst!: (value: PlatformExpressCompanyResource) => void
|
||||
let resolveSecond!: (value: PlatformExpressCompanyResource) => void
|
||||
vi.mocked(getPlatformExpressCompany).mockImplementation((companyId) => new Promise((resolve) => {
|
||||
if (String(companyId) === String(company.id)) resolveFirst = resolve
|
||||
else resolveSecond = resolve
|
||||
}))
|
||||
const wrapper = await mountView()
|
||||
const vm = wrapper.vm as unknown as {
|
||||
form: { companyCode: string; companyName: string }
|
||||
openEdit(row: PlatformExpressCompanyResource): Promise<void>
|
||||
}
|
||||
|
||||
void vm.openEdit(company)
|
||||
void vm.openEdit(secondCompany)
|
||||
resolveSecond(secondCompany)
|
||||
await flushPromises()
|
||||
resolveFirst(company)
|
||||
await flushPromises()
|
||||
|
||||
expect(vm.form).toMatchObject({ companyCode: 'JD', companyName: '京东物流' })
|
||||
})
|
||||
})
|
||||
|
||||
@@ -56,6 +56,7 @@ const queryFields = computed<QueryField[]>(() => [
|
||||
},
|
||||
])
|
||||
let loadSequence = 0
|
||||
let editorLoadSequence = 0
|
||||
|
||||
const emptyForm = (): SavePlatformExpressCompanyRequest & { id: string } => ({
|
||||
id: '',
|
||||
@@ -161,6 +162,7 @@ function applyFilters(model: QueryModel) {
|
||||
}
|
||||
|
||||
function openCreate() {
|
||||
editorLoadSequence += 1
|
||||
Object.assign(form, emptyForm())
|
||||
captureBaseline()
|
||||
editorOpen.value = true
|
||||
@@ -184,13 +186,17 @@ function assignEditor(row: PlatformExpressCompanyResource) {
|
||||
}
|
||||
|
||||
async function openEdit(row: PlatformExpressCompanyResource) {
|
||||
const sequence = ++editorLoadSequence
|
||||
const id = String(row.id)
|
||||
const pending = new Set(editLoadingIds.value)
|
||||
pending.add(id)
|
||||
editLoadingIds.value = pending
|
||||
try {
|
||||
assignEditor(await getPlatformExpressCompany(row.id))
|
||||
const result = await getPlatformExpressCompany(row.id)
|
||||
if (sequence !== editorLoadSequence) return
|
||||
assignEditor(result)
|
||||
} catch (error) {
|
||||
if (sequence !== editorLoadSequence) return
|
||||
const details = getApiErrorDetails(error, '快递公司详情加载失败,请稍后重试')
|
||||
ElMessage.error(details.requestId ? `${details.message}(requestId: ${details.requestId})` : details.message)
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user