fix: 优化产品架构设计校验提示
parent
e8c1f08640
commit
5005bacad7
@ -0,0 +1,52 @@
|
||||
export const SCENARIO_FIELDS = [
|
||||
"userScenario",
|
||||
"hardwareSense",
|
||||
"driverTransmit",
|
||||
"algorithmProcess",
|
||||
"applicationTrigger",
|
||||
"driverOutput",
|
||||
"hardwareEffect",
|
||||
];
|
||||
|
||||
const FIELD_LABELS = {
|
||||
userScenario: "用户场景",
|
||||
hardwareSense: "硬件物理层(感知)",
|
||||
driverTransmit: "驱动感知层(传递)",
|
||||
algorithmProcess: "算法处理层",
|
||||
applicationTrigger: "应用功能层",
|
||||
driverOutput: "驱动感知层(输出)",
|
||||
hardwareEffect: "硬件物理层(效果)",
|
||||
};
|
||||
|
||||
function hasText(value) {
|
||||
return Boolean(String(value || "").trim());
|
||||
}
|
||||
|
||||
function isEmptyRow(row) {
|
||||
return SCENARIO_FIELDS.every((field) => !hasText(row?.[field]));
|
||||
}
|
||||
|
||||
function getMissingFieldLabels(row) {
|
||||
return SCENARIO_FIELDS.filter((field) => !hasText(row?.[field])).map((field) => FIELD_LABELS[field]);
|
||||
}
|
||||
|
||||
export function getRowsForScenarioValidation(rows) {
|
||||
return (Array.isArray(rows) ? rows : []).filter((row) => !isEmptyRow(row));
|
||||
}
|
||||
|
||||
export function getCompletedScenarioCount(rows) {
|
||||
return getRowsForScenarioValidation(rows).filter((row) => getMissingFieldLabels(row).length === 0).length;
|
||||
}
|
||||
|
||||
export function getScenarioValidationMessage(rows) {
|
||||
const sourceRows = Array.isArray(rows) ? rows : [];
|
||||
const incompleteIndex = sourceRows.findIndex((row) => !isEmptyRow(row) && getMissingFieldLabels(row).length > 0);
|
||||
if (incompleteIndex >= 0) {
|
||||
return `第 ${incompleteIndex + 1} 行尚未填写完整,缺少:${getMissingFieldLabels(sourceRows[incompleteIndex]).join("、")}。`;
|
||||
}
|
||||
const enteredRows = getRowsForScenarioValidation(sourceRows);
|
||||
if (enteredRows.length < 3) {
|
||||
return `请至少完整填写 3 个典型工作场景;当前已完成 ${enteredRows.length} 个。`;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
@ -0,0 +1,80 @@
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import test from "node:test";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import {
|
||||
getRowsForScenarioValidation,
|
||||
getScenarioValidationMessage,
|
||||
} from "../src/views/product/productArchitectureScenarioValidation.mjs";
|
||||
|
||||
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
||||
|
||||
const completeRow = {
|
||||
userScenario: "用户说小美,打开客厅灯",
|
||||
hardwareSense: "麦克风采集语音",
|
||||
driverTransmit: "音频驱动传递数字信号",
|
||||
algorithmProcess: "识别唤醒词和开灯指令",
|
||||
applicationTrigger: "触发开灯功能",
|
||||
driverOutput: "调光驱动输出 PWM 信号",
|
||||
hardwareEffect: "客厅灯点亮",
|
||||
};
|
||||
|
||||
test("产品架构第 3 步忽略额外空行,只提交三条完整场景", () => {
|
||||
const rows = [completeRow, { ...completeRow }, { ...completeRow }, {
|
||||
userScenario: "",
|
||||
hardwareSense: "",
|
||||
driverTransmit: "",
|
||||
algorithmProcess: "",
|
||||
applicationTrigger: "",
|
||||
driverOutput: "",
|
||||
hardwareEffect: "",
|
||||
}];
|
||||
|
||||
assert.equal(getScenarioValidationMessage(rows), "");
|
||||
assert.equal(getRowsForScenarioValidation(rows).length, 3);
|
||||
});
|
||||
|
||||
test("产品架构第 3 步提示首个未完成场景及缺失字段", () => {
|
||||
const incomplete = { ...completeRow, algorithmProcess: "", driverOutput: "" };
|
||||
|
||||
assert.equal(
|
||||
getScenarioValidationMessage([completeRow, incomplete, { ...completeRow }]),
|
||||
"第 2 行尚未填写完整,缺少:算法处理层、驱动感知层(输出)。"
|
||||
);
|
||||
});
|
||||
|
||||
test("产品架构第 3 步保留半填场景在原表格中的行号", () => {
|
||||
const emptyRow = {
|
||||
userScenario: "",
|
||||
hardwareSense: "",
|
||||
driverTransmit: "",
|
||||
algorithmProcess: "",
|
||||
applicationTrigger: "",
|
||||
driverOutput: "",
|
||||
hardwareEffect: "",
|
||||
};
|
||||
const incomplete = { ...completeRow, algorithmProcess: "" };
|
||||
|
||||
assert.equal(
|
||||
getScenarioValidationMessage([completeRow, emptyRow, incomplete, { ...completeRow }]),
|
||||
"第 3 行尚未填写完整,缺少:算法处理层。"
|
||||
);
|
||||
});
|
||||
|
||||
test("产品架构第 3 步要求至少三条完整场景", () => {
|
||||
assert.equal(
|
||||
getScenarioValidationMessage([completeRow, { ...completeRow }]),
|
||||
"请至少完整填写 3 个典型工作场景;当前已完成 2 个。"
|
||||
);
|
||||
});
|
||||
|
||||
test("产品架构校验接口保留业务提示且不重复弹出 400 错误", () => {
|
||||
const apiSource = fs.readFileSync(path.join(root, "src/api/studentTrainingAnswer.js"), "utf8");
|
||||
const architectureChecks = apiSource.slice(
|
||||
apiSource.indexOf("export function checkProductArchitectureDesignStepOne"),
|
||||
apiSource.indexOf("export function checkProductDevelopmentProcessStepTwo")
|
||||
);
|
||||
|
||||
assert.equal((architectureChecks.match(/skipErrorMessage: true/g) || []).length, 4);
|
||||
});
|
||||
Loading…
Reference in New Issue