|
|
|
|
@ -21,6 +21,51 @@ const pages = {
|
|
|
|
|
'digitalMarketingAlgorithms/components/descriptiveStatistics': [1],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
test('numeric Excel pricing accepts teacher markups and enforces the raised channel limits', async () => {
|
|
|
|
|
const h = await helpers;
|
|
|
|
|
const state = await harness('product/price');
|
|
|
|
|
state.unitCost.value = '112';
|
|
|
|
|
const table = state.numericExcelTables.value[0];
|
|
|
|
|
const rows = h.templateRows(table);
|
|
|
|
|
const column = table.columns.findIndex(item => item.key === 'markupRate') + 1;
|
|
|
|
|
['20%', '160%', '260%'].forEach((rate, index) => { rows[index + 1][column] = rate; });
|
|
|
|
|
table.apply(h.parseTableRows(rows, table).rows);
|
|
|
|
|
assert.equal(state.validateStepOne(), '');
|
|
|
|
|
assert.deepEqual(plain(state.pricingRows.value.map(row => state.formatMoney(state.salePrice(row)))), ['134.40', '291.20', '403.20']);
|
|
|
|
|
const saved = plain(state.buildStepOneProgress());
|
|
|
|
|
const restored = await harness('product/price');
|
|
|
|
|
restored.applyStepOneProgress(saved);
|
|
|
|
|
assert.equal(restored.validateStepOne(), '');
|
|
|
|
|
assert.equal(restored.pricingRows.value[1].markupRate, '160');
|
|
|
|
|
assert.equal(restored.pricingRows.value[2].markupRate, '260');
|
|
|
|
|
assert.match(restored.rateHint(restored.pricingRows.value[1]), /40%-200%/);
|
|
|
|
|
assert.match(restored.rateHint(restored.pricingRows.value[2]), /70%-300%/);
|
|
|
|
|
for (const rates of [[20, 40, 70], [25, 200, 300], [20, 199.99, 299.99]]) {
|
|
|
|
|
rates.forEach((rate, index) => { restored.pricingRows.value[index].markupRate = String(rate); });
|
|
|
|
|
assert.equal(restored.validateStepOne(), '');
|
|
|
|
|
}
|
|
|
|
|
for (const [index, rate] of [[0, 14.99], [0, 25.01], [1, 39.99], [1, 200.01], [2, 69.99], [2, 300.01]]) {
|
|
|
|
|
[20, 160, 260].forEach((valid, i) => { restored.pricingRows.value[i].markupRate = String(valid); });
|
|
|
|
|
restored.pricingRows.value[index].markupRate = String(rate);
|
|
|
|
|
assert.notEqual(restored.validateStepOne(), '');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('pricing demo uses the same raised markup limits and sale price calculation', async () => {
|
|
|
|
|
const source = fs.readFileSync(path.resolve(__dirname, '../src/api/studentTrainingAnswer.js'), 'utf8');
|
|
|
|
|
const fn = babel.parse(source, { sourceType: 'module' }).program.body
|
|
|
|
|
.find(node => node.type === 'ExportNamedDeclaration' && node.declaration?.id?.name === 'validateProductPricingStepOne').declaration;
|
|
|
|
|
const context = { isStudentDemo: () => true };
|
|
|
|
|
vm.runInNewContext(source.slice(fn.start, fn.end), context);
|
|
|
|
|
const payload = rates => ({ unitCost: 112, pricingRows: ['dealer', 'direct-retail', 'premium-brand'].map((id, index) => ({ id, markupRate: rates[index] })) });
|
|
|
|
|
const result = await context.validateProductPricingStepOne(payload([20, 160, 260]));
|
|
|
|
|
assert.deepEqual(plain(result.data.pricingRows.map(row => row.salePrice)), [134.4, 291.2, 403.2]);
|
|
|
|
|
assert.equal((await context.validateProductPricingStepOne(payload([25, 200, 300]))).data.valid, true);
|
|
|
|
|
for (const rates of [[26, 160, 260], [20, 200.01, 260], [20, 160, 300.01]]) {
|
|
|
|
|
await assert.rejects(context.validateProductPricingStepOne(payload(rates)));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
async function harness(page, overrides = {}) {
|
|
|
|
|
const helper = await helpers;
|
|
|
|
|
const stepAnswers = await import("../src/views/training/trainingStepAnswers.mjs");
|
|
|
|
|
@ -108,6 +153,57 @@ for (const [page, steps] of Object.entries(pages)) test('numeric Excel round tri
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('promotion restores latest third-step ROI instead of stale evaluation ROI and submits it', async () => {
|
|
|
|
|
const channels=['抖音','天猫','唯品会'],rois=[1.3,1.68,1.8],writes=[],errors=[];
|
|
|
|
|
const evaluation=channels.map((channel,index)=>({channel,roi:index<2?1:1.8,achievement:index===0?'不达标':'达标',problemDiagnosis:index===0?'获客成本过高':'',optimizationAction:index===0?'优化素材与出价':''}));
|
|
|
|
|
const answer={currentStep:4,step1Answer:JSON.stringify({totalBudget:150000,rows:channels.map(channel=>({channel}))}),
|
|
|
|
|
step3Answer:JSON.stringify({grossMargin:68,breakEvenRoi:1.47,rows:[...channels.map((channel,index)=>({channel,actualRoi:rois[index]})),{channel:'合计',actualRoi:1.45}]}),
|
|
|
|
|
step4Answer:JSON.stringify({rows:evaluation,optimizationDecision:'优先优化抖音渠道'})};
|
|
|
|
|
const state=await harness('test/promotion',{
|
|
|
|
|
getStudentTrainingAnswer:async()=>({data:answer}),
|
|
|
|
|
validatePromotionEffectOptimizationStepFour:async payload=>{assert.deepEqual(plain(payload.rows.map(row=>row.roi)),rois);},
|
|
|
|
|
saveStudentTrainingAnswer:async(key,payload)=>writes.push({key,payload}),
|
|
|
|
|
ElMessage:{success(){},error:message=>errors.push(message)},
|
|
|
|
|
});
|
|
|
|
|
await state.loadProgress();
|
|
|
|
|
assert.deepEqual(plain(state.evaluationRows.value.map(row=>row.roi)),rois);
|
|
|
|
|
assert.equal(state.evaluationRows.value[0].problemDiagnosis,evaluation[0].problemDiagnosis);
|
|
|
|
|
assert.equal(state.evaluationRows.value[0].optimizationAction,evaluation[0].optimizationAction);
|
|
|
|
|
assert.equal(state.evaluationRows.value[1].achievement,'达标');
|
|
|
|
|
assert.equal(state.optimizationDecision.value,'优先优化抖音渠道');
|
|
|
|
|
await state.submitTask();
|
|
|
|
|
assert.deepEqual(errors,[]);assert.equal(writes.length,1);
|
|
|
|
|
assert.equal(writes[0].payload.saveAction,'SUBMIT');
|
|
|
|
|
assert.deepEqual(JSON.parse(writes[0].payload.step4Answer).rows.map(row=>row.roi),rois);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('promotion revalidating third step refreshes ROI while keeping evaluation answers', async () => {
|
|
|
|
|
const writes=[];
|
|
|
|
|
const state=await harness('test/promotion',{
|
|
|
|
|
validatePromotionEffectOptimizationStepThree:async()=>({}),
|
|
|
|
|
saveStudentTrainingAnswer:async(key,payload)=>writes.push(payload),
|
|
|
|
|
ElMessage:{success(){},error:message=>assert.fail(message)},
|
|
|
|
|
});
|
|
|
|
|
state.performanceRows.value=[{channel:'抖音',actualRoi:1.3},{channel:'天猫',actualRoi:1.68},{channel:'合计',actualRoi:1.45}];
|
|
|
|
|
state.evaluationRows.value=[{channel:'天猫',roi:1,achievement:'达标'}, {channel:'抖音',roi:1,achievement:'不达标',problemDiagnosis:'成本过高',optimizationAction:'优化出价'}];
|
|
|
|
|
await state.validatePerformance();
|
|
|
|
|
assert.equal(state.activeStep.value,4);
|
|
|
|
|
assert.equal(writes.length,1);assert.ok(writes[0].step3Answer);
|
|
|
|
|
assert.deepEqual(plain(state.evaluationRows.value.map(row=>row.roi)),[1.3,1.68]);
|
|
|
|
|
assert.equal(state.evaluationRows.value[0].problemDiagnosis,'成本过高');
|
|
|
|
|
assert.equal(state.evaluationRows.value[1].achievement,'达标');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('promotion evaluation payload follows current channels and preserves zero ROI', async () => {
|
|
|
|
|
const state=await harness('test/promotion');
|
|
|
|
|
state.performanceRows.value=[{channel:'天猫',actualRoi:0},{channel:'京东',actualRoi:undefined},{channel:'合计',actualRoi:1}];
|
|
|
|
|
state.evaluationRows.value=[{channel:'天猫',roi:9,achievement:'不达标',problemDiagnosis:'无成交',optimizationAction:'调整素材'},{channel:'京东',roi:2},{channel:'旧渠道',roi:3}];
|
|
|
|
|
const payload=state.evaluationPayload();
|
|
|
|
|
assert.deepEqual(plain(payload.rows.map(row=>row.channel)),['天猫','京东']);
|
|
|
|
|
assert.equal(payload.rows[0].roi,0);assert.equal(payload.rows[1].roi,undefined);
|
|
|
|
|
assert.equal(payload.rows[0].problemDiagnosis,'无成交');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('numeric Excel validates the entire file before mutation', async () => {
|
|
|
|
|
const h = await helpers;
|
|
|
|
|
const rows = [{ id: 'a', name: '天猫', count: 4, rate: 6, note: '保留' }, { id: 'b', name: '京东', count: 8, rate: 9 }];
|
|
|
|
|
@ -508,7 +604,7 @@ test('numeric Excel ignores a pending import after its table controls unmount',
|
|
|
|
|
assert.equal(errors.length,1); assert.match(errors[0],/已变化/);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('numeric Excel PSM imports six price ranges and saves percentages without changing chart or price points', async () => {
|
|
|
|
|
test('numeric Excel PSM imports editable price ranges and saves percentages without changing chart or price points', async () => {
|
|
|
|
|
for(const bookType of ['xls','xlsx']) {
|
|
|
|
|
const saved=[], validations=[], errors=[], downloads=[];
|
|
|
|
|
const state=await harness('product/price',{
|
|
|
|
|
@ -533,9 +629,13 @@ test('numeric Excel PSM imports six price ranges and saves percentages without c
|
|
|
|
|
const template=XLSX.utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[0]],{header:1,defval:''});
|
|
|
|
|
assert.equal(template.length,7);
|
|
|
|
|
assert.deepEqual(template.slice(1).map(r=>r[1]),ranges);
|
|
|
|
|
assert.equal(state.numericExcelTables.value[0].columns[0].readonly, undefined);
|
|
|
|
|
const instructions=XLSX.utils.sheet_to_json(workbook.Sheets['填写说明'],{header:1,defval:''});
|
|
|
|
|
assert.equal(instructions.find(row=>row[0]==='价格区间')[1],'填写文本');
|
|
|
|
|
assert.ok(template.slice(1).every(r=>r.slice(2).every(v=>v==='')));
|
|
|
|
|
const values=[[0,100,3,100],[3,60,11.5,50],[9,30,29,18],[29,14,71,8],[67,6,91,3],[100,2,100,1]];
|
|
|
|
|
const data=[template[0],...values.map((r,i)=>[i+1,ranges[i],...r]).reverse()];
|
|
|
|
|
const importedRanges=['≤599元','599~699元','699~799元','799~899元','899~999元','≥999元'];
|
|
|
|
|
const data=[template[0],...values.map((r,i)=>[i+1,importedRanges[i],...r]).reverse()];
|
|
|
|
|
const sheet=XLSX.utils.aoa_to_sheet(data);
|
|
|
|
|
sheet.E2={t:'n',v:1,z:'0%'}; // A genuine Excel percentage cell, displayed as 100%.
|
|
|
|
|
sheet.E6={t:'s',v:'11.5%'};
|
|
|
|
|
@ -545,7 +645,7 @@ test('numeric Excel PSM imports six price ranges and saves percentages without c
|
|
|
|
|
assert.deepEqual(errors,[]); assert.equal(saved.length,0);
|
|
|
|
|
assert.deepEqual(plain(state.psmRows.value.map(r=>r.id)),plain(ids));
|
|
|
|
|
state.psmRows.value.forEach((row,i)=>{
|
|
|
|
|
assert.equal(row.priceRange,ranges[i]);
|
|
|
|
|
assert.equal(row.priceRange,importedRanges[i]);
|
|
|
|
|
['tooExpensive','tooCheap','expensiveAcceptable','cheapValue'].forEach((field,j)=>assert.equal(Number(row[field]),values[i][j]));
|
|
|
|
|
});
|
|
|
|
|
assert.equal(state.validationMessage.value,'');
|
|
|
|
|
@ -560,10 +660,11 @@ test('numeric Excel PSM imports six price ranges and saves percentages without c
|
|
|
|
|
assert.equal(answer.chart.url,chart.url); assert.equal(answer.pricePoints.optimalPrice,599);
|
|
|
|
|
const restored=await harness('product/price'); restored.applyStepFourProgress(answer);
|
|
|
|
|
assert.equal(restored.psmRows.value[1].expensiveAcceptable,11.5);
|
|
|
|
|
assert.deepEqual(plain(restored.psmRows.value.map(row=>row.priceRange)), importedRanges);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('numeric Excel PSM rejects invalid percentages and changed price ranges without overwriting existing rows', async () => {
|
|
|
|
|
test('numeric Excel PSM rejects invalid percentages and accepts changed price ranges atomically', async () => {
|
|
|
|
|
const h=await helpers;
|
|
|
|
|
const state=await harness('product/price'); state.currentStep.value=4;
|
|
|
|
|
state.psmRows.value.forEach(r=>{r.tooExpensive='1';r.tooCheap='2';r.expensiveAcceptable='3';r.cheapValue='4';});
|
|
|
|
|
@ -574,7 +675,9 @@ test('numeric Excel PSM rejects invalid percentages and changed price ranges wit
|
|
|
|
|
assert.throws(()=>h.parseTableRows([header,[1,first,5,6,7,8],[2,second,bad,2,3,4]],table));
|
|
|
|
|
assert.equal(JSON.stringify(state.psmRows.value),before);
|
|
|
|
|
}
|
|
|
|
|
assert.throws(()=>h.parseTableRows([header,[1,'改动了价格区间',5,6,7,8]],table));
|
|
|
|
|
const edited=h.parseTableRows([header,[1,'399~599元',5,6,7,8]],table);
|
|
|
|
|
assert.equal(edited.rows[0].priceRange,'399~599元');
|
|
|
|
|
assert.equal(JSON.stringify(state.psmRows.value),before);
|
|
|
|
|
assert.throws(()=>h.parseTableRows([header,[1,first,5,6,7,8],[1,first,5,6,7,8]],table));
|
|
|
|
|
await assert.rejects(h.importTableFile({name:'PSM.xlsx',size:100},table,{
|
|
|
|
|
readWorkbook:async()=>[header,[2,second,'25%',2,3,4]],confirm:async()=>{throw Error('cancel');},isCurrent:()=>true,
|
|
|
|
|
@ -588,6 +691,25 @@ test('numeric Excel PSM rejects invalid percentages and changed price ranges wit
|
|
|
|
|
assert.equal(state.validationMessage.value,'');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('pricing demo accepts editable PSM ranges and still rejects blank or duplicate ranges', async () => {
|
|
|
|
|
const source=fs.readFileSync(path.resolve(__dirname,'../src/api/studentTrainingAnswer.js'),'utf8');
|
|
|
|
|
const fn=babel.parse(source,{sourceType:'module'}).program.body
|
|
|
|
|
.find(node=>node.type==='ExportNamedDeclaration' && node.declaration?.id?.name==='validateProductPricingStepFour').declaration;
|
|
|
|
|
const context={isStudentDemo:()=>true};
|
|
|
|
|
vm.runInNewContext(source.slice(fn.start,fn.end),context);
|
|
|
|
|
const state=await harness('product/price');
|
|
|
|
|
const psmRows=plain(state.psmRows.value).map((row,index)=>({...row,priceRange:`${500+index*100}~${600+index*100}元`,tooExpensive:20,tooCheap:30,expensiveAcceptable:40,cheapValue:50}));
|
|
|
|
|
const payload={psmRows,pricePoints:{optimalPrice:599,acceptablePrice:699,acceptableRange:'499~799元'}};
|
|
|
|
|
const result=await context.validateProductPricingStepFour(payload);
|
|
|
|
|
assert.deepEqual(plain(result.data.psmRows.map(row=>row.priceRange)),psmRows.map(row=>row.priceRange));
|
|
|
|
|
for(const label of ['',psmRows[1].priceRange]) {
|
|
|
|
|
const invalid=plain(payload);invalid.psmRows[0].priceRange=label;
|
|
|
|
|
await assert.rejects(context.validateProductPricingStepFour(invalid));
|
|
|
|
|
}
|
|
|
|
|
const invalid=plain(payload);invalid.psmRows[0].tooExpensive=100.01;
|
|
|
|
|
await assert.rejects(context.validateProductPricingStepFour(invalid));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('numeric Excel PSM import controls render above the fourth step table with original units', async () => {
|
|
|
|
|
const filename=path.resolve(__dirname,'../src/views/product/price.vue');
|
|
|
|
|
const descriptor=parse(fs.readFileSync(filename,'utf8')).descriptor;
|
|
|
|
|
@ -609,6 +731,9 @@ test('numeric Excel PSM import controls render above the fourth step table with
|
|
|
|
|
assert.ok(toolbar<html.indexOf('class="table-scroll"'));
|
|
|
|
|
assert.equal((html.match(/data-test-excel=/g)||[]).length,1);
|
|
|
|
|
assert.match(html,/价格(元)/); assert.match(html,/累计占比(%)/);
|
|
|
|
|
assert.equal((html.match(/aria-label="价格(元)"/g)||[]).length,6);
|
|
|
|
|
state.psmRows.value[0].priceRange='≤599元';
|
|
|
|
|
assert.ok((await render(4)).includes('value="≤599元"'));
|
|
|
|
|
for(const step of [1,2,3]) assert.equal(((await render(step)).match(/data-test-excel=/g)||[]).length,1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|