界面:表格长文本列统一左对齐,保留名称与属性对齐
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { tableTextAlignment } from '../src/tableTextAlignment.ts';
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
@@ -14,14 +15,14 @@ import {
|
||||
const exportSource = fs.readFileSync(new URL('../src/AnalysisReportExport.tsx', import.meta.url), 'utf8');
|
||||
const reportDocumentSource = exportSource.slice(exportSource.indexOf('function ReportDocument('), exportSource.indexOf('\nfunction reportHtmlFromElement('));
|
||||
const node = (tag, props) => React.createElement(tag, props, props?.children);
|
||||
const ReportDocument = new Function('React', 'reportCss', 'record', 'text', 'buildAnalysisNarrative', 'analysisScopeText',
|
||||
const ReportDocument = new Function('tableTextAlignment', 'React', 'reportCss', 'record', 'text', 'buildAnalysisNarrative', 'analysisScopeText',
|
||||
'parseServerReadingSummary', 'resolveAnalysisReportTitle', 'sanitizeAnalysisDisplayText', 'stripDuplicateFirstMarkdownH1', 'AnalysisReportNarrative',
|
||||
'AnalysisLegacyResults', 'AnalysisRecordListReport', 'analysisMemberListFullyRead', 'analysisMemberListPeriod', 'parseAnalysisMemberList',
|
||||
ts.transpileModule(`${reportDocumentSource}\nreturn ReportDocument;`, {
|
||||
fileName: 'analysis-report-document.tsx',
|
||||
compilerOptions: { target: ts.ScriptTarget.ES2022, jsx: ts.JsxEmit.React },
|
||||
}).outputText
|
||||
)(React, '', value => value && typeof value === 'object' && !Array.isArray(value) ? value : {},
|
||||
)(tableTextAlignment, React, '', value => value && typeof value === 'object' && !Array.isArray(value) ? value : {},
|
||||
value => value === null || value === undefined || value === '' ? '—' : String(value),
|
||||
() => ({ period: '2026年9月' }), () => '', parseServerReadingSummary, () => '分析报告', value => value, value => value,
|
||||
({ answer }) => node('div', { className: 'report-summary', children: answer }), () => null, () => null,
|
||||
@@ -51,7 +52,7 @@ test('the report includes every member row beyond the former 150-row limit as a
|
||||
|
||||
assert.match(html, /<h2>成员清单<\/h2>/);
|
||||
assert.match(html, /<th>成员<\/th>/);
|
||||
assert.match(html, /<th>备注<\/th>/);
|
||||
assert.match(html, /<th style="text-align:left">备注<\/th>/);
|
||||
assert.match(html, /<th>阶段<\/th>/);
|
||||
assert.equal((html.match(/<tr/g) || []).length, 182);
|
||||
assert.match(html, /最后一行成员181/);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { tableTextAlignment } from '../src/tableTextAlignment.ts';
|
||||
import { originalAnalysisBody, originalAnalysisSections } from '../src/analysisOriginalBody.ts';
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
@@ -32,7 +33,7 @@ function component(source, name, bindings) {
|
||||
}).outputText)(React, ...Object.values(bindings));
|
||||
}
|
||||
const markdownSource = readFileSync(new URL('../src/AiMarkdown.tsx', import.meta.url), 'utf8');
|
||||
const AiMarkdown = component(markdownSource, 'AiMarkdown', { sanitizeAnalysisDisplayText, analysisEvidenceParts });
|
||||
const AiMarkdown = component(markdownSource, 'AiMarkdown', { sanitizeAnalysisDisplayText, analysisEvidenceParts, tableTextAlignment });
|
||||
OriginalContent=component(readFileSync(new URL('../src/AnalysisOriginalContent.tsx',import.meta.url),'utf8'),'AnalysisOriginalContent',{AiMarkdown,originalAnalysisSections});
|
||||
|
||||
test('conclusion layout separates the lead, findings and table titles without rewriting checked facts', () => {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { tableTextAlignment } from '../src/tableTextAlignment.ts';
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
@@ -307,9 +308,9 @@ test('the report appendix includes all rows and set coverage, escaping source an
|
||||
const componentSource = fs.readFileSync(new URL('../src/AnalysisRecordList.tsx', import.meta.url), 'utf8');
|
||||
const helpers = componentSource.slice(componentSource.indexOf('function display('), componentSource.indexOf('export function AnalysisRecordListPanel'))
|
||||
+ componentSource.slice(componentSource.indexOf('export function AnalysisRecordListReport'), componentSource.indexOf('/** Add the same all-row appendix'));
|
||||
const Component = new Function('React', 'analysisSourceRecordSetLabel', 'analysisSourceRecordSetReadStatus', 'parseAnalysisSourceRecordList',
|
||||
const Component = new Function('React', 'analysisSourceRecordSetLabel', 'analysisSourceRecordSetReadStatus', 'parseAnalysisSourceRecordList', 'tableTextAlignment',
|
||||
ts.transpileModule(`${helpers.replaceAll('export function ', 'function ')}\nreturn AnalysisRecordListReport;`, { fileName: 'analysis-record-report.tsx', compilerOptions: { target: ts.ScriptTarget.ES2022, jsx: ts.JsxEmit.React } }).outputText
|
||||
)(React, analysisSourceRecordSetLabel, analysisSourceRecordSetReadStatus, parseAnalysisSourceRecordList);
|
||||
)(React, analysisSourceRecordSetLabel, analysisSourceRecordSetReadStatus, parseAnalysisSourceRecordList, tableTextAlignment);
|
||||
const html = renderToStaticMarkup(React.createElement(Component, { value: recordList }));
|
||||
assert.equal((html.match(/<tr/g) || []).length, 248);
|
||||
assert.match(html, /数学A · 黑片 · 2026年9月/);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { tableTextAlignment } from '../src/tableTextAlignment.ts';
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
@@ -157,8 +158,8 @@ test('export from the actual drawer keeps the clicked release even after current
|
||||
});
|
||||
|
||||
function tableFixture(props) {
|
||||
const code=read('QualityTable.tsx').slice(read('QualityTable.tsx').indexOf('type QualityTableProps')).replace('export function QualityTable','function QualityTable');
|
||||
const renderer=hookRenderer(hooks=>new Function('React','useState','useContext','CompactManagementTables','AntdTable',transpile(`${code}\nreturn QualityTable;`))(React,hooks.useState,()=>false,{},'AntdTable'));
|
||||
const code=read('QualityTable.tsx').slice(read('QualityTable.tsx').indexOf('function titleText')).replaceAll('export function ', 'function ');
|
||||
const renderer=hookRenderer(hooks=>new Function('React','tableTextAlignment','isValidElement','useState','useContext','CompactManagementTables','AntdTable',transpile(`${code}\nreturn QualityTable;`))(React,tableTextAlignment,React.isValidElement,hooks.useState,()=>false,{},'AntdTable'));
|
||||
return {render:()=>find(renderer.render(props),n=>n.type==='AntdTable').props,props};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import ts from 'typescript';
|
||||
import React from 'react';
|
||||
import { tableTextAlignment, alignReportTableText } from '../src/tableTextAlignment.ts';
|
||||
|
||||
const source = fs.readFileSync(new URL('../src/QualityTable.tsx', import.meta.url), 'utf8');
|
||||
const helper = source.slice(source.indexOf('function titleText'), source.indexOf('function compactColumns')).replaceAll('export function ', 'function ');
|
||||
const alignTableColumns = new Function('isValidElement', 'tableTextAlignment', ts.transpileModule(helper + '\nreturn alignTableColumns;', {
|
||||
compilerOptions: { target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.ESNext },
|
||||
}).outputText)(React.isValidElement, tableTextAlignment);
|
||||
|
||||
test('prose columns align left even with short or empty current values; names and categorical attributes stay centered', () => {
|
||||
for (const name of ['说明', '失败原因', '计算口径', '当前计算公式', '特殊情况处理', '原始行数据', '差异项', '阈值配置', 'description', 'error_message']) {
|
||||
assert.equal(tableTextAlignment(name), 'left', name);
|
||||
}
|
||||
for (const name of ['产品名称', '说明类型', '证据状态', '错误码', '属性', '来源文件', '月份', 'status']) {
|
||||
assert.equal(tableTextAlignment(name, ['很长的名称'.repeat(20)]), 'center', name);
|
||||
}
|
||||
assert.equal(tableTextAlignment('自定义列', ['短', '这是一段需要左对齐的较长业务文本。'.repeat(3)]), 'left');
|
||||
assert.equal(tableTextAlignment('自定义列', ['首行\n下一行']), 'left');
|
||||
assert.equal(tableTextAlignment('重量', [123, null]), 'center');
|
||||
});
|
||||
|
||||
test('grouped and dynamic source columns preserve numeric alignment, callbacks and original definitions', () => {
|
||||
const render = () => { throw new Error('classification must not execute cell renderers'); };
|
||||
const columns = [{ title: '分组', children: [
|
||||
{ title: React.createElement('span', null, '当前计算公式'), align: 'center', className: 'original', render },
|
||||
{ title: '自定义', dataIndex: ['raw', '含.标点'], render },
|
||||
{ title: '产品名称', dataIndex: 'name' },
|
||||
{ title: '重量', dataIndex: 'weight', align: 'right' },
|
||||
] }];
|
||||
const result = alignTableColumns(columns, [{ raw: { '含.标点': '详细记录'.repeat(20) }, name: '名称'.repeat(30), weight: 42 }]);
|
||||
assert.deepEqual(result[0].children.map(column => column.align), ['left', 'left', 'center', 'right']);
|
||||
assert.equal(result[0].children[0].render, render);
|
||||
assert.equal(result[0].children[0].className, 'original quality-table-text-column');
|
||||
assert.equal(columns[0].children[0].align, 'center');
|
||||
});
|
||||
|
||||
test('native report prose cells and their headers align left without changing names or numbers', () => {
|
||||
const cell = (text, tagName = 'TD') => ({ textContent: text, tagName, colSpan: 1, rowSpan: 1, style: { setProperty(...args) { this.applied = args; } } });
|
||||
const header = { cells: [cell('产品名称', 'TH'), cell('备注', 'TH'), cell('重量', 'TH')] };
|
||||
const row = { cells: [cell('产品甲'), cell('需现场核实'), cell('120')] };
|
||||
const table = { rows: [header, row], tHead: { rows: [header] } };
|
||||
alignReportTableText({ querySelectorAll: () => [table] });
|
||||
assert.deepEqual(header.cells[1].style.applied, ['text-align', 'left', 'important']);
|
||||
assert.deepEqual(row.cells[1].style.applied, ['text-align', 'left', 'important']);
|
||||
assert.equal(row.cells[0].style.applied, undefined);
|
||||
assert.equal(row.cells[2].style.applied, undefined);
|
||||
});
|
||||
Reference in New Issue
Block a user