const assert = require("node:assert/strict"); const fs = require("node:fs"); const path = require("node:path"); const test = require("node:test"); const frontendRoot = path.resolve(__dirname, ".."); const page = fs.readFileSync(path.join(frontendRoot, "src/views/assessment/diagnosis.vue"), "utf8"); const api = fs.readFileSync(path.join(frontendRoot, "src/api/studentTrainingAnswer.js"), "utf8"); test("产品问题诊断第一步固定首尾列并支持动态增删中间渠道", () => { assert.match(page, /链路节点<\/th>[\s\S]*?v-for="channel in channels"[\s\S]*?行业均值<\/th>/); assert.match(page, /@click="addFunnelChannel"/); assert.match(page, /@click="removeFunnelChannel\(channel\.id\)"/); assert.match(page, /row\.channelRates\[channel\.id\]/); assert.doesNotMatch(page, /天猫<\/th>京东<\/th>抖音<\/th>拼多多<\/th>/); }); test("百分号与转化率输入框保持同行", () => { assert.match(page, /
[\s\S]*?%<\/span>[\s\S]*?<\/div>/); assert.match(page, /\.rate-input\{[^}]*display:flex[^}]*white-space:nowrap/); assert.match(page, /\.rate-input \.unit\{[^}]*white-space:nowrap/); }); test("动态渠道随第一步答案提交并用于校验", () => { assert.match(page, /channels: channelSnapshot/); assert.match(page, /channelRates: \{ \.\.\.row\.channelRates \}/); assert.match(api, /data: \{ channels: submittedChannels, conversionRates/); assert.match(api, /source\.channelRates\[channel\.id\]/); }); test("三个步骤的百分比输入全部将百分号固定在输入框同行", () => { const units = [...page.matchAll(/%<\/span>/g)]; assert.equal(units.length, 7); units.forEach(({ index }) => { assert.ok(page.lastIndexOf('
', index) > page.lastIndexOf(" { const validationBlock = api.slice( api.indexOf("export function validateProductDiagnosisIterationStepOne"), api.indexOf("export function validatePromotionEffectOptimizationStepOne") ); assert.equal((validationBlock.match(/skipErrorMessage:\s*true/g) || []).length, 3); assert.match(api, /throw new Error\("正面、中性、负面评论占比之和应为100%。"\)/); assert.match(page, /function diagnosisErrorMessage[\s\S]*?Request failed with status code/); assert.match(page, /validateStepTwo[\s\S]*?diagnosisErrorMessage\(error/); }); test("第二步草稿保存完整分析状态并在重新进入页面后恢复", () => { assert.match(page, /function buildStepTwo\(\)[\s\S]*?totalComments: commentPreview\.value\.totalComments[\s\S]*?analysisResult: analysisResult\.value/); assert.match(page, /function buildStepTwoValidationPayload/); assert.match(page, /validateProductDiagnosisIterationStepTwo\(buildStepTwoValidationPayload\(data\)\)/); assert.match(page, /function restoreStepTwo\(stepTwo\)[\s\S]*?rootCauseAnalysis\.value = stepTwo\.rootCauseAnalysis/); assert.match(page, /analysisResult\.value = \{ sourceFileName, totalComments, positiveCount, neutralCount, negativeCount/); assert.match(page, /restoreStepTwo\(parseSavedStep\(answer\?\.step2Answer\)\)/); assert.doesNotMatch(page, /if \(stepTwo\.sourceFileName\)/); });