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.
dianshang-qianduan/tests/training-task-fixed-steps.s...

61 lines
2.2 KiB
JavaScript

const assert = require("assert");
const fs = require("fs");
const path = require("path");
const root = path.resolve(__dirname, "..");
const read = (file) => fs.readFileSync(path.join(root, file), "utf8");
const stepCounts = read("src/views/training/taskKeyMap.js");
const teacherEditor = read("src/views/teacherEnd/trainingTask/index.vue");
const adminEditor = read("src/views/schoolAdmin/trainingTask/index.vue");
const expectedCounts = {
"new-product-survey": 4,
"product-development-factors": 4,
"product-development-process": 4,
"industry-demand-analysis": 4,
"competitive-environment-analysis": 4,
"market-opportunity-selection": 6,
"business-feasibility": 3,
"target-user-profile": 5,
"consumer-behavior": 4,
"consumer-scenario": 4,
"feature-conversion": 4,
"product-value-positioning": 4,
"product-structure": 4,
"after-sales-service": 3,
"requirements-doc": 3,
"hardware-cost": 4,
"supplier-evaluation": 3,
"purchase-demand-forecast": 4,
"product-pricing": 5,
"category-optimization": 5,
"release-channel-evaluation": 4,
"promotion-effect-optimization": 4,
"product-diagnosis-iteration": 3,
"comprehensive-case-training": 10,
};
for (const [taskKey, count] of Object.entries(expectedCounts)) {
assert(
new RegExp(`"${taskKey}"\\s*:\\s*${count}(?:,|\\n)`).test(stepCounts),
`${taskKey} should be fixed to ${count} student steps`
);
}
for (const [name, editor] of [
["teacher", teacherEditor],
["admin", adminEditor],
]) {
assert(/import \{ getStudentTrainingStepCount \} from "@\/views\/training\/taskKeyMap";/.test(editor));
assert(/const expectedCount = getStudentTrainingStepCount\(taskKey\);/.test(editor));
assert(/Array\.from\(\{ length: expectedCount \}/.test(editor));
assert(/steps: JSON\.stringify\(fixedSteps\)/.test(editor));
assert(/步骤名称(固定 \$\{taskForm\.steps\.length\} 步)/.test(editor));
assert(!/@click="addStep"/.test(editor), `${name} editor must not add steps`);
assert(!/@click="removeStep/.test(editor), `${name} editor must not remove steps`);
assert(!/新增步骤/.test(editor), `${name} editor must not show add-step control`);
}
console.log("teacher and admin training task fixed-step contracts passed");