import { defineComponent } from 'vue' import { mount } from '@vue/test-utils' import { describe, expect, it, vi } from 'vitest' import OwnedBusinessDetailLayout from './OwnedBusinessDetailLayout.vue' import OwnedBusinessPhotosDialog from './OwnedBusinessPhotosDialog.vue' import OwnedBusinessOperationsDialog from './OwnedBusinessOperationsDialog.vue' const Surface = defineComponent({ template: '
' }) const Tabs = defineComponent({ props: ['modelValue'], emits: ['update:modelValue'], template: '
' }) const Pane = defineComponent({ props: ['name', 'label'], template: '
' }) const Dialog = defineComponent({ props: ['width', 'showConfirm', 'beforeClose'], template: '
' }) const global = { stubs: { AdminPage: Surface, DetailPageLayout: Surface, AppDialog: Dialog, ElTabs: Tabs, ElTabPane: Pane, ElButton: Surface }, directives: { loading: () => {} } } describe('OwnedBusiness presentation boundaries', () => { it('mounts only the selected one of the three independent detail regions', async () => { const wrapper = mount(OwnedBusinessDetailLayout, { global, props: { dispatchNo: 'DS-OWN-1' }, slots: { task: '

task-facts

', route: '

route-facts

', history: '

history-facts

' } }) expect(wrapper.findAllComponents(Pane).map(pane => pane.props('label'))).toEqual(['任务与车辆信息', '路线货物与凭证', '操作记录']) expect(wrapper.text()).toContain('task-facts'); expect(wrapper.text()).not.toContain('history-facts') wrapper.findComponent(Tabs).vm.$emit('update:modelValue', 'history'); await wrapper.vm.$nextTick() expect(wrapper.text()).toContain('history-facts'); expect(wrapper.text()).not.toContain('task-facts') }) it('preserves seven real prototype photo roles without demo images or uploaded claims', () => { const wrapper = mount(OwnedBusinessPhotosDialog, { global, props: { modelValue: true } }) expect(wrapper.findComponent(Dialog).props('width')).toBe('760px') expect(wrapper.findComponent(Dialog).props('showConfirm')).toBe(false) expect(wrapper.findAll('section[aria-label]').map(section => section.attributes('aria-label'))).toEqual(['装车现场', '装车清单', '出车前检查', '驾驶证附件', '签收凭证', '起始油耗表盘', '结束油耗表盘']) expect(wrapper.findAll('img')).toHaveLength(0); expect(wrapper.text()).not.toContain('已上传') }) it('blocks a close while busy and delegates unsaved-result decisions to the owner', async () => { const guard = vi.fn(), done = vi.fn() const wrapper = mount(OwnedBusinessPhotosDialog, { global, props: { modelValue: true, busy: true, beforeClose: guard } }) const close = wrapper.findComponent(Dialog).props('beforeClose') as (done: () => void) => void close(done); expect(guard).not.toHaveBeenCalled(); expect(done).not.toHaveBeenCalled() await wrapper.setProps({ busy: false }); close(done) expect(guard).toHaveBeenCalledWith(done); expect(done).not.toHaveBeenCalled() }) it('keeps an unknown operations request until its owner explicitly handles closing', async () => { const done = vi.fn(), guard = vi.fn() const wrapper = mount(OwnedBusinessOperationsDialog, { global, props: { modelValue: true, pending: true } }) const close = wrapper.findComponent(Dialog).props('beforeClose') as (done: () => void) => void close(done); expect(done).not.toHaveBeenCalled() await wrapper.setProps({ beforeClose: guard }); close(done) expect(guard).toHaveBeenCalledWith(done); expect(done).not.toHaveBeenCalled() }) })