优化
This commit is contained in:
@@ -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