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*]*>\{\{ 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 = { "市场规模": "25–35", "市场潜力": "25–35", "竞争强度": "20–30", "运营难度": "10–20", }; 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 = ["25–35", "65–75", "55–65", "35–45", "25–35", "35–45", "25–35", "55–65", "35–45"]; 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(/([\s\S]*?)<\/table>/)?.[1] || ""; assert.match(weightTable, /
\{\{ formatWeight\(correspondingWeight\(item\)\) \}\}%<\/td>/); assert.doesNotMatch(weightTable, /class="corresponding-weight"[^>]*>[\s\S]* { 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\(\);/); });