2026-08-12 16:40:09 +08:00
|
|
|
import ElementPlus from 'element-plus'
|
|
|
|
|
import { createPinia, setActivePinia } from 'pinia'
|
|
|
|
|
import { flushPromises, mount } from '@vue/test-utils'
|
|
|
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
2026-08-12 16:31:46 +08:00
|
|
|
import { readFileSync } from 'node:fs'
|
|
|
|
|
import { resolve } from 'node:path'
|
2026-08-12 16:40:09 +08:00
|
|
|
import { useAccessPreviewStore } from '@/core/access/accessPreview'
|
|
|
|
|
import { useAuthStore } from '@/core/auth/auth'
|
2026-08-30 17:43:03 +08:00
|
|
|
import { getFinanceSettlement, listFinancePayableSettlements, listFinanceReceivableSettlements } from '@/modules/finance'
|
2026-08-20 18:02:24 +08:00
|
|
|
import { adjustContainerFee, createContainerFee, listApplicableFeeItems, listContainerCostDetails, listContainerFeeSupplierOptions, listContainerFees, uploadContainerFeePaymentVoucher } from '../api/containerFees'
|
2026-08-12 16:40:09 +08:00
|
|
|
import ContainerFeesPanel from './ContainerFeesPanel.vue'
|
|
|
|
|
|
|
|
|
|
vi.mock('../api/containerFees', async (importOriginal) => {
|
|
|
|
|
const actual = await importOriginal<typeof import('../api/containerFees')>()
|
2026-08-20 18:02:24 +08:00
|
|
|
return { ...actual, listContainerFees: vi.fn(), listApplicableFeeItems: vi.fn(), listContainerFeeSupplierOptions: vi.fn(), listContainerCostDetails: vi.fn(), createContainerFee: vi.fn(), adjustContainerFee: vi.fn(), uploadContainerFeePaymentVoucher: vi.fn(), approveContainerFee: vi.fn(), rejectContainerFee: vi.fn(), voidContainerFee: vi.fn() }
|
2026-08-12 16:40:09 +08:00
|
|
|
})
|
2026-08-30 17:43:03 +08:00
|
|
|
vi.mock('@/modules/finance', () => ({
|
2026-08-27 21:48:15 +08:00
|
|
|
getFinanceSettlement: vi.fn(), listFinancePayableSettlements: vi.fn(), listFinanceReceivableSettlements: vi.fn(),
|
|
|
|
|
}))
|
2026-08-12 16:31:46 +08:00
|
|
|
|
|
|
|
|
const panel = readFileSync(resolve(process.cwd(), 'src/modules/loading-lists/components/ContainerFeesPanel.vue'), 'utf8')
|
|
|
|
|
const detail = readFileSync(resolve(process.cwd(), 'src/modules/loading-lists/components/LoadingListDetailDrawer.vue'), 'utf8')
|
|
|
|
|
|
2026-08-12 16:40:09 +08:00
|
|
|
class ResizeObserverStub { observe() {}; unobserve() {}; disconnect() {} }
|
|
|
|
|
function memoryStorage(): Storage { const values = new Map<string, string>(); return { get length() { return values.size }, clear: () => values.clear(), getItem: (key) => values.get(key) ?? null, key: (index) => [...values.keys()][index] ?? null, removeItem: (key) => values.delete(key), setItem: (key, value) => values.set(key, value) } }
|
2026-08-12 17:29:35 +08:00
|
|
|
async function mountPanel(permissions: string[], customers = [{ accountId: '11', customerName: '客户A' }], containerBookingId = '99') {
|
2026-08-12 16:40:09 +08:00
|
|
|
const pinia = createPinia(); setActivePinia(pinia)
|
|
|
|
|
const auth = useAuthStore(); auth.token = 'token'; auth.permissions = permissions
|
|
|
|
|
useAccessPreviewStore().initializeAfterLogin()
|
2026-09-02 17:07:03 +08:00
|
|
|
const wrapper = mount(ContainerFeesPanel, { attachTo: document.body, props: { planId: '9', containerBookingId, customers, businessReferences: [{ accountId: '11', customerName: '客户A', orderId: '501', orderNo: 'FL-501', inboundId: '601', inboundCode: 'NYEXX2608300001' }] }, global: { plugins: [pinia, ElementPlus] } })
|
2026-08-12 16:40:09 +08:00
|
|
|
await flushPromises(); return wrapper
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
vi.stubGlobal('ResizeObserver', ResizeObserverStub); vi.stubGlobal('localStorage', memoryStorage()); vi.stubGlobal('sessionStorage', memoryStorage())
|
|
|
|
|
vi.mocked(listContainerFees).mockReset().mockResolvedValue([]); vi.mocked(listApplicableFeeItems).mockReset().mockResolvedValue([])
|
2026-08-19 09:14:35 +08:00
|
|
|
vi.mocked(listContainerFeeSupplierOptions).mockReset().mockResolvedValue([])
|
2026-08-12 16:40:09 +08:00
|
|
|
vi.mocked(listContainerCostDetails).mockReset().mockResolvedValue([]); vi.mocked(createContainerFee).mockReset()
|
2026-08-18 17:40:40 +08:00
|
|
|
vi.mocked(adjustContainerFee).mockReset().mockResolvedValue({} as never)
|
2026-08-27 21:48:15 +08:00
|
|
|
vi.mocked(getFinanceSettlement).mockReset().mockResolvedValue({} as never)
|
|
|
|
|
vi.mocked(listFinancePayableSettlements).mockReset().mockResolvedValue([])
|
|
|
|
|
vi.mocked(listFinanceReceivableSettlements).mockReset().mockResolvedValue([])
|
2026-08-20 18:02:24 +08:00
|
|
|
vi.mocked(uploadContainerFeePaymentVoucher).mockReset().mockResolvedValue({ fileId: '9001', fileName: '付款凭证.pdf' })
|
2026-08-12 16:40:09 +08:00
|
|
|
document.body.innerHTML = ''
|
|
|
|
|
})
|
|
|
|
|
|
2026-08-12 16:31:46 +08:00
|
|
|
describe('ContainerFeesPanel contract', () => {
|
2026-08-18 16:39:44 +08:00
|
|
|
it('keeps fee controls and table utilities in compact aligned toolbars', () => {
|
|
|
|
|
expect(panel).toContain('class="fees-header__actions"')
|
|
|
|
|
expect(panel).toContain('class="customer-context"')
|
|
|
|
|
expect(panel).toContain('<template #toolbar-start><div class="fees-table-title">')
|
|
|
|
|
expect(panel).toContain('.fees-panel :deep(.data-table__toolbar) { min-height: 48px;')
|
|
|
|
|
})
|
|
|
|
|
|
2026-08-12 16:31:46 +08:00
|
|
|
it('is exposed from loading-list detail and derives customer context from real items', () => {
|
2026-08-12 17:29:35 +08:00
|
|
|
expect(detail).toContain(':container-booking-id="summary.containerBookingId"')
|
2026-08-12 16:31:46 +08:00
|
|
|
expect(detail).toContain('item.accountId')
|
|
|
|
|
expect(panel).toContain('该柜次包含多个客户,请先选择费用归属客户')
|
|
|
|
|
expect(panel).toContain('装柜明细缺少客户归属,无法安全维护费用')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('covers create, review, reject, approved adjustment and void actions', () => {
|
|
|
|
|
expect(panel).toContain('新增费用')
|
|
|
|
|
expect(panel).toContain("row.reviewStatus === 'PENDING'")
|
|
|
|
|
expect(panel).toContain('approveContainerFee')
|
|
|
|
|
expect(panel).toContain('rejectContainerFee')
|
|
|
|
|
expect(panel).toContain("row.reviewStatus === 'APPROVED'")
|
|
|
|
|
expect(panel).toContain('adjustContainerFee')
|
|
|
|
|
expect(panel).toContain('voidContainerFee')
|
2026-08-18 17:40:40 +08:00
|
|
|
expect(panel).toContain('调整仅允许修改业务日期和金额')
|
|
|
|
|
expect(panel).toContain('请先作废后新增')
|
2026-08-19 09:14:35 +08:00
|
|
|
expect(panel).toContain("row.supplierName || '服务端未返回'")
|
2026-08-12 16:31:46 +08:00
|
|
|
})
|
|
|
|
|
|
2026-08-18 17:40:40 +08:00
|
|
|
it('adjusts only business date and amount while preserving the approved snapshot', async () => {
|
|
|
|
|
const wrapper = await mountPanel(['firstleg:inbound:fee-detail:view', 'firstleg:inbound:fee-detail:edit'])
|
2026-08-19 09:14:35 +08:00
|
|
|
const item = { id: '2', loadingPlanId: '9', containerBookingId: '99', containerNo: null, feeItemId: '7', feeItemName: '拖车费', direction: 'PAYABLE' as const, supplierId: '41', supplierName: '承运商A', supplierCategory: 'TRUCKING' as const, businessDate: '2026-08-12', amount: 100, currency: 'CNY' as const, reviewStatus: 'APPROVED' as const, sourceStatus: 'ACTIVE' as const, sourceVersion: 3, remark: '原备注', reviewerName: null, reviewedAt: null, reviewReason: null }
|
2026-08-18 17:40:40 +08:00
|
|
|
const state = (wrapper.vm.$ as unknown as { setupState: { openAdjust(value: typeof item): void; save(): Promise<void>; form: { businessDate: string; amount: number } } }).setupState
|
|
|
|
|
state.openAdjust(item); await flushPromises()
|
|
|
|
|
state.form.businessDate = '2026-08-13'; state.form.amount = 120
|
|
|
|
|
await state.save()
|
|
|
|
|
expect(adjustContainerFee).toHaveBeenCalledWith('9', '11', '2', { expectedSourceVersion: 3, businessDate: '2026-08-13', amount: 120 })
|
|
|
|
|
expect(wrapper.text()).toContain('已审核费用仍可调整日期与金额')
|
|
|
|
|
})
|
|
|
|
|
|
2026-08-12 16:31:46 +08:00
|
|
|
it('shows only server allocations and supplier snapshots', () => {
|
|
|
|
|
expect(panel).toContain('listContainerCostDetails')
|
|
|
|
|
expect(panel).toContain('仅展示 Finance 已持久化结果')
|
|
|
|
|
expect(panel).toContain("cost.supplierName || '服务端未返回'")
|
|
|
|
|
expect(panel).toContain('尚无与该柜次关联的财务分摊结果')
|
|
|
|
|
expect(panel).not.toMatch(/allocatedAmount\s*=|allocationRate\s*=/)
|
2026-08-30 17:43:03 +08:00
|
|
|
expect(panel).toContain("orderNumbers.get(row.orderId) || '订单编码待补充'")
|
|
|
|
|
expect(panel).toContain("inboundCodes.get(row.inboundId) || '入仓码待补充'")
|
|
|
|
|
expect(panel).not.toContain("prop: 'orderId', label: '订单'")
|
|
|
|
|
expect(panel).not.toContain("prop: 'inboundId', label: '入库单'")
|
2026-08-12 16:31:46 +08:00
|
|
|
})
|
2026-08-12 16:40:09 +08:00
|
|
|
|
|
|
|
|
it('clears the previous customer context and ignores a late response', async () => {
|
|
|
|
|
let resolveFirst!: (value: Awaited<ReturnType<typeof listContainerFees>>) => void
|
|
|
|
|
vi.mocked(listContainerFees).mockImplementation((planId, accountId) => accountId === '11'
|
|
|
|
|
? new Promise((resolve) => { resolveFirst = resolve })
|
|
|
|
|
: Promise.resolve([]))
|
|
|
|
|
const wrapper = await mountPanel(['firstleg:inbound:fee-detail:view'], [{ accountId: '11', customerName: '客户A' }, { accountId: '22', customerName: '客户B' }])
|
|
|
|
|
const state = (wrapper.vm.$ as unknown as { setupState: { accountId: string; fees: unknown[]; costs: unknown[]; editorOpen: boolean } }).setupState
|
|
|
|
|
state.accountId = '11'; await flushPromises(); state.editorOpen = true
|
|
|
|
|
state.accountId = '22'; await flushPromises()
|
|
|
|
|
expect(state.fees).toEqual([]); expect(state.costs).toEqual([]); expect(state.editorOpen).toBe(false)
|
2026-08-19 09:14:35 +08:00
|
|
|
resolveFirst([{ id: 'old', loadingPlanId: '9', containerBookingId: '99', containerNo: null, feeItemId: '1', feeItemName: '旧客户费用', direction: 'RECEIVABLE', supplierId: null, supplierName: null, supplierCategory: null, businessDate: '2026-08-12', amount: 10, currency: 'CNY', reviewStatus: 'PENDING', sourceStatus: 'ACTIVE', sourceVersion: 1, remark: null, reviewerName: null, reviewedAt: null, reviewReason: null }])
|
2026-08-12 16:40:09 +08:00
|
|
|
await flushPromises()
|
|
|
|
|
expect(state.fees).toEqual([])
|
|
|
|
|
expect(listContainerCostDetails).not.toHaveBeenCalledWith('11', expect.anything())
|
|
|
|
|
})
|
|
|
|
|
|
2026-08-12 17:29:35 +08:00
|
|
|
it('uses the summary container ID when fee rows are empty', async () => {
|
|
|
|
|
vi.mocked(listContainerFees).mockResolvedValue([])
|
|
|
|
|
await mountPanel(['firstleg:inbound:fee-detail:view'])
|
|
|
|
|
expect(listContainerCostDetails).toHaveBeenCalledWith('11', '99')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('uses the summary container ID when fee rows agree', async () => {
|
|
|
|
|
vi.mocked(listContainerFees).mockResolvedValue([
|
2026-08-19 09:14:35 +08:00
|
|
|
{ id: '1', loadingPlanId: '9', containerBookingId: '99', containerNo: null, feeItemId: '1', feeItemName: '费用A', direction: 'RECEIVABLE', supplierId: null, supplierName: null, supplierCategory: null, businessDate: '2026-08-12', amount: 10, currency: 'CNY', reviewStatus: 'PENDING', sourceStatus: 'ACTIVE', sourceVersion: 1, remark: null, reviewerName: null, reviewedAt: null, reviewReason: null },
|
2026-08-12 17:29:35 +08:00
|
|
|
])
|
|
|
|
|
await mountPanel(['firstleg:inbound:fee-detail:view'])
|
|
|
|
|
expect(listContainerCostDetails).toHaveBeenCalledWith('11', '99')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('fails closed when fee rows disagree with the summary container', async () => {
|
|
|
|
|
vi.mocked(listContainerFees).mockResolvedValue([
|
2026-08-19 09:14:35 +08:00
|
|
|
{ id: '2', loadingPlanId: '9', containerBookingId: '100', containerNo: null, feeItemId: '2', feeItemName: '费用B', direction: 'PAYABLE', supplierId: '41', supplierName: '承运商A', supplierCategory: 'TRUCKING', businessDate: '2026-08-12', amount: 20, currency: 'CNY', reviewStatus: 'PENDING', sourceStatus: 'ACTIVE', sourceVersion: 1, remark: null, reviewerName: null, reviewedAt: null, reviewReason: null },
|
2026-08-12 17:29:35 +08:00
|
|
|
])
|
|
|
|
|
const wrapper = await mountPanel(['firstleg:inbound:fee-detail:view', 'firstleg:fee-item:view'])
|
|
|
|
|
expect(wrapper.text()).toContain('柜次费用加载失败')
|
|
|
|
|
expect(listContainerCostDetails).not.toHaveBeenCalled()
|
|
|
|
|
})
|
|
|
|
|
|
2026-08-12 16:40:09 +08:00
|
|
|
it('blocks write entry points without a selected customer or edit permission', async () => {
|
|
|
|
|
const wrapper = await mountPanel(['firstleg:inbound:fee-detail:view'], [{ accountId: '11', customerName: '客户A' }, { accountId: '22', customerName: '客户B' }])
|
|
|
|
|
const state = (wrapper.vm.$ as unknown as { setupState: { openCreate(): void; save(): Promise<void>; editorOpen: boolean } }).setupState
|
|
|
|
|
state.openCreate(); await state.save()
|
|
|
|
|
expect(state.editorOpen).toBe(false)
|
|
|
|
|
expect(createContainerFee).not.toHaveBeenCalled()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('hides all mutation buttons when permissions are missing', async () => {
|
|
|
|
|
vi.mocked(listContainerFees).mockResolvedValue([
|
2026-08-19 09:14:35 +08:00
|
|
|
{ id: '1', loadingPlanId: '9', containerBookingId: '99', containerNo: null, feeItemId: '1', feeItemName: '待审费用', direction: 'RECEIVABLE', supplierId: null, supplierName: null, supplierCategory: null, businessDate: '2026-08-12', amount: 10, currency: 'CNY', reviewStatus: 'PENDING', sourceStatus: 'ACTIVE', sourceVersion: 1, remark: null, reviewerName: null, reviewedAt: null, reviewReason: null },
|
|
|
|
|
{ id: '2', loadingPlanId: '9', containerBookingId: '99', containerNo: null, feeItemId: '2', feeItemName: '已审费用', direction: 'PAYABLE', supplierId: '41', supplierName: '承运商A', supplierCategory: 'TRUCKING', businessDate: '2026-08-12', amount: 20, currency: 'CNY', reviewStatus: 'APPROVED', sourceStatus: 'ACTIVE', sourceVersion: 1, remark: null, reviewerName: null, reviewedAt: null, reviewReason: null },
|
2026-08-12 16:40:09 +08:00
|
|
|
])
|
|
|
|
|
const wrapper = await mountPanel(['firstleg:inbound:fee-detail:view'])
|
2026-08-18 17:40:40 +08:00
|
|
|
for (const label of ['新增费用', '通过', '驳回', '调整', '作废']) expect(wrapper.findAll('button').some((button) => button.text() === label)).toBe(false)
|
2026-08-12 16:40:09 +08:00
|
|
|
})
|
2026-08-12 16:58:52 +08:00
|
|
|
|
2026-08-27 21:48:15 +08:00
|
|
|
it('hides adjustment and void actions for settled fees', async () => {
|
|
|
|
|
vi.mocked(listContainerFees).mockResolvedValue([
|
|
|
|
|
{ id: '1', loadingPlanId: '9', containerBookingId: '99', containerNo: null, feeItemId: '1', feeItemName: '海运费', direction: 'RECEIVABLE', supplierId: null, supplierName: null, supplierCategory: null, businessDate: '2026-08-12', amount: 300, currency: 'CNY', reviewStatus: 'APPROVED', sourceStatus: 'ACTIVE', sourceVersion: 1, remark: null, reviewerName: null, reviewedAt: null, reviewReason: null },
|
|
|
|
|
])
|
|
|
|
|
vi.mocked(listFinanceReceivableSettlements).mockResolvedValue([{ id: 'ar-1', status: 'PAID', paymentStatus: 'PAID' } as never])
|
|
|
|
|
vi.mocked(getFinanceSettlement).mockResolvedValue({ lines: [{ sourceType: 'CONTAINER_FEE', sourceFeeId: '1' }] } as never)
|
|
|
|
|
const wrapper = await mountPanel([
|
|
|
|
|
'firstleg:inbound:fee-detail:view', 'firstleg:inbound:fee-detail:edit', 'firstleg:inbound:fee-detail:review',
|
|
|
|
|
'platform:finance:settlement-ar:list',
|
|
|
|
|
])
|
|
|
|
|
expect(wrapper.findAll('button').some((button) => button.text() === '调整')).toBe(false)
|
|
|
|
|
expect(wrapper.findAll('button').some((button) => button.text() === '作废')).toBe(false)
|
|
|
|
|
expect(getFinanceSettlement).toHaveBeenCalledWith('ar-1')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('hides adjustment and void actions for directly paid payable fees', async () => {
|
|
|
|
|
vi.mocked(listContainerFees).mockResolvedValue([
|
|
|
|
|
{ id: '2', loadingPlanId: '9', containerBookingId: '99', containerNo: null, feeItemId: '1', feeItemName: '拖车费', direction: 'PAYABLE', supplierId: '41', supplierName: '承运商A', supplierCategory: 'TRUCKING', settlementMode: 'DIRECT_PAID', paidAt: '2026-08-12T10:00:00', paymentMethod: 'BANK_TRANSFER', paymentReferenceNo: 'BANK-1', paymentVoucherFileIds: ['9001'], businessDate: '2026-08-12', amount: 100, currency: 'CNY', reviewStatus: 'APPROVED', sourceStatus: 'ACTIVE', sourceVersion: 1, remark: null, reviewerName: null, reviewedAt: null, reviewReason: null },
|
|
|
|
|
])
|
|
|
|
|
const wrapper = await mountPanel(['firstleg:inbound:fee-detail:view', 'firstleg:inbound:fee-detail:edit', 'firstleg:inbound:fee-detail:review'])
|
|
|
|
|
expect(wrapper.findAll('button').some((button) => button.text() === '调整')).toBe(false)
|
|
|
|
|
expect(wrapper.findAll('button').some((button) => button.text() === '作废')).toBe(false)
|
|
|
|
|
})
|
|
|
|
|
|
2026-08-19 09:14:35 +08:00
|
|
|
it('keeps receivable usable when supplier permission is missing', async () => {
|
|
|
|
|
vi.mocked(listApplicableFeeItems).mockResolvedValue([{ id: '7', name: '操作费', feeCode: 'OPERATION', supplierCategory: 'TRUCKING', warehouseReceivable: true, warehousePayable: true, pickupReceivable: false, pickupPayable: false }])
|
2026-08-12 16:58:52 +08:00
|
|
|
const wrapper = await mountPanel(['firstleg:inbound:fee-detail:view', 'firstleg:inbound:fee-detail:edit', 'firstleg:fee-item:view'])
|
2026-08-19 09:14:35 +08:00
|
|
|
const state = (wrapper.vm.$ as unknown as { setupState: { openCreate(): void; form: { direction: string; supplierId: string | null } } }).setupState
|
2026-08-12 16:58:52 +08:00
|
|
|
state.openCreate(); await flushPromises()
|
2026-08-19 09:14:35 +08:00
|
|
|
expect(wrapper.text()).toContain('当前账号缺少供应商查看权限,仅可维护应收费用')
|
2026-08-12 16:58:52 +08:00
|
|
|
expect(listApplicableFeeItems).toHaveBeenCalledTimes(1)
|
2026-08-19 09:14:35 +08:00
|
|
|
expect(listContainerFeeSupplierOptions).not.toHaveBeenCalled()
|
2026-08-12 16:58:52 +08:00
|
|
|
expect(state.form.direction).toBe('RECEIVABLE')
|
|
|
|
|
})
|
|
|
|
|
|
2026-08-19 09:14:35 +08:00
|
|
|
it('isolates a supplier load failure and clears supplier fields for receivable', async () => {
|
|
|
|
|
vi.mocked(listApplicableFeeItems).mockResolvedValue([{ id: '7', name: '操作费', feeCode: 'TRUCKING', supplierCategory: 'TRUCKING', warehouseReceivable: true, warehousePayable: true, pickupReceivable: false, pickupPayable: false }])
|
|
|
|
|
vi.mocked(listContainerFeeSupplierOptions).mockRejectedValue(new Error('suppliers unavailable'))
|
|
|
|
|
const wrapper = await mountPanel(['firstleg:inbound:fee-detail:view', 'firstleg:inbound:fee-detail:edit', 'firstleg:fee-item:view', 'platform:supplier:list'])
|
|
|
|
|
const state = (wrapper.vm.$ as unknown as { setupState: { openCreate(): void; form: { direction: string; feeItemId: string; supplierId: string | null }; feeItems: unknown[] } }).setupState
|
2026-08-12 16:58:52 +08:00
|
|
|
state.openCreate(); await flushPromises()
|
|
|
|
|
expect(state.feeItems).toHaveLength(1)
|
2026-08-19 09:14:35 +08:00
|
|
|
state.form.direction = 'PAYABLE'; state.form.feeItemId = '7'; await flushPromises()
|
|
|
|
|
expect(wrapper.text()).toContain('供应商加载失败')
|
|
|
|
|
state.form.supplierId = '41'; state.form.direction = 'RECEIVABLE'; await flushPromises()
|
|
|
|
|
expect(state.form.supplierId).toBeNull()
|
2026-08-12 16:58:52 +08:00
|
|
|
})
|
|
|
|
|
|
2026-08-19 09:14:35 +08:00
|
|
|
it('submits only the selected supplier ID for payable fees', async () => {
|
|
|
|
|
vi.mocked(listApplicableFeeItems).mockResolvedValue([{ id: '7', name: '操作费', feeCode: 'TRUCKING', supplierCategory: 'TRUCKING', warehouseReceivable: true, warehousePayable: true, pickupReceivable: false, pickupPayable: false }])
|
|
|
|
|
vi.mocked(listContainerFeeSupplierOptions).mockResolvedValue([{ id: '41', supplierName: '承运商A', category: 'TRUCKING' }])
|
|
|
|
|
const wrapper = await mountPanel(['firstleg:inbound:fee-detail:view', 'firstleg:inbound:fee-detail:edit', 'firstleg:fee-item:view', 'platform:supplier:list'])
|
2026-08-20 18:02:24 +08:00
|
|
|
const state = (wrapper.vm.$ as unknown as { setupState: { openCreate(): void; save(): Promise<void>; form: { direction: string; feeItemId: string; supplierId: string | null; settlementMode: string | null; amount: number } } }).setupState
|
2026-08-12 16:58:52 +08:00
|
|
|
state.openCreate(); await flushPromises()
|
2026-08-20 18:02:24 +08:00
|
|
|
state.form.direction = 'PAYABLE'; state.form.feeItemId = '7'; await flushPromises(); state.form.supplierId = '41'; state.form.settlementMode = 'ON_ACCOUNT'; state.form.amount = 100
|
2026-08-12 16:58:52 +08:00
|
|
|
await state.save()
|
2026-08-20 18:02:24 +08:00
|
|
|
expect(createContainerFee).toHaveBeenCalledWith('9', '11', expect.objectContaining({ direction: 'PAYABLE', supplierId: '41', settlementMode: 'ON_ACCOUNT', paidAt: null, paymentMethod: null, paymentReferenceNo: null, paymentVoucherFileIds: null }))
|
2026-08-19 09:14:35 +08:00
|
|
|
expect(createContainerFee).not.toHaveBeenCalledWith(expect.anything(), expect.anything(), expect.objectContaining({ partnerId: expect.anything() }))
|
|
|
|
|
})
|
|
|
|
|
|
2026-08-19 09:42:12 +08:00
|
|
|
it('allows any loaded ACTIVE supplier when the payable fee item has no supplier category', async () => {
|
2026-08-19 09:14:35 +08:00
|
|
|
vi.mocked(listApplicableFeeItems).mockResolvedValue([{ id: '7', name: '未映射费用', feeCode: 'UNMAPPED', supplierCategory: null, warehouseReceivable: false, warehousePayable: true, pickupReceivable: false, pickupPayable: false }])
|
2026-08-19 09:42:12 +08:00
|
|
|
vi.mocked(listContainerFeeSupplierOptions).mockResolvedValue([{ id: '41', supplierName: '报关行', category: 'CUSTOMS' }])
|
2026-08-19 09:14:35 +08:00
|
|
|
const wrapper = await mountPanel(['firstleg:inbound:fee-detail:view', 'firstleg:inbound:fee-detail:edit', 'firstleg:fee-item:view', 'platform:supplier:list'])
|
2026-08-20 18:02:24 +08:00
|
|
|
const state = (wrapper.vm.$ as unknown as { setupState: { openCreate(): void; save(): Promise<void>; form: { direction: string; feeItemId: string; supplierId: string | null; settlementMode: string | null; amount: number } } }).setupState
|
2026-08-19 09:14:35 +08:00
|
|
|
state.openCreate(); await flushPromises()
|
2026-08-20 18:02:24 +08:00
|
|
|
state.form.direction = 'PAYABLE'; state.form.feeItemId = '7'; await flushPromises(); state.form.supplierId = '41'; state.form.settlementMode = 'ON_ACCOUNT'; state.form.amount = 100
|
2026-08-19 09:14:35 +08:00
|
|
|
await state.save(); await flushPromises()
|
2026-08-19 09:42:12 +08:00
|
|
|
expect(listContainerFeeSupplierOptions).toHaveBeenCalledWith(null)
|
2026-08-20 18:02:24 +08:00
|
|
|
expect(createContainerFee).toHaveBeenCalledWith('9', '11', expect.objectContaining({ direction: 'PAYABLE', supplierId: '41', settlementMode: 'ON_ACCOUNT', paidAt: null, paymentMethod: null, paymentReferenceNo: null, paymentVoucherFileIds: null }))
|
2026-08-19 09:14:35 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('fails closed when a supplier candidate does not match the fee-item category', async () => {
|
|
|
|
|
vi.mocked(listApplicableFeeItems).mockResolvedValue([{ id: '7', name: '拖车费', feeCode: 'TRUCKING', supplierCategory: 'TRUCKING', warehouseReceivable: false, warehousePayable: true, pickupReceivable: false, pickupPayable: false }])
|
|
|
|
|
vi.mocked(listContainerFeeSupplierOptions).mockResolvedValue([{ id: '41', supplierName: '报关行', category: 'CUSTOMS' }])
|
|
|
|
|
const wrapper = await mountPanel(['firstleg:inbound:fee-detail:view', 'firstleg:inbound:fee-detail:edit', 'firstleg:fee-item:view', 'platform:supplier:list'])
|
|
|
|
|
const state = (wrapper.vm.$ as unknown as { setupState: { openCreate(): void; save(): Promise<void>; form: { direction: string; feeItemId: string; supplierId: string | null; amount: number } } }).setupState
|
|
|
|
|
state.openCreate(); await flushPromises()
|
|
|
|
|
state.form.direction = 'PAYABLE'; state.form.feeItemId = '7'; await flushPromises(); state.form.supplierId = '41'; state.form.amount = 100
|
|
|
|
|
await state.save(); await flushPromises()
|
|
|
|
|
expect(createContainerFee).not.toHaveBeenCalled()
|
|
|
|
|
expect(document.body.textContent).toContain('所选供应商与费用项目要求的供应商类别不匹配')
|
2026-08-12 16:58:52 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('requires fee-item permission before opening a write form', async () => {
|
|
|
|
|
const wrapper = await mountPanel(['firstleg:inbound:fee-detail:view', 'firstleg:inbound:fee-detail:edit'])
|
|
|
|
|
const state = (wrapper.vm.$ as unknown as { setupState: { openCreate(): void; editorOpen: boolean } }).setupState
|
|
|
|
|
state.openCreate(); await flushPromises()
|
|
|
|
|
expect(state.editorOpen).toBe(false)
|
|
|
|
|
expect(wrapper.text()).toContain('当前账号缺少费用项目查看权限')
|
|
|
|
|
expect(listApplicableFeeItems).not.toHaveBeenCalled()
|
|
|
|
|
})
|
2026-08-20 18:02:24 +08:00
|
|
|
|
|
|
|
|
it('clears paid inputs for RECEIVABLE and ON_ACCOUNT and shows backend settlement semantics', async () => {
|
|
|
|
|
vi.mocked(listContainerFees).mockResolvedValue([{ id: '2', loadingPlanId: '9', containerBookingId: '99', containerNo: null, feeItemId: '7', feeItemName: '已付拖车费', direction: 'PAYABLE', supplierId: '41', supplierName: '承运商A', supplierCategory: 'TRUCKING', settlementMode: 'DIRECT_PAID', paidAt: '2026-08-12T10:00:00', paymentMethod: 'BANK_TRANSFER', paymentReferenceNo: 'BANK-1', paymentVoucherFileIds: ['9001'], businessDate: '2026-08-12', amount: 100, currency: 'CNY', reviewStatus: 'PENDING', sourceStatus: 'ACTIVE', sourceVersion: 1, remark: null, reviewerName: null, reviewedAt: null, reviewReason: null }])
|
|
|
|
|
vi.mocked(listApplicableFeeItems).mockResolvedValue([{ id: '7', name: '操作费', feeCode: 'TRUCKING', supplierCategory: 'TRUCKING', warehouseReceivable: true, warehousePayable: true, pickupReceivable: false, pickupPayable: false }])
|
|
|
|
|
const wrapper = await mountPanel(['firstleg:inbound:fee-detail:view', 'firstleg:inbound:fee-detail:edit', 'firstleg:fee-item:view', 'platform:supplier:list'])
|
|
|
|
|
expect(wrapper.text()).toContain('已付成本'); expect(wrapper.text()).toContain('银行转账'); expect(wrapper.text()).toContain('BANK-1')
|
|
|
|
|
const state = (wrapper.vm.$ as unknown as { setupState: { openCreate(): void; form: { direction: string; settlementMode: string | null; paidAt: string | null; paymentMethod: string | null; paymentReferenceNo: string | null; paymentVoucherFileIds: string[] | null } } }).setupState
|
|
|
|
|
state.openCreate(); await flushPromises(); Object.assign(state.form, { direction: 'PAYABLE', settlementMode: 'DIRECT_PAID', paidAt: '2026-08-12T10:00:00', paymentMethod: 'CASH', paymentReferenceNo: 'CASH-1', paymentVoucherFileIds: ['9001'] }); await flushPromises()
|
|
|
|
|
state.form.settlementMode = 'ON_ACCOUNT'; await flushPromises(); expect(state.form).toMatchObject({ settlementMode: 'ON_ACCOUNT', paidAt: null, paymentMethod: null, paymentReferenceNo: null, paymentVoucherFileIds: null })
|
|
|
|
|
state.form.direction = 'RECEIVABLE'; await flushPromises(); expect(state.form.settlementMode).toBeNull()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('fails closed without DIRECT_PAID evidence and submits a scoped uploaded voucher', async () => {
|
|
|
|
|
vi.mocked(listApplicableFeeItems).mockResolvedValue([{ id: '7', name: '操作费', feeCode: 'TRUCKING', supplierCategory: 'TRUCKING', warehouseReceivable: false, warehousePayable: true, pickupReceivable: false, pickupPayable: false }])
|
|
|
|
|
vi.mocked(listContainerFeeSupplierOptions).mockResolvedValue([{ id: '41', supplierName: '承运商A', category: 'TRUCKING' }])
|
|
|
|
|
const wrapper = await mountPanel(['firstleg:inbound:fee-detail:view', 'firstleg:inbound:fee-detail:edit', 'firstleg:fee-item:view', 'platform:supplier:list'])
|
|
|
|
|
const state = (wrapper.vm.$ as unknown as { setupState: { openCreate(): void; save(): Promise<void>; selectVoucher(event: Event): Promise<void>; form: { direction: string; feeItemId: string; supplierId: string | null; settlementMode: string | null; paidAt: string | null; paymentMethod: string | null; paymentReferenceNo: string | null; amount: number } } }).setupState
|
2026-08-20 18:05:27 +08:00
|
|
|
state.openCreate(); await flushPromises(); Object.assign(state.form, { direction: 'PAYABLE', feeItemId: '7' }); await flushPromises()
|
|
|
|
|
Object.assign(state.form, { supplierId: '41', settlementMode: 'DIRECT_PAID', paidAt: '2026-08-12T10:00:00', paymentMethod: 'ONLINE', paymentReferenceNo: null, amount: 100 }); await flushPromises()
|
2026-08-20 18:02:24 +08:00
|
|
|
await state.save(); expect(createContainerFee).not.toHaveBeenCalled()
|
|
|
|
|
const input = document.createElement('input'); Object.defineProperty(input, 'files', { value: [new File(['x'], '付款凭证.pdf')] })
|
|
|
|
|
await state.selectVoucher({ target: input } as unknown as Event); await state.save()
|
|
|
|
|
expect(uploadContainerFeePaymentVoucher).toHaveBeenCalledWith('11', expect.objectContaining({ name: '付款凭证.pdf' }))
|
|
|
|
|
expect(createContainerFee).toHaveBeenCalledWith('9', '11', expect.objectContaining({ settlementMode: 'DIRECT_PAID', paymentMethod: 'ONLINE', paymentVoucherFileIds: ['9001'] }))
|
|
|
|
|
})
|
2026-08-12 16:31:46 +08:00
|
|
|
})
|