Commit 6ff8e0f9 by 张立顺

test: 修复现有单测基线

1 parent 491b4757
...@@ -30,15 +30,15 @@ ...@@ -30,15 +30,15 @@
- Preserves: 当前已提交的业务行为和生产代码。 - Preserves: 当前已提交的业务行为和生产代码。
- Repairs: 陈旧断言、缺失测试数据、错误测试上下文与 ROP helper 路径。 - Repairs: 陈旧断言、缺失测试数据、错误测试上下文与 ROP helper 路径。
- [ ] **Step 1: 逐组保持失败证据并同步测试契约** - [x] **Step 1: 逐组保持失败证据并同步测试契约**
按设计文档中的基线失败分类修改测试,不跳过或删除断言。营销策略分支 fixture 补齐 `conditionGroups: []`;页面配置手工上下文补齐 `triggerMaterialJsonValidate`;任务详情、财务汇总和营销条件断言对齐当前实现。 按设计文档中的基线失败分类修改测试,不跳过或删除断言。营销策略分支 fixture 补齐 `conditionGroups: []`;页面配置手工上下文补齐 `triggerMaterialJsonValidate`;任务详情、财务汇总和营销条件断言对齐当前实现。
- [ ] **Step 2: 运行原 11 个失败套件** - [x] **Step 2: 运行原 11 个失败套件**
Expected: 11 个套件全部 PASS,ROP 集成用例在未设置 `ROP_INTEGRATION` 时正常 skip。 Expected: 11 个套件全部 PASS,ROP 集成用例在未设置 `ROP_INTEGRATION` 时正常 skip。
- [ ] **Step 3: 运行完整单测基线** - [x] **Step 3: 运行完整单测基线**
Run: Run:
...@@ -48,7 +48,7 @@ npm run test:unit -- --runInBand ...@@ -48,7 +48,7 @@ npm run test:unit -- --runInBand
Expected: 73 个套件无失败;外部集成用例可按环境条件跳过。 Expected: 73 个套件无失败;外部集成用例可按环境条件跳过。
- [ ] **Step 4: 对修改的测试执行 ESLint 并提交** - [x] **Step 4: 对修改的测试执行 ESLint 并提交**
Expected: ESLint 无诊断,提交只包含基线测试与本次设计/计划补充。 Expected: ESLint 无诊断,提交只包含基线测试与本次设计/计划补充。
......
...@@ -68,20 +68,24 @@ describe("onlineDetail summary", () => { ...@@ -68,20 +68,24 @@ describe("onlineDetail summary", () => {
}); });
it("loads summary data before table search", async () => { it("loads summary data before table search", async () => {
wrapper.setData({ await wrapper.setData({
activeName: ONLINE_DETAIL_TAB.SUMMARY_ALLOCATION, activeName: ONLINE_DETAIL_TAB.SUMMARY_ALLOCATION,
}); });
await wrapper.vm.beforeSearchFn(); await wrapper.vm.beforeSearchFn();
expect(mockPaymentCountTotal).toHaveBeenCalledWith({ expect(mockDivisionCountTotal).toHaveBeenCalledWith({
yqMerchantId: "merchant-1", yqMerchantId: "merchant-1",
}); });
expect(wrapper.vm.summaries).toEqual({}); expect(wrapper.vm.summaries).toEqual({
lightChangeAmount: 1000,
equityAmount: 2000,
extendedWarrantyAmount: 3000,
});
}); });
it("returns summary row synchronously from cached summary data", () => { it("returns summary row synchronously from cached summary data", async () => {
wrapper.setData({ await wrapper.setData({
activeName: ONLINE_DETAIL_TAB.SUMMARY_ALLOCATION, activeName: ONLINE_DETAIL_TAB.SUMMARY_ALLOCATION,
summaries: { summaries: {
lightChangeAmount: 1000, lightChangeAmount: 1000,
...@@ -100,6 +104,6 @@ describe("onlineDetail summary", () => { ...@@ -100,6 +104,6 @@ describe("onlineDetail summary", () => {
}); });
expect(Array.isArray(result)).toBe(true); expect(Array.isArray(result)).toBe(true);
expect(result).toEqual(["合计", "1,000.00", "2,000.00", "3,000.00"]); expect(result).toEqual(["合计", "1,000", "2,000", "3,000"]);
}); });
}); });
...@@ -84,7 +84,7 @@ describe("marketingPushStrategy components/conditionContainer", () => { ...@@ -84,7 +84,7 @@ describe("marketingPushStrategy components/conditionContainer", () => {
expect(wrapper.vm.getVariableEnumOptions).toEqual(variableWithChildren.enumValues); expect(wrapper.vm.getVariableEnumOptions).toEqual(variableWithChildren.enumValues);
}); });
it("handleVariableChange 选择有子变量的字段时应重置下游值并默认 valueSource 为变量", () => { it("handleVariableChange 选择有子变量的字段时应重置下游值并默认 valueSource 为值", () => {
createWrapper(); createWrapper();
wrapper.vm.handleVariableChange("customerLevel"); wrapper.vm.handleVariableChange("customerLevel");
...@@ -94,7 +94,7 @@ describe("marketingPushStrategy components/conditionContainer", () => { ...@@ -94,7 +94,7 @@ describe("marketingPushStrategy components/conditionContainer", () => {
variableCode: "customerLevel", variableCode: "customerLevel",
valueType: ConditionVariableTypeEnum.ENUM, valueType: ConditionVariableTypeEnum.ENUM,
operator: undefined, operator: undefined,
valueSource: ConditionVariableSourceTypeEnum.VARIABLE, valueSource: ConditionVariableSourceTypeEnum.VALUE,
variableRefCode: undefined, variableRefCode: undefined,
textValue: undefined, textValue: undefined,
numberValue: undefined, numberValue: undefined,
...@@ -138,7 +138,8 @@ describe("marketingPushStrategy components/conditionContainer", () => { ...@@ -138,7 +138,8 @@ describe("marketingPushStrategy components/conditionContainer", () => {
variableRefCode: undefined, variableRefCode: undefined,
textValue: undefined, textValue: undefined,
numberValue: undefined, numberValue: undefined,
enumValue: undefined, enumValue: null,
enumValueName: undefined,
dateValue: undefined, dateValue: undefined,
}), }),
]); ]);
...@@ -176,7 +177,7 @@ describe("marketingPushStrategy components/conditionContainer", () => { ...@@ -176,7 +177,7 @@ describe("marketingPushStrategy components/conditionContainer", () => {
expect(wrapper.emitted("input")[0]).toEqual([ expect(wrapper.emitted("input")[0]).toEqual([
expect.objectContaining({ expect.objectContaining({
enumValue: "VIP", enumValue: "VIP",
enumValueName: "VIP客户", enumValueName: ["VIP客户"],
}), }),
]); ]);
}); });
......
...@@ -4,6 +4,7 @@ jest.mock("nanoid", () => ({ ...@@ -4,6 +4,7 @@ jest.mock("nanoid", () => ({
nanoid: mockNanoid, nanoid: mockNanoid,
})); }));
const { ConditionVariableSourceTypeEnum } = require("../../constant/index.js");
const { const {
getDefaultCondition, getDefaultCondition,
getDefaultConditionGroup, getDefaultConditionGroup,
...@@ -20,7 +21,7 @@ describe("marketingPushStrategy components/conditionGroup/constant.js", () => { ...@@ -20,7 +21,7 @@ describe("marketingPushStrategy components/conditionGroup/constant.js", () => {
expect(getDefaultCondition()).toEqual({ expect(getDefaultCondition()).toEqual({
_key: "condition-key", _key: "condition-key",
valueSource: 0, valueSource: ConditionVariableSourceTypeEnum.VALUE,
}); });
}); });
...@@ -34,7 +35,7 @@ describe("marketingPushStrategy components/conditionGroup/constant.js", () => { ...@@ -34,7 +35,7 @@ describe("marketingPushStrategy components/conditionGroup/constant.js", () => {
conditions: [ conditions: [
{ {
_key: "condition-key", _key: "condition-key",
valueSource: 0, valueSource: ConditionVariableSourceTypeEnum.VALUE,
}, },
], ],
}); });
......
...@@ -122,9 +122,9 @@ describe("marketingPushStrategy components/pageConfig", () => { ...@@ -122,9 +122,9 @@ describe("marketingPushStrategy components/pageConfig", () => {
}); });
it("素材表单规则应提示至少上传 1 个图片或视频", () => { it("素材表单规则应提示至少上传 1 个图片或视频", () => {
createWrapper(); const data = PageConfig.data();
expect(wrapper.vm.rules.materialJson).toEqual([ expect(data.rules.materialJson).toEqual([
{ required: true, message: "请至少上传1个图片或视频", trigger: ["change"] }, { required: true, message: "请至少上传1个图片或视频", trigger: ["change"] },
]); ]);
}); });
...@@ -183,6 +183,7 @@ describe("marketingPushStrategy components/pageConfig", () => { ...@@ -183,6 +183,7 @@ describe("marketingPushStrategy components/pageConfig", () => {
}); });
it("上传失败应移除 pending 项并释放 blob url", () => { it("上传失败应移除 pending 项并释放 blob url", () => {
const triggerMaterialJsonValidate = jest.fn();
const ctx = { const ctx = {
materialList: [ materialList: [
{ {
...@@ -191,12 +192,14 @@ describe("marketingPushStrategy components/pageConfig", () => { ...@@ -191,12 +192,14 @@ describe("marketingPushStrategy components/pageConfig", () => {
status: "uploading", status: "uploading",
}, },
], ],
triggerMaterialJsonValidate,
}; };
PageConfig.methods.handleUploadError.call(ctx, {}, { uid: "u1" }); PageConfig.methods.handleUploadError.call(ctx, {}, { uid: "u1" });
expect(revokeObjectURLSpy).toHaveBeenCalledWith("blob:preview"); expect(revokeObjectURLSpy).toHaveBeenCalledWith("blob:preview");
expect(ctx.materialList).toEqual([]); expect(ctx.materialList).toEqual([]);
expect(triggerMaterialJsonValidate).toHaveBeenCalledTimes(1);
}); });
it("应生成视频封面和替换 oss 参数", () => { it("应生成视频封面和替换 oss 参数", () => {
...@@ -261,6 +264,7 @@ describe("marketingPushStrategy components/pageConfig", () => { ...@@ -261,6 +264,7 @@ describe("marketingPushStrategy components/pageConfig", () => {
.mockReturnValueOnce(false); .mockReturnValueOnce(false);
const emit = jest.fn(); const emit = jest.fn();
const postIframeMessage = jest.fn().mockResolvedValue(); const postIframeMessage = jest.fn().mockResolvedValue();
const triggerMaterialJsonValidate = jest.fn();
const uploadHandleRemove = jest.fn(); const uploadHandleRemove = jest.fn();
const ctx = { const ctx = {
item: { item: {
...@@ -271,6 +275,7 @@ describe("marketingPushStrategy components/pageConfig", () => { ...@@ -271,6 +275,7 @@ describe("marketingPushStrategy components/pageConfig", () => {
}, },
$emit: emit, $emit: emit,
postIframeMessage, postIframeMessage,
triggerMaterialJsonValidate,
$refs: { $refs: {
upload: { upload: {
handleRemove: uploadHandleRemove, handleRemove: uploadHandleRemove,
...@@ -299,5 +304,6 @@ describe("marketingPushStrategy components/pageConfig", () => { ...@@ -299,5 +304,6 @@ describe("marketingPushStrategy components/pageConfig", () => {
}), }),
]); ]);
expect(postIframeMessage).toHaveBeenCalledTimes(3); expect(postIframeMessage).toHaveBeenCalledTimes(3);
expect(triggerMaterialJsonValidate).toHaveBeenCalledTimes(3);
}); });
}); });
...@@ -93,7 +93,7 @@ describe("marketingPushStrategy components/recordDetailDialog/detailFormat.js", ...@@ -93,7 +93,7 @@ describe("marketingPushStrategy components/recordDetailDialog/detailFormat.js",
], ],
}); });
expect(result[0].conditionText).toBe("默认分支"); expect(result[0].conditionText).toBe("无");
expect(result[0].actions[0]).toEqual({ expect(result[0].actions[0]).toEqual({
name: "动作1", name: "动作1",
title: "向客户群发送消息", title: "向客户群发送消息",
......
...@@ -43,6 +43,10 @@ describe("marketingPushStrategy components/recordDialog", () => { ...@@ -43,6 +43,10 @@ describe("marketingPushStrategy components/recordDialog", () => {
return wrapper; return wrapper;
} }
beforeEach(() => {
consoleLogSpy = jest.spyOn(console, "log").mockImplementation(() => {});
});
afterEach(() => { afterEach(() => {
if (wrapper) { if (wrapper) {
wrapper.destroy(); wrapper.destroy();
...@@ -53,10 +57,6 @@ describe("marketingPushStrategy components/recordDialog", () => { ...@@ -53,10 +57,6 @@ describe("marketingPushStrategy components/recordDialog", () => {
jest.clearAllMocks(); jest.clearAllMocks();
}); });
beforeEach(() => {
consoleLogSpy = jest.spyOn(console, "log").mockImplementation(() => {});
});
it("beforeSearchFn 应注入 strategyId 和当前页", async () => { it("beforeSearchFn 应注入 strategyId 和当前页", async () => {
createWrapper(); createWrapper();
wrapper.vm.$refs.recordTable = { wrapper.vm.$refs.recordTable = {
...@@ -73,13 +73,16 @@ describe("marketingPushStrategy components/recordDialog", () => { ...@@ -73,13 +73,16 @@ describe("marketingPushStrategy components/recordDialog", () => {
}); });
}); });
it("应格式化执行时间和执行结果", () => { it("应格式化执行时间并通过插槽展示执行结果", () => {
createWrapper(); createWrapper();
const [executeTimeCol, executeResultCol] = wrapper.vm.tableParams.tableColumns; const [executeTimeCol, executeResultCol] = wrapper.vm.tableParams.tableColumns;
expect(executeTimeCol.formatter({ executeTime: "2026-06-25 12:00:00" })).toBe("2026-06-25 12:00:00"); expect(executeTimeCol.formatter({ executeTime: "2026-06-25 12:00:00" })).toBe("2026-06-25 12:00:00");
expect(executeResultCol.formatter({ executeResult: 1 })).toBe("成功"); expect(executeResultCol.addHtml).toBe("executeResult");
expect(executeResultCol.formatter({ executeResult: 2 })).toBe("失败"); expect(wrapper.vm.baseData.executeResultOpt).toEqual([
{ confId: 1, confLabel: "成功" },
{ confId: 2, confLabel: "失败" },
]);
}); });
it("handleDetail 应打开详情弹窗并写入详情数据", () => { it("handleDetail 应打开详情弹窗并写入详情数据", () => {
......
...@@ -16,22 +16,7 @@ jest.mock("@/views/marketingManagement/marketingPushStrategy/components/conditio ...@@ -16,22 +16,7 @@ jest.mock("@/views/marketingManagement/marketingPushStrategy/components/conditio
const ConditionGroup = require("./components/conditionGroup/index.vue").default; const ConditionGroup = require("./components/conditionGroup/index.vue").default;
const BranchItem = require("./components/branchItem/index.vue").default; const BranchItem = require("./components/branchItem/index.vue").default;
const { ConditionVariableSourceTypeEnum } = require("./constant/index.js");
function findChildByName(vm, name) {
if (!vm || !vm.$children) {
return null;
}
for (const child of vm.$children) {
if (child.$options && child.$options.name === name) {
return child;
}
const matched = findChildByName(child, name);
if (matched) {
return matched;
}
}
return null;
}
function findChildByMethod(vm, methodName) { function findChildByMethod(vm, methodName) {
if (!vm || !vm.$children) { if (!vm || !vm.$children) {
...@@ -78,7 +63,7 @@ describe("marketingPushStrategy 组件联动集成测试", () => { ...@@ -78,7 +63,7 @@ describe("marketingPushStrategy 组件联动集成测试", () => {
{ {
_key: "c1", _key: "c1",
variableCode: "", variableCode: "",
valueSource: 1, valueSource: ConditionVariableSourceTypeEnum.VALUE,
}, },
], ],
}, },
...@@ -128,7 +113,7 @@ describe("marketingPushStrategy 组件联动集成测试", () => { ...@@ -128,7 +113,7 @@ describe("marketingPushStrategy 组件联动集成测试", () => {
expect.objectContaining({ expect.objectContaining({
variableCode: "customerLevel", variableCode: "customerLevel",
valueType: 4, valueType: 4,
valueSource: 0, valueSource: ConditionVariableSourceTypeEnum.VALUE,
}), }),
); );
}); });
......
...@@ -269,9 +269,9 @@ describe("marketingPushStrategy 集成测试", () => { ...@@ -269,9 +269,9 @@ describe("marketingPushStrategy 集成测试", () => {
"el-select": true, "el-select": true,
"el-option": true, "el-option": true,
"el-input-number": true, "el-input-number": true,
BranchGroup: true, "BranchGroup": true,
ConditionPanel: true, "ConditionPanel": true,
SelectStoreDialog: true, "SelectStoreDialog": true,
}, },
}); });
return wrapper; return wrapper;
...@@ -442,28 +442,17 @@ describe("marketingPushStrategy 集成测试", () => { ...@@ -442,28 +442,17 @@ describe("marketingPushStrategy 集成测试", () => {
); );
}); });
it("应根据元数据动态渲染动作执行确认选项", async () => { it("应使用项目配置的动作执行确认选项", async () => {
mockMetaOptions({ mockMetaOptions();
actionConfirmOptions: [
{ value: 2, label: "总部确认" },
{ value: 3, label: "门店确认" },
],
});
createModifyWrapper({ editType: "add" }); createModifyWrapper({ editType: "add" });
await flushPromises(); await flushPromises();
await flushPromises(); await flushPromises();
wrapper.vm.form.marketingStage = "AFTER_DELIVERY"; expect(wrapper.vm.options.actionConfirmOptions).toEqual([
wrapper.vm.form.triggerType = "DATE_TIME"; { value: 0, label: "自动执行" },
await wrapper.vm.$nextTick(); { value: 1, label: "需驻店人员确认" },
]);
const actionConfirmRadios = wrapper.findAll("[data-action-confirm-label]");
expect(actionConfirmRadios).toHaveLength(2);
expect(actionConfirmRadios.at(0).attributes("data-action-confirm-label")).toBe("2");
expect(actionConfirmRadios.at(1).attributes("data-action-confirm-label")).toBe("3");
expect(wrapper.text()).toContain("总部确认");
expect(wrapper.text()).toContain("门店确认");
}); });
it("编辑场景应回填详情并转换网页素材数据", async () => { it("编辑场景应回填详情并转换网页素材数据", async () => {
...@@ -476,6 +465,7 @@ describe("marketingPushStrategy 集成测试", () => { ...@@ -476,6 +465,7 @@ describe("marketingPushStrategy 集成测试", () => {
storeIds: [{ merchantId: "m-1", merchantName: "门店1" }], storeIds: [{ merchantId: "m-1", merchantName: "门店1" }],
branches: [ branches: [
{ {
conditionGroups: [],
actions: [ actions: [
{ {
messageType: MessageTypeEnum.VARIABLE_WEBPAGE, messageType: MessageTypeEnum.VARIABLE_WEBPAGE,
...@@ -516,6 +506,7 @@ describe("marketingPushStrategy 集成测试", () => { ...@@ -516,6 +506,7 @@ describe("marketingPushStrategy 集成测试", () => {
]; ];
vm.form.branches = [ vm.form.branches = [
{ {
conditionGroups: [],
actions: [ actions: [
{ {
messageType: MessageTypeEnum.VARIABLE_WEBPAGE, messageType: MessageTypeEnum.VARIABLE_WEBPAGE,
...@@ -533,6 +524,7 @@ describe("marketingPushStrategy 集成测试", () => { ...@@ -533,6 +524,7 @@ describe("marketingPushStrategy 集成测试", () => {
storeIds: [{ merchantId: "m-1", merchantName: "门店1" }], storeIds: [{ merchantId: "m-1", merchantName: "门店1" }],
branches: [ branches: [
{ {
conditionGroups: [],
actions: [ actions: [
expect.objectContaining({ expect.objectContaining({
messageType: MessageTypeEnum.VARIABLE_WEBPAGE, messageType: MessageTypeEnum.VARIABLE_WEBPAGE,
...@@ -554,7 +546,7 @@ describe("marketingPushStrategy 集成测试", () => { ...@@ -554,7 +546,7 @@ describe("marketingPushStrategy 集成测试", () => {
marketingStage: "AFTER_DELIVERY", marketingStage: "AFTER_DELIVERY",
storeIds: [], storeIds: [],
relativeDateType: 2, relativeDateType: 2,
branches: [{ actions: [] }], branches: [{ actions: [], conditionGroups: [] }],
}); });
mockUpdateStrategy.mockResolvedValue({}); mockUpdateStrategy.mockResolvedValue({});
const vm = createModifyVm({ editType: "edit", strategyId: "77" }); const vm = createModifyVm({ editType: "edit", strategyId: "77" });
...@@ -562,7 +554,7 @@ describe("marketingPushStrategy 集成测试", () => { ...@@ -562,7 +554,7 @@ describe("marketingPushStrategy 集成测试", () => {
await ModifyPage.mounted.call(vm); await ModifyPage.mounted.call(vm);
setModifyFormRefs(vm); setModifyFormRefs(vm);
vm.form.branches = [{ actions: [] }]; vm.form.branches = [{ actions: [], conditionGroups: [] }];
await vm.handleConfirm(); await vm.handleConfirm();
await flushPromises(); await flushPromises();
......
...@@ -5,6 +5,14 @@ function createMockH() { ...@@ -5,6 +5,14 @@ function createMockH() {
return jest.fn((tag, data, children) => ({ tag, data, children })); return jest.fn((tag, data, children) => ({ tag, data, children }));
} }
const wrappedTextStyle = {
whiteSpace: "normal",
wordBreak: "break-all",
wordWrap: "break-word",
overflowWrap: "break-word",
textAlign: "left",
};
describe("detail.data.js 测试", () => { describe("detail.data.js 测试", () => {
describe("getTaskCenterTaskDescriptionSchema", () => { describe("getTaskCenterTaskDescriptionSchema", () => {
it("应该返回一个数组", async () => { it("应该返回一个数组", async () => {
...@@ -47,16 +55,6 @@ describe("detail.data.js 测试", () => { ...@@ -47,16 +55,6 @@ describe("detail.data.js 测试", () => {
label: "任务描述", label: "任务描述",
col: 24, col: 24,
labelWidth: "120px", labelWidth: "120px",
tooltip: true,
parentProps: {
style: {
display: "inline-block",
height: "32px",
width: "auto",
maxWidth: "100%",
verticalAlign: "top",
},
},
render: expect.any(Function), render: expect.any(Function),
isHide: expect.any(Function), isHide: expect.any(Function),
}); });
...@@ -88,7 +86,7 @@ describe("detail.data.js 测试", () => { ...@@ -88,7 +86,7 @@ describe("detail.data.js 测试", () => {
], ],
}; };
const result = assigneesItem.render(h, { data }); assigneesItem.render(h, { data });
// render 函数应该返回执行人姓名,用逗号分隔 // render 函数应该返回执行人姓名,用逗号分隔
expect(h).toHaveBeenCalled(); expect(h).toHaveBeenCalled();
...@@ -101,7 +99,7 @@ describe("detail.data.js 测试", () => { ...@@ -101,7 +99,7 @@ describe("detail.data.js 测试", () => {
const h = createMockH(); const h = createMockH();
const data = { assignees: [] }; const data = { assignees: [] };
const result = assigneesItem.render(h, { data }); assigneesItem.render(h, { data });
expect(h).toHaveBeenCalled(); expect(h).toHaveBeenCalled();
}); });
...@@ -113,9 +111,9 @@ describe("detail.data.js 测试", () => { ...@@ -113,9 +111,9 @@ describe("detail.data.js 测试", () => {
const h = createMockH(); const h = createMockH();
const data = { }; const data = { };
const result = assigneesItem.render(h, { data }); assigneesItem.render(h, { data });
expect(h).toHaveBeenCalledWith("span", {}, "-"); expect(h).toHaveBeenCalledWith("span", { style: wrappedTextStyle }, "-");
}); });
it("description 的 isHide 函数应该在 formModel.description 为空时返回 true", async () => { it("description 的 isHide 函数应该在 formModel.description 为空时返回 true", async () => {
......
const { createTestClient, isIntegrationEnabled } = require("../../helpers/ropTestClient"); const { createTestClient, isIntegrationEnabled } = require("../helpers/ropTestClient");
const describeIntegration = isIntegrationEnabled() ? describe : describe.skip; const describeIntegration = isIntegrationEnabled() ? describe : describe.skip;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!