Files
juzi/h5/test/water-copy.js

29 lines
3.0 KiB
JavaScript

'use strict';
const assert=require('node:assert/strict'),SS=require('../js/skin-score'),UI=require('../js/report-ui'),Copy=require('../js/report-copy');
function run(score,severity=3,pigment=66,dc=30){
const r=structuredClone(SS.MOCK_RESULT);Object.assign(r.score_info,{water_score:score,melanin_score:pigment,dark_circle_score:dc});
r.melasma={value:0};r.freckle={value:0};r.water={water_severity:severity,water_area:.03};
const vm=SS.buildViewModel(r,SS.MOCK_SIDE,{}),before=JSON.stringify({r,vm});
const presentation=UI.build(vm,r);assert.equal(JSON.stringify({r,vm}),before);
return{r,vm,presentation,water:presentation.views.find(v=>v.key==='water')};
}
const example=run(97);assert.equal(example.vm.cats.tone.P,77.9);assert.equal(example.water.P,97);assert.equal(example.water.level,'优秀');
assert.equal(example.water.text,'角质层含水量充足,肌肤屏障锁水能力强,表面饱满水润,无干燥紧绷表现。');
assert.deepEqual(example.water.advice,Copy.care.water['优秀']);
assert(!example.presentation.care.some(v=>v.name==='水分'),'healthy water97 should not displace a weaker item in global bottom three');
for(const[p,level]of[[0,'改善'],[30,'改善'],[40,'良好'],[60,'良好'],[65,'优秀'],[79.99,'优秀'],[80,'优秀'],[90,'优秀'],[100,'优秀']]){
for(const pigment of[0,50,100]){const x=run(p,3,pigment,0);assert.equal(x.water.level,level);assert.equal(x.water.P,p);assert.deepEqual(x.water.advice,Copy.care.water[level]);}
}
const crossed=run(97,70);assert.equal(crossed.water.P,30);assert.equal(crossed.water.level,'改善');assert.equal(crossed.vm.cats.tone.vars.tone_scoring.water_adjusted_score,30);
assert.equal(crossed.water.text,'角质层含水量较低,缺水面积 3%、肌肤缺水比较严重 70,肌肤含水量偏低,水润度不足,表面偏干燥,容易出现干纹。');
assert.equal(run(40).water.text,'角质层含水量适中,缺水面积 3%、肌肤含水量处于健康水平,整体水润度良好。');
assert(run(20,3).water.text.includes('肌肤缺水比较严重 3'));
assert(!run(20,null).water.text.includes('肌肤缺水比较严重'));
const old=structuredClone(example.presentation);old.copyRule='wrinkles-excellent-acne-detected-v1';old.views.find(v=>v.key==='water').text='水分分 97;旧水分文案';
const savedBefore=JSON.stringify(old),updated=UI.forDisplay(example.vm,example.r,old);
assert.equal(updated.views.find(v=>v.key==='water').text,example.water.text);
assert.equal(JSON.stringify(old),savedBefore,'history snapshot not rewritten');assert.deepEqual(updated.product,old.product);
for(const v of updated.views.filter(v=>v.key!=='water'))assert.equal(v.text,old.views.find(x=>x.key===v.key).text,'other conclusions unchanged');
for(const score of[null,undefined,-1,101,NaN,Infinity]){const x=run(score);assert.equal(x.water.valid,false);assert.equal(x.water.advice,null);assert(!x.presentation.care.some(v=>v.name==='水分'));}
console.log('PASS water: independent copy/advice, displayed 8/9 boundaries, true severity, existing cross-check, missing/invalid, scoring immutable');