This commit is contained in:
2026-08-06 14:55:17 +08:00
parent a813426588
commit 4ac0adac62
18 changed files with 379 additions and 352 deletions
@@ -5,8 +5,6 @@ import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vites
import { listPlatformExpressCompanies, type PlatformExpressCompanyResource } from '@/modules/master-data/express-companies/api/platformExpressCompanies'
import { useAccessPreviewStore } from '@/core/access/accessPreview'
import { useAuthStore } from '@/core/auth/auth'
import QueryToolbar from '@/shared/components/QueryToolbar.vue'
import { listPlatformTenants, type PlatformTenantResource } from '../../../iam/api/platformIam'
import ExpressCompaniesView from './ExpressCompaniesView.vue'
vi.mock('@/modules/master-data/express-companies/api/platformExpressCompanies', () => ({
@@ -16,8 +14,6 @@ vi.mock('@/modules/master-data/express-companies/api/platformExpressCompanies',
changePlatformExpressCompanyStatus: vi.fn(),
}))
vi.mock('../../../iam/api/platformIam', () => ({ listPlatformTenants: vi.fn() }))
class ResizeObserverStub implements ResizeObserver {
observe() {}
unobserve() {}
@@ -38,7 +34,7 @@ function createMemoryStorage(): Storage {
const company: PlatformExpressCompanyResource = {
id: '19001',
tenantId: 10001,
tenantId: 0,
companyCode: 'SF',
companyName: '顺丰速运',
servicePhone: '95338',
@@ -49,16 +45,6 @@ const company: PlatformExpressCompanyResource = {
updatedAt: '2026-07-31T10:20:00',
}
const tenant = (id: number | string, tenantName: string): PlatformTenantResource => ({
id, tenantCode: String(id), tenantName, status: 'ACTIVE', legalName: tenantName,
legalRepresentative: null, unifiedSocialCreditCode: null, contactName: null,
contactPhone: null, contactEmail: null, servicePackage: null, contactWechat: null,
salesOwnerName: null, paymentTermDays: null, enterpriseType: null, establishedDate: null,
registeredCapital: null, registeredCapitalCurrency: null, registeredAddress: null,
internalRemark: null, createdAt: null, approvedAt: null,
})
const snowflakeTenantId = '9223372036854775806'
async function mountView() {
vi.stubGlobal('localStorage', createMemoryStorage())
vi.stubGlobal('sessionStorage', createMemoryStorage())
@@ -83,9 +69,6 @@ describe('ExpressCompaniesView query and table migration', () => {
beforeEach(() => {
vi.stubGlobal('ResizeObserver', ResizeObserverStub)
document.body.innerHTML = ''
vi.mocked(listPlatformTenants).mockReset().mockResolvedValue({
records: [tenant(10001, '默认企业'), tenant(snowflakeTenantId, '雪花企业')], page: 1, size: 200, total: 2, pages: 1,
})
vi.mocked(listPlatformExpressCompanies).mockReset().mockResolvedValue({
records: [company], page: 1, size: 20, total: 1, pages: 1,
})
@@ -95,12 +78,12 @@ describe('ExpressCompaniesView query and table migration', () => {
const wrapper = await mountView()
expect(wrapper.find('.query-toolbar').exists()).toBe(true)
expect(wrapper.find('input[aria-label="所属企业"]').exists()).toBe(true)
expect(wrapper.find('input[aria-label="所属企业"]').exists()).toBe(false)
expect(wrapper.find('.data-table').exists()).toBe(true)
expect(wrapper.text()).toContain('顺丰速运')
expect(wrapper.text()).toContain('全部企业 · 共 1 家快递公司')
expect(wrapper.text()).toContain('平台公共数据 · 共 1 家快递公司')
expect(wrapper.find('.metric-strip').exists()).toBe(false)
expect(listPlatformExpressCompanies).toHaveBeenCalledWith(undefined, 1, 20, '', '')
expect(listPlatformExpressCompanies).toHaveBeenCalledWith(1, 20, '', '')
})
it('does not request with edited filters until search is submitted', async () => {
@@ -113,18 +96,16 @@ describe('ExpressCompaniesView query and table migration', () => {
await searchButton?.trigger('click')
await flushPromises()
expect(listPlatformExpressCompanies).toHaveBeenLastCalledWith(undefined, 1, 20, '顺丰', '')
expect(listPlatformExpressCompanies).toHaveBeenLastCalledWith(1, 20, '顺丰', '')
})
it('preserves a snowflake tenant id as a string when switching enterprises', async () => {
it('opens the create form without selecting an enterprise', async () => {
const wrapper = await mountView()
const toolbar = wrapper.findComponent(QueryToolbar)
const model = { tenantId: snowflakeTenantId, keyword: '', status: '' }
toolbar.vm.$emit('update:modelValue', model)
toolbar.vm.$emit('search', model)
const createButton = wrapper.findAll('button').find((button) => button.text().trim() === '新增快递公司')
await createButton?.trigger('click')
await flushPromises()
expect(listPlatformExpressCompanies).toHaveBeenLastCalledWith(snowflakeTenantId, 1, 20, '', '')
expect(document.body.textContent).toContain('新增快递公司')
expect(document.body.textContent).not.toContain('请先在筛选条件中选择所属企业')
})
})