import ElementPlus from 'element-plus' import { enableAutoUnmount, flushPromises, mount } from '@vue/test-utils' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { getPallet, listReceivingOverseasWarehouses } from '../api/pallets' import PalletDetailView from './PalletDetailView.vue' vi.mock('vue-router', () => ({ useRoute: () => ({ params: { palletId: 'internal-pallet-id' }, query: { warehouseId: 'internal-warehouse-id' } }), useRouter: () => ({ push: vi.fn() }), })) vi.mock('../api/pallets', () => ({ getPallet: vi.fn(), listReceivingOverseasWarehouses: vi.fn() })) enableAutoUnmount(afterEach) describe('PalletDetailView business identifiers', () => { beforeEach(() => { vi.mocked(getPallet).mockReset() vi.mocked(listReceivingOverseasWarehouses).mockResolvedValue({ records: [], page: 1, size: 200, total: 0, pages: 0 }) }) it('does not expose the route ID while loading or after a failed load', async () => { let rejectLoad!: (cause: Error) => void vi.mocked(getPallet).mockReturnValue(new Promise((_, reject) => { rejectLoad = reject })) const wrapper = mount(PalletDetailView, { global: { plugins: [ElementPlus] } }) expect(wrapper.get('.overseas-detail-title').text()).toContain('—') expect(wrapper.text()).not.toContain('internal-pallet-id') rejectLoad(new Error('暂时无法加载')) await flushPromises() expect(wrapper.text()).toContain('托盘详情加载失败') expect(wrapper.text()).not.toContain('internal-pallet-id') }) it('renders the pallet code inside the dense detail and keeps unavailable location codes empty', async () => { vi.mocked(getPallet).mockResolvedValue({ id: 'internal-pallet-id', warehouseId: 'internal-warehouse-id', customerId: 'customer-1', locationId: 'internal-location-id', palletCode: 'PALLET-LAX-001', palletType: 'WOOD', fbaWarehouseCode: 'ONT8', capacityCbm: 2, unitPrice: 10, status: 'IDLE', version: 1, }) const wrapper = mount(PalletDetailView, { global: { plugins: [ElementPlus] } }) await flushPromises() expect(wrapper.get('.admin-density .overseas-detail-title').text()).toContain('PALLET-LAX-001') const location = wrapper.findAll('.density-fields dt').find(item => item.text() === '库位')! expect(location.element.nextElementSibling?.textContent).toBe('—') expect(wrapper.text()).not.toMatch(/internal-(pallet|warehouse|location)-id/) }) })