179 lines
5.5 KiB
TypeScript
179 lines
5.5 KiB
TypeScript
// @vitest-environment jsdom
|
||
import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
|
||
import { computed, ref } from 'vue'
|
||
import { flushPromises, mount } from '@vue/test-utils'
|
||
import { createPinia, setActivePinia } from 'pinia'
|
||
import { createMemoryHistory, createRouter } from 'vue-router'
|
||
import { i18n } from '@/i18n'
|
||
import zh from '@/i18n/locales/zh'
|
||
import TodoListView from './TodoListView.vue'
|
||
import type { InboxItem } from '@/types'
|
||
import { setDesktopScreen } from '@/test/screen'
|
||
|
||
/**
|
||
* 列表上「点标题进单据、点操作列才弹处理框」这一拆。
|
||
*
|
||
* 钉三件:
|
||
* 1. 抄送需处理那一行点标题 → 去 work-detail,不再弹处理框;
|
||
* 2. 同行点「处理」→ 弹处理框,路由不动;
|
||
* 3. 只需阅那一行点标题 → 仍然去单据详情(老口径不变)。
|
||
*/
|
||
const api = vi.hoisted(() => ({
|
||
listInbox: vi.fn(),
|
||
countProcessing: vi.fn(),
|
||
executeInbox: vi.fn(),
|
||
markInboxSeen: vi.fn(),
|
||
handleRead: vi.fn(),
|
||
listProcesses: vi.fn(),
|
||
deleteJob: vi.fn()
|
||
}))
|
||
vi.mock('@/api', () => ({
|
||
taskAPI: {
|
||
listInbox: api.listInbox,
|
||
countProcessing: api.countProcessing,
|
||
executeInbox: api.executeInbox,
|
||
markInboxSeen: api.markInboxSeen
|
||
},
|
||
designAPI: { listProcesses: api.listProcesses },
|
||
workAPI: { handleRead: api.handleRead, deleteJob: api.deleteJob }
|
||
}))
|
||
|
||
const phoneShell = ref(false)
|
||
vi.mock('@/composables/useMobileShell', () => ({
|
||
useMobileShell: () => ({ phoneShell: computed(() => phoneShell.value) }),
|
||
useChromeless: () => ({ chromeless: computed(() => false) })
|
||
}))
|
||
|
||
function row(over: Partial<InboxItem> = {}): InboxItem {
|
||
return {
|
||
id: 'c1',
|
||
job: 'jc1',
|
||
work: 'wc1',
|
||
title: '差旅报销 · 202611240018',
|
||
status: 'pending',
|
||
process: 'p1',
|
||
process_name: '费用报销流程',
|
||
category: '',
|
||
category_name: '财务',
|
||
serial: 'BX202611240018',
|
||
activity: 'a1',
|
||
activity_name: '财务复核',
|
||
activity_type: 'approve',
|
||
activity_token: '',
|
||
person: 'pe1',
|
||
identity: 'i1',
|
||
identity_name: '我',
|
||
creator_person: '张锦杰',
|
||
creator_unit_name: '财务中心',
|
||
route_name: '',
|
||
route_name_list: [],
|
||
opinion: '请核对发票',
|
||
form: 'f1',
|
||
start_time: '2026-11-24 09:12:00',
|
||
view_time: null,
|
||
expire_time: null,
|
||
expired: false,
|
||
press_count: 0,
|
||
inbox_kind: 'cc_action',
|
||
unread: true,
|
||
requires_action: true,
|
||
sender: '陈妮',
|
||
read_type: 'cc',
|
||
...over
|
||
} as InboxItem
|
||
}
|
||
|
||
async function render(rows: InboxItem[]) {
|
||
const pinia = createPinia()
|
||
setActivePinia(pinia)
|
||
api.listInbox.mockResolvedValue({
|
||
items: rows,
|
||
total: rows.length,
|
||
page: 1,
|
||
page_size: 20,
|
||
pages: 1
|
||
})
|
||
api.countProcessing.mockResolvedValue({
|
||
total: rows.length,
|
||
expired: 0,
|
||
unread: rows.length,
|
||
approval: 0,
|
||
cc_action: 0,
|
||
cc_read: 0
|
||
})
|
||
api.listProcesses.mockResolvedValue([])
|
||
const router = createRouter({
|
||
history: createMemoryHistory(),
|
||
routes: [
|
||
{ path: '/todo', name: 'my-todo', component: TodoListView },
|
||
{ path: '/todo/:id', name: 'todo-detail', component: { template: '<div />' } },
|
||
{ path: '/work/:job', name: 'work-detail', component: { template: '<div />' } },
|
||
{ path: '/start', component: { template: '<div />' } }
|
||
]
|
||
})
|
||
await router.push('/todo')
|
||
await router.isReady()
|
||
const wrapper = mount(TodoListView, {
|
||
attachTo: document.body,
|
||
global: { plugins: [pinia, router, i18n], stubs: { Teleport: true, teleport: true } }
|
||
})
|
||
await flushPromises()
|
||
return { wrapper, router }
|
||
}
|
||
|
||
beforeAll(() => {
|
||
setDesktopScreen()
|
||
window.matchMedia = ((query: string) => ({
|
||
matches: query.includes('min-width'),
|
||
media: query,
|
||
onchange: null,
|
||
addEventListener: vi.fn(),
|
||
removeEventListener: vi.fn(),
|
||
addListener: vi.fn(),
|
||
removeListener: vi.fn(),
|
||
dispatchEvent: vi.fn()
|
||
})) as unknown as typeof window.matchMedia
|
||
})
|
||
|
||
beforeEach(() => {
|
||
phoneShell.value = false
|
||
document.body.innerHTML = ''
|
||
i18n.global.setLocaleMessage('zh', zh)
|
||
i18n.global.locale.value = 'zh'
|
||
vi.clearAllMocks()
|
||
api.markInboxSeen.mockResolvedValue({ marked: 1 })
|
||
api.handleRead.mockResolvedValue(undefined)
|
||
})
|
||
|
||
describe('抄送需处理那一行的两种点击', () => {
|
||
it('点标题进单据详情,不弹处理框', async () => {
|
||
const { wrapper, router } = await render([row()])
|
||
await wrapper.find('[data-test="oa-todo-title"]').trigger('click')
|
||
await flushPromises()
|
||
expect(router.currentRoute.value.name).toBe('work-detail')
|
||
expect(router.currentRoute.value.params.job).toBe('jc1')
|
||
// 处理框没弹:那条路径上的提交接口一个都没碰
|
||
expect(api.handleRead).not.toHaveBeenCalled()
|
||
})
|
||
|
||
it('点操作列「处理」弹框,路由不动', async () => {
|
||
const { wrapper, router } = await render([row()])
|
||
const button = wrapper.find('[data-test="oa-open-cc_action"]')
|
||
expect(button.exists()).toBe(true)
|
||
await button.trigger('click')
|
||
await flushPromises()
|
||
expect(router.currentRoute.value.name).toBe('my-todo')
|
||
// 弹层里的提交按钮存在即算弹框;不在这里真提交
|
||
expect(wrapper.find('[data-test="oa-handle-submit"]').exists()).toBe(true)
|
||
})
|
||
|
||
it('只需阅那一行点标题仍然进单据详情', async () => {
|
||
const { wrapper, router } = await render([
|
||
row({ id: 'c2', inbox_kind: 'cc_read', requires_action: false, read_type: 'cc' })
|
||
])
|
||
await wrapper.find('[data-test="oa-todo-title"]').trigger('click')
|
||
await flushPromises()
|
||
expect(router.currentRoute.value.name).toBe('work-detail')
|
||
})
|
||
})
|