import { KeepAlive, defineComponent, h, ref } from 'vue' import { flushPromises, mount } from '@vue/test-utils' import { expect, it, vi } from 'vitest' import { getRelabelOrder } from '../api/relabelOrders' import RelabelOrderDetailView from './RelabelOrderDetailView.vue' vi.mock('vue-router', () => ({ useRoute: () => ({ params: { orderId: 'RL-1' } }), useRouter: () => ({ push: vi.fn() }) })) vi.mock('@/core/access/accessPreview', () => ({ useAccessPreviewStore: () => ({ can: () => false }) })) vi.mock('../api/relabelOrders', () => ({ getRelabelOrder: vi.fn(), confirmRelabelCompletion: vi.fn(), getRelabelReviewTask: vi.fn(), returnRelabelForRework: vi.fn(), downloadRelabelCompletionPhoto: vi.fn(), downloadRelabelPdf: vi.fn(), uploadRelabelPdf: vi.fn() })) it('reloads authoritative status when a cached detail tab is reopened without double loading initially', async () => { vi.mocked(getRelabelOrder).mockResolvedValueOnce({ application: { id: '1', relabelNo: 'RL-1', status: 'PENDING_REVIEW' }, items: [], history: [] }) .mockResolvedValueOnce({ application: { id: '1', relabelNo: 'RL-1', status: 'PENDING_PROCESSING' }, items: [], history: [] }) const active = ref(true) const Host = defineComponent({ setup: () => () => h(KeepAlive, null, { default: () => active.value ? h(RelabelOrderDetailView) : h('div') }) }) const wrapper = mount(Host, { global: { stubs: { OverseasReadOnlyDetail: true, AppDialog: true } } }) await flushPromises() expect(getRelabelOrder).toHaveBeenCalledTimes(1) expect(wrapper.findComponent({ name: 'OverseasReadOnlyDetail' }).props('statusText')).toBe('待审核') active.value = false await flushPromises() active.value = true await flushPromises() expect(getRelabelOrder).toHaveBeenCalledTimes(2) expect(wrapper.findComponent({ name: 'OverseasReadOnlyDetail' }).props('statusText')).toBe('待处理') wrapper.unmount() })