刘光辉
7 小时以前 0dfe84494048ce27ba8449831782128412d3eb13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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&amp;B&lt;项目&gt;');
    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');
  });
});