import ElementPlus from 'element-plus' import { readFileSync } from 'node:fs' import { resolve } from 'node:path' import { createPinia, setActivePinia } from 'pinia' import { enableAutoUnmount, flushPromises, mount } from '@vue/test-utils' import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vitest' 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' const expressCompaniesSource = readFileSync(resolve(process.cwd(), 'src/modules/master-data/express-companies/pages/ExpressCompaniesView.vue'), 'utf8') vi.mock('@/modules/master-data/express-companies/api/platformExpressCompanies', () => ({ listPlatformExpressCompanies: vi.fn(), getPlatformExpressCompany: vi.fn(), createPlatformExpressCompany: vi.fn(), downloadPlatformExpressCompanyImportTemplate: vi.fn(), importPlatformExpressCompanies: vi.fn(), updatePlatformExpressCompany: vi.fn(), changePlatformExpressCompanyStatus: vi.fn(), })) class ResizeObserverStub implements ResizeObserver { observe() {} unobserve() {} disconnect() {} } function createMemoryStorage(): Storage { const values = new Map() return { get length() { return values.size }, clear: () => values.clear(), getItem: (key) => values.get(key) ?? null, key: (index) => [...values.keys()][index] ?? null, removeItem: (key) => values.delete(key), setItem: (key, value) => values.set(key, value), } } const company: PlatformExpressCompanyResource = { id: '19001', tenantId: 0, companyCode: 'SF', companyName: '顺丰速运', servicePhone: '95338', website: 'https://www.sf-express.com', trackingUrlTemplate: 'https://example.com/track/{trackingNo}', status: 'ACTIVE', remark: '测试数据', updatedAt: '2026-07-31T10:20:00', } async function mountView() { vi.stubGlobal('localStorage', createMemoryStorage()) vi.stubGlobal('sessionStorage', createMemoryStorage()) const pinia = createPinia() setActivePinia(pinia) const auth = useAuthStore() auth.token = 'token' auth.permissions = ['platform:express:list', 'platform:express:create', 'platform:express:edit', 'platform:express:status'] useAccessPreviewStore().initializeAfterLogin() const wrapper = mount(ExpressCompaniesView, { attachTo: document.body, global: { plugins: [pinia, ElementPlus] }, }) await flushPromises() return wrapper } enableAutoUnmount(afterEach) afterAll(() => vi.unstubAllGlobals()) describe('ExpressCompaniesView query and table migration', () => { it('renders edit and status as shared outlined text buttons', () => { const actions = expressCompaniesSource.slice(expressCompaniesSource.indexOf('