36 lines
3.7 KiB
TypeScript
36 lines
3.7 KiB
TypeScript
import ElementPlus from 'element-plus'
|
|
import { mount } from '@vue/test-utils'
|
|
import { expect, it } from 'vitest'
|
|
import DispatchArrangeFields from './DispatchArrangeFields.vue'
|
|
import type { ArrangeGroup, CargoLine, PreviewGroup } from '../dispatchContracts'
|
|
import { destination } from '../dispatchTestFixtures'
|
|
const cargo = (sourceKey: string, customerId = 'C1'): CargoLine => ({ sourceKey, customerId, inboundCode: `IN-${sourceKey}`, sourceOrigin: null }) as CargoLine
|
|
function values() {
|
|
const preview: PreviewGroup = { groupKey: 'group-1', customerId: 'C1', customerName: '客户甲', destination: destination(), groupCargoHash: 'group-cargo', cargo: [cargo('A'), cargo('B')], externalFreightHash: 'external-hash', externalQuotes: [], feeCoverageCargoHash: 'coverage-hash', feeSources: [{ financeFeeId: 'fee-1', customerId: 'C1', currency: 'USD', amount: 100, sourceVersion: 2, sourceHash: 'fee-hash', status: 'ACTIVE', services: ['DELIVERY_FEE', 'LOADING_FEE'], sourceKeys: ['A'] }], requiredServices: ['DELIVERY_FEE'], blockReasons: [] }
|
|
const group: ArrangeGroup = { groupKey: 'group-1', groupCargoHash: 'group-cargo', plannedDeliveryAt: '', deliveryMethod: '', waybillNo: null, carrierName: null, pickupMethod: '', loadingType: 'PALLET', vehicleType: null, vehicleSize: null, appointmentAccount: null, sellerName: null, remark: null, externalFreightHash: 'external-hash', feeCoverageCargoHash: 'coverage-hash', feeCoverage: [], fees: ['DELIVERY_FEE', 'LOADING_FEE', 'APPOINTMENT_FEE'].map(feeType => ({ feeType, feeName: feeType, direction: 'RECEIVABLE', currency: 'USD', amount: null })) }
|
|
return { preview, group }
|
|
}
|
|
it('requires explicit per-service coverage and preserves uncovered cargo instead of treating a partial fee as full coverage', async () => {
|
|
const { preview, group } = values()
|
|
const wrapper = mount(DispatchArrangeFields, { props: { modelValue: [group], preview: [preview], disabled: false }, global: { plugins: [ElementPlus] } })
|
|
const covered = (wrapper.vm as unknown as { covered(index: number, preview: PreviewGroup, service: string): boolean }).covered
|
|
expect(covered(0, preview, 'DELIVERY_FEE')).toBe(false)
|
|
await wrapper.get('input[type="checkbox"]').setValue(true)
|
|
expect(group.feeCoverage).toEqual([{ financeFeeId: 'fee-1', sourceVersion: 2, sourceHash: 'fee-hash', services: ['DELIVERY_FEE'] }])
|
|
expect(covered(0, preview, 'DELIVERY_FEE')).toBe(false)
|
|
preview.feeSources[0]!.sourceKeys.push('B'); expect(covered(0, preview, 'DELIVERY_FEE')).toBe(true)
|
|
expect(covered(0, preview, 'LOADING_FEE')).toBe(false)
|
|
preview.feeSources[0]!.customerId = 'C2'; expect(covered(0, preview, 'DELIVERY_FEE')).toBe(false); wrapper.unmount()
|
|
})
|
|
it('matches external quotes to the original customer and inbound source and shows only applicable additional fees', async () => {
|
|
const { preview, group } = values(); preview.cargo = [cargo('A')]
|
|
preview.externalQuotes = [{ customerId: 'C2', groupKey: 'group-1', bookingNo: 'BOOK-1', inboundCode: 'IN-A', currency: 'USD', amount: 100, sourceHash: 'external-source' }]
|
|
const wrapper = mount(DispatchArrangeFields, { props: { modelValue: [group], preview: [preview], disabled: false }, global: { plugins: [ElementPlus] } })
|
|
const state = wrapper.vm as unknown as { covered(index: number, preview: PreviewGroup, service: string): boolean }
|
|
expect(state.covered(0, preview, 'DELIVERY_FEE')).toBe(false)
|
|
expect(wrapper.findAll('.el-input-number')).toHaveLength(1)
|
|
preview.externalQuotes[0]!.customerId = 'C1'; expect(state.covered(0, preview, 'DELIVERY_FEE')).toBe(true)
|
|
group.loadingType = 'FLOOR'; group.appointmentAccount = 'BUY_APPOINTMENT'; await wrapper.setProps({ modelValue: [{ ...group }] })
|
|
expect(wrapper.findAll('.el-input-number')).toHaveLength(2); expect(wrapper.text()).toContain('卖家姓名'); wrapper.unmount()
|
|
})
|