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/market-opportunity-step2.st...

67 lines
4.1 KiB
JavaScript

const assert = require("node:assert/strict");
const fs = require("node:fs");
const path = require("node:path");
const test = require("node:test");
const source = fs.readFileSync(path.join(__dirname, "../src/views/product/market-opportunity-selection.vue"), "utf8");
test("第二步按指定顺序渲染固定权重维度,并实时展示每个维度合计", () => {
const expectedIds = [
"search-count", "transaction-amount", "transaction-growth",
"category-transaction-growth", "demand-supply-ratio", "online-products",
"online-merchants", "organic-traffic-ratio", "return-rate",
];
const actualIds = [...source.matchAll(/\{ id: "([^"]+)"/g)].slice(0, 9).map((match) => match[1]);
assert.deepEqual(actualIds, expectedIds);
assert.match(source, /items:\s*indicators\.filter\(\(item\) => item\.group === name\)/);
assert.match(source, /维度内权重合计\s*<strong[^>]*>\{\{ dimensionWeightTotal\(group\.name\) \}\}%<\/strong>/);
});
test("第二步以固定分组计算对应总权重,并在保存前要求所有合计均为 100%", () => {
assert.match(source, /primaryWeights\.value\[item\.group\]/);
const validation = source.match(/function isValidSavedStepTwoOutcome\(primary, dimension\) \{([^}]*)\}/)?.[1] || "";
assert.match(validation, /primaryTotal === 100/);
assert.match(validation, /correspondingTotal === 100/);
assert.match(validation, /calculateDimensionWeightTotal\(group, dimension\) === 100/);
assert.match(source, /function isStepTwoReady\(\) \{ return isValidSavedStepTwoOutcome\(primaryWeights\.value, weights\.value\); \}/);
assert.match(source, /if \(!isStepTwoReady\(\)\) \{ proxy\?\.\$modal\?\.msgError\?\.\("请确认一级指标、维度内权重和对应总权重均为 100%"\); return; \}/);
});
test("第二步为全部一级和二级指标提供题目规定的建议区间与固定分组", () => {
const expectedPrimarySuggestions = {
"市场规模": "2535", "市场潜力": "2535", "竞争强度": "2030", "运营难度": "1020",
};
const expectedMetricGroups = {
"search-count": "市场规模", "transaction-amount": "市场规模",
"transaction-growth": "市场潜力", "category-transaction-growth": "市场潜力",
"demand-supply-ratio": "竞争强度", "online-products": "竞争强度", "online-merchants": "竞争强度",
"organic-traffic-ratio": "运营难度", "return-rate": "运营难度",
};
const expectedMetricSuggestions = ["2535", "6575", "5565", "3545", "2535", "3545", "2535", "5565", "3545"];
const metricEntries = [...source.matchAll(/\{ id: "([^"]+)", name: "[^"]+", group: "([^"]+)", suggestion: "([^"]+)" \}/g)].slice(0, 9);
assert.deepEqual(Object.fromEntries(metricEntries.map(([, id, group]) => [id, group])), expectedMetricGroups);
assert.deepEqual(metricEntries.map(([, , , suggestion]) => suggestion), expectedMetricSuggestions);
for (const [group, suggestion] of Object.entries(expectedPrimarySuggestions)) {
assert.match(source, new RegExp(`"${group}": "${suggestion}"`));
}
});
test("第二步的对应总权重列仅显示计算结果,不提供可编辑输入", () => {
const weightTable = source.match(/<table class="weight-table">([\s\S]*?)<\/table>/)?.[1] || "";
assert.match(weightTable, /<td class="corresponding-weight">\{\{ formatWeight\(correspondingWeight\(item\)\) \}\}%<\/td>/);
assert.doesNotMatch(weightTable, /class="corresponding-weight"[^>]*>[\s\S]*<input/);
});
test("恢复历史第一步答案时,只有与固定分组完全一致的答案才能解锁第二步", () => {
assert.match(source, /stepOnePassed\.value = indicators\.every\(\(item\) => answers\.value\[item\.id\] === item\.group\)/);
});
test("第二步只恢复通过三级 100% 校验的历史权重,失效历史数据保持空白", () => {
assert.match(source, /function isValidSavedStepTwoOutcome\(primary, dimension\)/);
assert.match(source, /if \(isValidSavedStepTwoOutcome\(savedPrimaryWeights, savedDimensionWeights\)\) \{/);
assert.match(source, /primaryWeights\.value = createPrimaryWeights\(\); weights\.value = createWeights\(\);/);
});