提交
This commit is contained in:
@@ -2,12 +2,24 @@ import ElementPlus from 'element-plus'
|
||||
import { createPinia, setActivePinia } from 'pinia'
|
||||
import { enableAutoUnmount, flushPromises, mount } from '@vue/test-utils'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { getCustomerDimensionConfig, updateCustomerDimensionConfig, type CustomerDimensionConfig } from '@/modules/dimension-config'
|
||||
import { getCustomerDimensionConfig, updateCustomerDimensionConfig, updateCustomerDimensionDefaultCalculationMode, type CustomerDimensionConfig } from '@/modules/dimension-config'
|
||||
import {
|
||||
createCustomerChargeRule,
|
||||
listCustomerChargeRules,
|
||||
setCustomerChargeRuleDefault,
|
||||
type CustomerChargeRule,
|
||||
} from '@/modules/fba-pricing'
|
||||
import { useAccessPreviewStore } from '@/core/access/accessPreview'
|
||||
import { useAuthStore } from '@/core/auth/auth'
|
||||
import CustomerBillingRulesPanel from './CustomerBillingRulesPanel.vue'
|
||||
|
||||
vi.mock('@/modules/dimension-config', () => ({ getCustomerDimensionConfig: vi.fn(), updateCustomerDimensionConfig: vi.fn() }))
|
||||
vi.mock('@/modules/dimension-config', () => ({ getCustomerDimensionConfig: vi.fn(), updateCustomerDimensionConfig: vi.fn(), updateCustomerDimensionDefaultCalculationMode: vi.fn() }))
|
||||
vi.mock('@/modules/fba-pricing', () => ({
|
||||
createCustomerChargeRule: vi.fn(),
|
||||
listCustomerChargeRules: vi.fn(),
|
||||
retireCustomerChargeRule: vi.fn(),
|
||||
setCustomerChargeRuleDefault: vi.fn(),
|
||||
}))
|
||||
|
||||
const boxes = [
|
||||
['SMALL', '小箱', 30, 20, 20, '标准小箱'],
|
||||
@@ -17,6 +29,7 @@ const boxes = [
|
||||
] as const
|
||||
const config: CustomerDimensionConfig = {
|
||||
tenantId: '8',
|
||||
defaultCalculationMode: 'ADD',
|
||||
rules: boxes.map(([boxType, boxTypeName, innerLengthCm, innerWidthCm, innerHeightCm, remark], index) => ({
|
||||
id: String(100 + index),
|
||||
boxType, boxTypeName, innerLengthCm, innerWidthCm, innerHeightCm, edgeAdditionCm: 2,
|
||||
@@ -25,6 +38,13 @@ const config: CustomerDimensionConfig = {
|
||||
remark, version: 3, createdAt: '2026-08-07T10:00:00', updatedAt: '2026-08-07T10:20:00',
|
||||
})),
|
||||
}
|
||||
const chargeRule: CustomerChargeRule = {
|
||||
id: '201', tenantId: '8', ruleCode: 'RULE-201', ruleVersion: 1, customerId: '8', customerName: '柏悦物流',
|
||||
businessType: 'FBA', chargeMode: 'CBM', taxMode: 'TAX_INCLUDED', conversionFactor: 167,
|
||||
lengthFactor: 1, widthFactor: 1, heightFactor: 1, defaultRule: false, roundingScale: 2,
|
||||
roundingMode: 'HALF_UP', currency: 'CNY', effectiveFrom: '2026-09-02T10:00:00', effectiveTo: null,
|
||||
status: 'ACTIVE', remark: null,
|
||||
}
|
||||
|
||||
enableAutoUnmount(afterEach)
|
||||
|
||||
@@ -33,10 +53,16 @@ describe('CustomerBillingRulesPanel', () => {
|
||||
vi.clearAllMocks()
|
||||
document.body.innerHTML = ''
|
||||
const pinia = createPinia(); setActivePinia(pinia)
|
||||
const auth = useAuthStore(); auth.token = 'token'; auth.permissions = ['firstleg:dimension-config:view', 'firstleg:dimension-config:edit']
|
||||
const auth = useAuthStore(); auth.token = 'token'; auth.permissions = [
|
||||
'firstleg:dimension-config:view', 'firstleg:dimension-config:edit',
|
||||
'firstleg:fba-pricing:rule:view', 'firstleg:fba-pricing:rule:edit',
|
||||
]
|
||||
useAccessPreviewStore().initializeAfterLogin()
|
||||
vi.mocked(getCustomerDimensionConfig).mockResolvedValue(config)
|
||||
vi.mocked(updateCustomerDimensionConfig).mockResolvedValue(config)
|
||||
vi.mocked(updateCustomerDimensionDefaultCalculationMode).mockResolvedValue(config)
|
||||
vi.mocked(listCustomerChargeRules).mockResolvedValue([chargeRule])
|
||||
vi.mocked(createCustomerChargeRule).mockResolvedValue(chargeRule)
|
||||
})
|
||||
|
||||
it('renders the four fixed carton dimension rows and calculated values', async () => {
|
||||
@@ -90,4 +116,33 @@ describe('CustomerBillingRulesPanel', () => {
|
||||
await flushPromises()
|
||||
expect(document.body.textContent).toContain('编辑箱规尺寸')
|
||||
})
|
||||
|
||||
it('saves the coefficient set and can use it as the customer default calculation mode', async () => {
|
||||
vi.mocked(listCustomerChargeRules)
|
||||
.mockResolvedValueOnce([chargeRule])
|
||||
.mockResolvedValueOnce([{ ...chargeRule, defaultRule: true }])
|
||||
vi.mocked(updateCustomerDimensionDefaultCalculationMode).mockResolvedValue({
|
||||
...config,
|
||||
defaultCalculationMode: 'MULTIPLY',
|
||||
})
|
||||
mount(CustomerBillingRulesPanel, { attachTo: document.body, props: { customerId: '8', customerName: '柏悦物流' }, global: { plugins: [ElementPlus] } })
|
||||
await flushPromises()
|
||||
|
||||
;[...document.querySelectorAll<HTMLButtonElement>('button')].find((button) => button.textContent?.trim() === '编辑规则')?.click()
|
||||
await flushPromises()
|
||||
expect(document.body.textContent).toContain('箱规按权重系数计算')
|
||||
|
||||
;[...document.querySelectorAll<HTMLButtonElement>('button')].find((button) => button.textContent?.trim() === '保存系数规则')?.click()
|
||||
await flushPromises()
|
||||
expect(createCustomerChargeRule).toHaveBeenCalledWith('8', expect.objectContaining({
|
||||
defaultRule: false,
|
||||
remark: expect.stringMatching(/SMALL:30,20,20;系数:\d+(?:\.\d+)?/),
|
||||
}))
|
||||
expect(setCustomerChargeRuleDefault).toHaveBeenCalledWith('8', '201')
|
||||
|
||||
const defaultRuleCheckboxes = [...document.querySelectorAll<HTMLInputElement>('input[type="checkbox"]')]
|
||||
defaultRuleCheckboxes[1]?.click()
|
||||
await flushPromises()
|
||||
expect(updateCustomerDimensionDefaultCalculationMode).toHaveBeenCalledWith('8', 'MULTIPLY')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user