This commit is contained in:
2026-08-12 12:35:32 +08:00
parent 11e085e30f
commit 4fb8b85c13
22 changed files with 161 additions and 47 deletions
@@ -5,6 +5,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
import TruckAppointmentsView from './TruckAppointmentsView.vue'
import { listTruckAppointments } from '../api/platformTrucking'
import type { TruckAppointmentResource } from '../types'
import { useAuthStore } from '@/core/auth/auth'
import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'
@@ -24,6 +25,10 @@ describe('TruckAppointmentsView', () => {
beforeEach(() => {
vi.mocked(listTruckAppointments).mockReset().mockResolvedValue({ records: [row], page: 1, size: 20, total: 1, pages: 1 })
setActivePinia(createPinia())
useAuthStore().permissions = [
'platform:firstleg:truck-appointment:view',
'platform:firstleg:truck-appointment:edit',
]
})
it('loads the real list and renders relationship snapshots', async () => {
@@ -58,6 +63,20 @@ describe('TruckAppointmentsView', () => {
expect(source).toContain("appointmentActionLabel('编辑', row as TruckAppointmentResource)")
})
it('does not expose a technical carrier id when the business name is unavailable', async () => {
vi.mocked(listTruckAppointments).mockResolvedValue({
records: [{ ...row, carrierName: '', carrierId: 'carrier-77' }],
page: 1,
size: 20,
total: 1,
pages: 1,
})
const wrapper = mount(TruckAppointmentsView, { global: { plugins: [ElementPlus] } })
await flushPromises()
expect(wrapper.text()).toContain('已关联承运商')
expect(wrapper.text()).not.toContain('carrier-77')
})
it('uses the table toolbar for create and keeps a single empty state', () => {
expect(source).toContain('<template #toolbar-actions>')
expect(source).not.toContain('<template #toolbar-start>')
@@ -67,8 +86,16 @@ describe('TruckAppointmentsView', () => {
})
it('shows the two frequent row actions directly without a more menu', () => {
expect(source).toContain("v-if=\"access.can('platform:firstleg:truck-appointment:view')\"")
expect(source).toContain('<Eye :size="15" />详情')
expect(source).toContain('<Pencil :size="15" />编辑')
expect(source).not.toContain('MoreHorizontal')
})
it('hides the detail action when the account lacks the backend view permission', async () => {
useAuthStore().permissions = ['platform:firstleg:truck-appointment:list']
const wrapper = mount(TruckAppointmentsView, { global: { plugins: [ElementPlus] } })
await flushPromises()
expect(wrapper.find('button[aria-label="查看 TA-9001"]').exists()).toBe(false)
})
})