优化
This commit is contained in:
@@ -4,11 +4,12 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { ApiResponseError } from '@/shared/api/http'
|
||||
import TruckAppointmentForm from './TruckAppointmentForm.vue'
|
||||
import type { SaveTruckAppointmentRequest, TruckAppointmentResource } from '../types'
|
||||
import { listSuppliers } from '@/modules/suppliers'
|
||||
import { getOceanBooking } from '@/modules/ocean-bookings'
|
||||
import { listTruckAppointmentCandidates } from '../api/platformTrucking'
|
||||
|
||||
vi.mock('@/modules/suppliers', () => ({
|
||||
listSuppliers: vi.fn().mockResolvedValue({ records: [{ id: 'carrier-1', name: '平台拖车公司', category: 'TRUCKING', status: 'ACTIVE' }] }),
|
||||
listSuppliers: vi.fn().mockResolvedValue({ records: [{ id: 'carrier-1', name: '平台拖车公司', category: 'TRUCKING', status: 'ACTIVE', contactName: '张调度', phone: '13800000001' }, { id: 'carrier-2', name: '第二车队', category: 'TRUCKING', status: 'ACTIVE', contactName: '李调度', phone: '13800000002' }] }),
|
||||
}))
|
||||
vi.mock('@/modules/ocean-bookings', () => ({
|
||||
getOceanBooking: vi.fn(),
|
||||
@@ -156,15 +157,61 @@ describe('TruckAppointmentForm booking-only behavior', () => {
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('offers only RMB for domestic trucking payables', async () => {
|
||||
const wrapper = mount(TruckAppointmentForm, {
|
||||
props: { modelValue: { ...model, payableAmount: '88.00', currency: 'RMB' } },
|
||||
global: { plugins: [ElementPlus] },
|
||||
})
|
||||
it('starts with five main fields and optional collapsed dispatch information', async () => {
|
||||
const wrapper = mount(TruckAppointmentForm, { props: { modelValue: { ...model } }, global: { plugins: [ElementPlus] } })
|
||||
await flushPromises()
|
||||
const currencySelect = wrapper.findAllComponents({ name: 'ElSelect' }).find((select) => select.props('placeholder') === '请选择币种')!
|
||||
expect(currencySelect.props('modelValue')).toBe('RMB')
|
||||
expect(currencySelect.findAllComponents({ name: 'ElOption' }).map(option => option.props('value'))).toEqual(['RMB'])
|
||||
expect(wrapper.findAll('.appointment-grid > .el-form-item').filter(item => !item.element.closest('details'))).toHaveLength(5)
|
||||
expect((wrapper.get('details').element as HTMLDetailsElement).open).toBe(false)
|
||||
for (const label of ['门店名称', '司机身份证号', '毛重(kg)', '体积(m³)', '在途分钟', '托盘数量', '查看附件引用']) expect(wrapper.text()).not.toContain(label)
|
||||
expect(wrapper.findAllComponents({ name: 'ElSelect' })).toHaveLength(2)
|
||||
expect(wrapper.text()).toContain('元')
|
||||
expect(wrapper.text()).toContain('保存预约')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('copies supplier contacts and replaces or clears them when switching suppliers', async () => {
|
||||
const wrapper = mount(TruckAppointmentForm, { props: { modelValue: { ...model } }, global: { plugins: [ElementPlus] } })
|
||||
await flushPromises()
|
||||
expect(listSuppliers).toHaveBeenCalledWith({ page: 1, size: 200, category: 'TRUCKING', status: 'ACTIVE' })
|
||||
const supplier = wrapper.findAllComponents({ name: 'ElSelect' })[1]!
|
||||
supplier.vm.$emit('update:modelValue', 'carrier-1')
|
||||
await flushPromises()
|
||||
expect(wrapper.emitted('update:modelValue')!.at(-1)![0]).toMatchObject({ carrierId: 'carrier-1', fleetContact: '张调度', fleetPhone: '13800000001', currency: 'RMB' })
|
||||
expect(wrapper.get('[aria-label="车队联系方式"]').text()).toContain('张调度')
|
||||
supplier.vm.$emit('update:modelValue', 'carrier-2')
|
||||
await flushPromises()
|
||||
expect(wrapper.emitted('update:modelValue')!.at(-1)![0]).toMatchObject({ carrierId: 'carrier-2', fleetContact: '李调度', fleetPhone: '13800000002' })
|
||||
supplier.vm.$emit('update:modelValue', '')
|
||||
await flushPromises()
|
||||
expect(wrapper.emitted('update:modelValue')!.at(-1)![0]).toMatchObject({ carrierId: null, carrierName: null, fleetContact: null, fleetPhone: null })
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('preserves saved contact overrides and supplementary values when editing', async () => {
|
||||
const wrapper = mount(TruckAppointmentForm, { props: { modelValue: { ...model, oceanBookingId: 'booking-1', carrierId: 'carrier-1', fleetContact: '本次调度', fleetPhone: '13900000000', storeName: '目的门店', grossWeightKg: '120.00' }, resource: resource('appointment-1', 'booking-1') }, global: { plugins: [ElementPlus] } })
|
||||
await flushPromises()
|
||||
wrapper.findAllComponents({ name: 'ElSelect' })[1]!.vm.$emit('update:modelValue', 'carrier-1')
|
||||
await flushPromises()
|
||||
expect(wrapper.get('[aria-label="车队联系方式"]').text()).toContain('本次调度')
|
||||
expect(wrapper.text()).toContain('其他已存资料')
|
||||
expect(wrapper.findAllComponents({ name: 'ElInput' }).some(input => input.props('modelValue') === '目的门店')).toBe(true)
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('keeps amount validation at two decimal places on the displayed field', async () => {
|
||||
const valid = { ...model, oceanBookingId: 'booking-1', carrierId: 'carrier-1', plannedLoadingAt: '2026-09-19T09:00:00', payableAmount: '100.00' }
|
||||
const wrapper = mount(TruckAppointmentForm, { props: { modelValue: valid }, global: { plugins: [ElementPlus] } })
|
||||
await flushPromises()
|
||||
await wrapper.setProps({ modelValue: { ...valid, billOfLadingNo: 'BL-1', payableAmount: '100.001' } })
|
||||
await flushPromises()
|
||||
expect(wrapper.findAllComponents({ name: 'ElInput' }).find(input => input.props('placeholder') === '请输入应付拖车费')?.props('modelValue')).toBe('100.001')
|
||||
const rule = wrapper.findComponent({ name: 'ElForm' }).props('rules').payableAmount[0]
|
||||
const reject = vi.fn()
|
||||
rule.validator(null, '100.001', reject)
|
||||
expect(reject).toHaveBeenCalledWith(expect.objectContaining({ message: expect.stringContaining('应付拖车费') }))
|
||||
const accept = vi.fn()
|
||||
rule.validator(null, '100.00', accept)
|
||||
expect(accept).toHaveBeenCalledWith(undefined)
|
||||
wrapper.unmount()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user