验证费率缺失时不会调用带默认值的计算函数
This commit is contained in:
1 parent
ca19987108
commit
6c55903f11
1 file changed
+6
-2
@@ -1,7 +1,7 @@
|
|||||||
import { render, screen } from '@testing-library/react';
|
import { render, screen } from '@testing-library/react';
|
||||||
import { describe, expect, it } from 'vitest';
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||||
import { orderViews } from '../src/pages/Orders/orderViews';
|
import { orderViews } from '../src/pages/Orders/orderViews';
|
||||||
import type { LedgerState } from '../src/shared';
|
import { Cards, type LedgerState } from '../src/shared';
|
||||||
|
|
||||||
const date = '2026-11-20';
|
const date = '2026-11-20';
|
||||||
const account = '麦麦信用卡';
|
const account = '麦麦信用卡';
|
||||||
@@ -34,6 +34,8 @@ function renderPayment(action: 'receipt' | 'correct', orderRate?: number, shopRa
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe.each(['receipt', 'correct'] as const)('订单 %s 的信用卡手续费', action => {
|
describe.each(['receipt', 'correct'] as const)('订单 %s 的信用卡手续费', action => {
|
||||||
|
afterEach(() => vi.restoreAllMocks());
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
{ detail: '保留原单零费率', orderRate: 0, shopRate: 9, rate: 0, fee: '0.00' },
|
{ detail: '保留原单零费率', orderRate: 0, shopRate: 9, rate: 0, fee: '0.00' },
|
||||||
{ detail: '沿用历史费率', orderRate: 4, shopRate: 9, rate: 4, fee: '1.00' },
|
{ detail: '沿用历史费率', orderRate: 4, shopRate: 9, rate: 4, fee: '1.00' },
|
||||||
@@ -49,9 +51,11 @@ describe.each(['receipt', 'correct'] as const)('订单 %s 的信用卡手续费'
|
|||||||
{ detail: '原单与店铺费率均缺失', orderRate: undefined },
|
{ detail: '原单与店铺费率均缺失', orderRate: undefined },
|
||||||
{ detail: '原单费率无效', orderRate: 1001 },
|
{ detail: '原单费率无效', orderRate: 1001 },
|
||||||
])('$detail时留空并提示重新读取', ({ orderRate }) => {
|
])('$detail时留空并提示重新读取', ({ orderRate }) => {
|
||||||
|
const calculate = vi.spyOn(Cards, 'amount');
|
||||||
renderPayment(action, orderRate);
|
renderPayment(action, orderRate);
|
||||||
expect(screen.getByLabelText('信用卡手续费自动金额')).toHaveDisplayValue('');
|
expect(screen.getByLabelText('信用卡手续费自动金额')).toHaveDisplayValue('');
|
||||||
expect(screen.getByText('信用卡手续费率未能确认,请重新读取后核对。')).toBeVisible();
|
expect(screen.getByText('信用卡手续费率未能确认,请重新读取后核对。')).toBeVisible();
|
||||||
expect(screen.getByLabelText('手续费付款人')).toBeRequired();
|
expect(screen.getByLabelText('手续费付款人')).toBeRequired();
|
||||||
|
if (orderRate === undefined) expect(calculate).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user