You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.8 KiB
JavaScript
81 lines
2.8 KiB
JavaScript
|
1 month ago
|
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);
|
||
|
|
});
|