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/product-diagnosis-dynamic-c...

59 lines
3.3 KiB
JavaScript

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 class="fixed-column">链路节点<\/th>[\s\S]*?v-for="channel in channels"[\s\S]*?<th class="fixed-column">行业均值<\/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><th>抖音<\/th><th>拼多多<\/th>/);
});
test("百分号与转化率输入框保持同行", () => {
assert.match(page, /<div class="rate-input">[\s\S]*?<el-input-number[\s\S]*?<span class="unit">%<\/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 class="unit">%<\/span>/g)];
assert.equal(units.length, 7);
units.forEach(({ index }) => {
assert.ok(page.lastIndexOf('<div class="rate-input">', index) > page.lastIndexOf("<td", index));
});
});
test("三个步骤的后端校验错误均交由页面显示单条中文提示", () => {
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\)/);
});