This commit is contained in:
2026-08-07 20:07:37 +08:00
parent 28d0b81c5a
commit 99413ee155
27 changed files with 1065 additions and 595 deletions
@@ -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: '京东物流' })
})
})