import type { StabilityAnalysisRow } from '#/api/x/lims/wendingxing';
|
|
import { describe, expect, it } from 'vitest';
|
|
import { buildStabilityExport } from '../stabilityExport';
|
|
function row(overrides: Partial<StabilityAnalysisRow> = {}): StabilityAnalysisRow {
|
return {
|
batch_key: 'plan-a::00045',
|
biaozhun_id: 'standard-a',
|
exception_type: 'non_compliant',
|
jieguo_luru_riqi: '2026-07-30T09:30:00',
|
jihua_bianhao: '00123',
|
jihua_id: 'plan-a',
|
numeric_result: 6.7,
|
pihao: '00045',
|
raw_result: '6.70',
|
shangxian: '7.0',
|
shangxian_value: 7,
|
shuju_leixing: '数值',
|
unit: '/',
|
xiaxian: '5.0',
|
xiaxian_value: 5,
|
xiangmu_bianma: 'XM1899',
|
xiangmu_id: 'ph',
|
xiangmu_mingcheng: 'pH值',
|
yangpin_mingcheng: '脉络宁口服液',
|
zhouqi: '18.000000000000000',
|
zhouqi_danwei: 'month',
|
zhouqi_order: 18,
|
...overrides,
|
};
|
}
|
|
describe('buildStabilityExport', () => {
|
it('builds the reference xls format without compliance annotations', () => {
|
const result = buildStabilityExport([row()], new Date(2026, 6, 30, 13, 31, 19));
|
|
expect(result.fileName).toBe('稳定性数据分析表_20260730133119.xls');
|
expect(result.mimeType).toBe('application/vnd.ms-excel;charset=utf-8');
|
expect(result.html).toContain('稳定性数据分析表');
|
expect(result.html).toContain('00123');
|
expect(result.html).toContain('00045');
|
expect(result.html).toContain('2026-07-30');
|
expect(result.html).toContain('>18<');
|
expect(result.html).toContain('>月<');
|
expect(result.html).toContain('>6.70<');
|
expect(result.html).not.toContain('不符合规定');
|
});
|
|
it('escapes cell text and uses slash for a zero-period unit', () => {
|
const result = buildStabilityExport([
|
row({ xiangmu_mingcheng: 'A&B<项目>' }),
|
row({ batch_key: 'plan-a::zero', pihao: 'zero', zhouqi: '0.000', zhouqi_danwei: 'month' }),
|
]);
|
|
expect(result.html).toContain('A&B<项目>');
|
expect(result.html).toContain('>0<');
|
expect(result.html).toContain('>/<');
|
});
|
|
it('writes Excel-compatible inline styles on plain header cells', () => {
|
const result = buildStabilityExport([row()]);
|
const filledHeaders = result.html.match(/<td style="[^"]*background-color:rgb\(38, 183, 255\);[^"]*color:rgb\(255, 255, 255\);/g) || [];
|
|
expect(filledHeaders).toHaveLength(12);
|
expect(result.html).toContain('>单位</td>');
|
expect(result.html).not.toContain('<thead>');
|
expect(result.html).not.toContain('<th');
|
});
|
});
|