Commit 6ff8e0f9 by 张立顺

test: 修复现有单测基线

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