stockMoveDialog.spec.js
1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { listUpgradeGoodsSimple, moveMerchantGoodsStock } from "@api/stockManage";
import { STOCK_MOVE_ZERO_MESSAGE } from "./stockMove";
import StockMoveDialog from "./stockMoveDialog.vue";
jest.mock("@api/stockManage", () => ({
listUpgradeGoodsSimple: jest.fn(),
moveMerchantGoodsStock: jest.fn(),
}));
describe("stock move dialog", () => {
beforeEach(() => {
jest.clearAllMocks();
});
it("queries light-modification products and excludes the current UID", async () => {
listUpgradeGoodsSimple.mockResolvedValue({
list: [
{ id: 1, commodityCode: "OLD" },
{ id: 2, commodityCode: "NEW" },
],
});
const context = {
requestSequence: 0,
loading: false,
targetOptions: [],
row: { upgradeGoodsId: 1, upgradeCommodityCode: "OLD" },
};
await StockMoveDialog.methods.fetchTargetOptions.call(context, "UID");
expect(listUpgradeGoodsSimple).toHaveBeenCalledWith({
currentPage: 1,
pageSize: 20,
commodityCode: "UID",
productType: 1,
});
expect(context.targetOptions).toEqual([{ id: 2, commodityCode: "NEW" }]);
});
it("blocks zero-stock rows before validating or submitting", () => {
const warning = jest.fn();
const validate = jest.fn();
StockMoveDialog.methods.handleConfirm.call({
submitting: false,
row: { stock: 0 },
$message: { warning },
$refs: { stockMoveForm: { validate } },
});
expect(warning).toHaveBeenCalledWith(STOCK_MOVE_ZERO_MESSAGE);
expect(validate).not.toHaveBeenCalled();
expect(moveMerchantGoodsStock).not.toHaveBeenCalled();
});
});