|
|
|
|
|
// Generate a self-contained browser regression fixture using the installed Vue/Element Plus.
|
|
|
|
|
|
// Open the printed file URL; assertions run without a server, login, or backend requests.
|
|
|
|
|
|
const fs = require('node:fs');
|
|
|
|
|
|
const path = require('node:path');
|
|
|
|
|
|
const assert = require('node:assert/strict');
|
|
|
|
|
|
const sass = require('sass');
|
|
|
|
|
|
const { parse } = require('@vue/compiler-sfc');
|
|
|
|
|
|
const root = path.resolve(__dirname, '..');
|
|
|
|
|
|
const read = (file) => fs.readFileSync(path.join(root, file), 'utf8');
|
|
|
|
|
|
const directive = read('src/directive/common/trainingFillHints.js').replace('export default', 'window.trainingFillHints =');
|
|
|
|
|
|
|
|
|
|
|
|
// Every currently routed task page must opt in, including both shared task shells.
|
|
|
|
|
|
const router = read('src/router/index.js');
|
|
|
|
|
|
const taskImports = [...router.matchAll(/@\/views\/((?:foundation|demand|product|test|channel|assessment|training)\/[^"']+\.vue)/g)];
|
|
|
|
|
|
for (const [, file] of taskImports) {
|
|
|
|
|
|
assert.match(parse(read(`src/views/${file}`)).descriptor.template.content, /v-training-fill-hints/, `${file} is missing fill hints`);
|
|
|
|
|
|
}
|
|
|
|
|
|
assert.equal(new Set(taskImports.map(([, file]) => file)).size, 30);
|
|
|
|
|
|
|
|
|
|
|
|
const taskStyles = parse(read('src/views/demand/business-feasibility.vue')).descriptor.styles.map((style) => style.content).join('\n');
|
|
|
|
|
|
const css = read('node_modules/element-plus/dist/index.css') + sass.compileString(
|
|
|
|
|
|
read('src/assets/styles/student-training.scss') + '\n' + taskStyles,
|
|
|
|
|
|
{ logger: sass.Logger.silent }
|
|
|
|
|
|
).css;
|
|
|
|
|
|
const fixture = `<!doctype html><html lang="zh-CN"><meta charset="UTF-8"><title>实训填写底色 · 回归验证</title>
|
|
|
|
|
|
<style>${css}
|
|
|
|
|
|
body{margin:24px;background:#fff;font-family:Microsoft YaHei,sans-serif;color:#1f2937}#app{max-width:1080px;margin:auto}
|
|
|
|
|
|
h1{font-size:21px}h2{font-size:16px}table{width:100%;border-collapse:collapse}th{width:160px;text-align:left;background:#f8fafc}td,th{padding:10px;border:1px solid #e5e7eb}
|
|
|
|
|
|
.checks{padding:12px;background:#eff6ff;white-space:pre-wrap;line-height:1.6}.extra-fields{display:grid;grid-template-columns:1fr 1fr;gap:14px;margin-top:22px}.el-radio-group{padding:8px}
|
|
|
|
|
|
</style><div id="app"></div><pre id="results" class="checks">验证中…</pre>
|
|
|
|
|
|
<script>${read('node_modules/vue/dist/vue.global.js')}</script>
|
|
|
|
|
|
<script>${read('node_modules/element-plus/dist/index.full.js')}</script>
|
|
|
|
|
|
<script>${directive}</script>
|
|
|
|
|
|
<script>
|
|
|
|
|
|
const {createApp,ref,nextTick}=Vue;
|
|
|
|
|
|
const taskApp=createApp({setup(){return {text:ref(''),number:ref(undefined),selected:ref(''),choice:ref(''),native:ref(''),disabled:ref(false),rows:ref([]),editor:ref(false),editorText:ref(''),phase:ref('empty')}} ,template:
|
|
|
|
|
|
\`<div class="studentLayout"><section class="app-main"><div class="feasibility-page student-training-shell" v-training-fill-hints>
|
|
|
|
|
|
<h1>商业可行性论证 · 填写区域提示</h1><p>未填写为淡黄色,填写后为白色;清空后重新标黄。</p><h2>项目概述</h2>
|
|
|
|
|
|
<table><tr><th>项目背景</th><td><el-input id="description" v-model="text" :disabled="disabled" type="textarea" :rows="3" placeholder="请输入项目背景" /></td></tr>
|
|
|
|
|
|
<tr><th>已填写内容</th><td><el-input id="prefilled" model-value="结合市场需求分析,明确产品定位与立项目标。" type="textarea" :rows="2" /></td></tr></table>
|
|
|
|
|
|
<div class="extra-fields"><label>成本金额<el-input-number id="amount" v-model="number" :min="0" /></label>
|
|
|
|
|
|
<label>风险等级<el-select id="risk" v-model="selected" placeholder="请选择" clearable><el-option label="高" value="high"/><el-option label="低" value="low"/></el-select></label>
|
|
|
|
|
|
<label>任务判断<el-radio-group id="choice" v-model="choice"><el-radio label="yes">建议立项</el-radio><el-radio label="no">暂缓立项</el-radio></el-radio-group></label>
|
|
|
|
|
|
<label>原生输入<input id="native" v-model="native" /></label><label>只读结果<el-input id="readonly" model-value="系统计算" readonly /></label>
|
|
|
|
|
|
<div class="training-ai-sidebar"><el-input id="ai" placeholder="AI 提问" /></div>
|
|
|
|
|
|
<div class="training-excel-tools"><el-select id="excel" placeholder="选择导入表格"><el-option label="权重" value="weight"/></el-select></div>
|
|
|
|
|
|
<div v-training-fill-hints><el-input id="nested" placeholder="嵌套步骤" /></div>
|
|
|
|
|
|
</div><div v-for="row in rows" :key="row.id"><el-input :id="row.id" v-model="row.value" /></div>
|
|
|
|
|
|
</div></section><el-dialog v-model="editor" append-to-body title="问卷编辑器"><div v-training-fill-hints><el-input id="editor" v-model="editorText" placeholder="题目内容" /></div></el-dialog></div>\`});
|
|
|
|
|
|
taskApp.use(ElementPlus);taskApp.directive('trainingFillHints',window.trainingFillHints);const vm=taskApp.mount('#app');
|
|
|
|
|
|
const results=[];const frame=()=>new Promise(requestAnimationFrame);const flush=async()=>{await nextTick();await frame();await frame()};
|
|
|
|
|
|
function check(condition,message){if(!condition)throw Error(message);results.push('通过:'+message)}
|
|
|
|
|
|
function field(id){return document.getElementById(id)}
|
|
|
|
|
|
function state(id){return field(id)?.getAttribute('data-training-fill-state')}
|
|
|
|
|
|
function color(id){return getComputedStyle(field(id)).backgroundColor}
|
|
|
|
|
|
(async()=>{try{
|
|
|
|
|
|
await flush();
|
|
|
|
|
|
check(state('description')==='empty'&&color('description')==='rgb(255, 247, 214)','空文本显示淡黄色,覆盖任务页原有样式');
|
|
|
|
|
|
check(state('prefilled')==='filled'&&color('prefilled')==='rgb(255, 255, 255)','已有内容显示白底');
|
|
|
|
|
|
check(state('amount')==='empty','空数值显示填写提示');
|
|
|
|
|
|
check(state('risk')==='empty','可编辑的只读式下拉输入显示提示');
|
|
|
|
|
|
check(!state('readonly')&&!state('ai')&&!state('excel'),'只读结果、AI 输入和导入工具不标黄');
|
|
|
|
|
|
check(state('nested')==='empty','嵌套任务组件正常标黄');
|
|
|
|
|
|
field('description').value='学生输入';field('description').dispatchEvent(new Event('input',{bubbles:true}));await flush();
|
|
|
|
|
|
check(state('description')==='filled'&&color('description')==='rgb(255, 255, 255)','输入后恢复白底');
|
|
|
|
|
|
vm.text='';await flush();check(state('description')==='empty','程序清空后重新标黄');
|
|
|
|
|
|
vm.text=' ';await flush();check(state('description')==='empty','只有空格仍视为空');
|
|
|
|
|
|
vm.text='已保存的项目背景';vm.number=0;vm.selected='low';vm.choice='yes';await flush();
|
|
|
|
|
|
check(state('description')==='filled','异步回填内容恢复白底');
|
|
|
|
|
|
check(state('amount')==='filled'&&color('amount')==='rgb(255, 255, 255)','有效数值 0 按已填写处理');
|
|
|
|
|
|
check(state('risk')==='filled'&&color('risk')==='rgb(255, 255, 255)','下拉选择后恢复白底');
|
|
|
|
|
|
check(field('choice').getAttribute('data-training-fill-state')==='filled','单选作答后恢复白底');
|
|
|
|
|
|
vm.selected='';vm.choice='';await flush();check(state('risk')==='empty'&&field('choice').getAttribute('data-training-fill-state')==='empty','清空选择后重新标黄');
|
|
|
|
|
|
vm.disabled=true;await flush();check(!state('description'),'禁用输入不保留填写提示');
|
|
|
|
|
|
vm.disabled=false;await flush();check(state('description')==='filled','重新启用后按实际内容显示');
|
|
|
|
|
|
vm.rows=[{id:'async-row',value:''}];await flush();check(state('async-row')==='empty','动态新增表格行显示填写提示');
|
|
|
|
|
|
vm.rows[0].value='Excel 导入的内容';await flush();check(state('async-row')==='filled','批量导入回填后恢复白底');
|
|
|
|
|
|
vm.editor=true;await flush();check(state('editor')==='empty','传送到 body 的问卷编辑器显示提示');
|
|
|
|
|
|
vm.editorText='调研问题';await flush();check(state('editor')==='filled','问卷编辑器回填恢复白底');
|
|
|
|
|
|
const readonlyRoot=document.createElement('div');readonlyRoot.className='student-task-readonly-preview';readonlyRoot.innerHTML='<div><input></div>';document.body.append(readonlyRoot);
|
|
|
|
|
|
window.trainingFillHints.mounted(readonlyRoot.firstChild);await flush();check(!readonlyRoot.querySelector('input').hasAttribute('data-training-fill-state'),'教师只读预览不标黄');readonlyRoot.remove();
|
|
|
|
|
|
vm.text='';vm.number=undefined;vm.native='';await flush();
|
|
|
|
|
|
document.getElementById('results').textContent=results.join('\\n')+'\\n全部 '+results.length+' 项浏览器验证通过';document.title='PASS '+results.length+' · 实训填写底色';
|
|
|
|
|
|
}catch(error){document.getElementById('results').textContent=results.join('\\n')+'\\n失败:'+error.stack;document.title='FAIL · 实训填写底色'}})();
|
|
|
|
|
|
</script></html>`;
|
|
|
|
|
|
const outputDir = path.join(root, 'tests/e2e/reports');
|
|
|
|
|
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
|
|
|
|
const output = path.join(outputDir, 'training-fill-hints.html');
|
|
|
|
|
|
fs.writeFileSync(output, fixture);
|
|
|
|
|
|
console.log(`Task-page coverage passed: 30 routed components. Browser fixture: file:///${output.replaceAll('\\', '/')}`);
|