summaryrefslogtreecommitdiff
path: root/frontend/src/lib/coverage.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/lib/coverage.test.ts')
-rw-r--r--frontend/src/lib/coverage.test.ts43
1 files changed, 43 insertions, 0 deletions
diff --git a/frontend/src/lib/coverage.test.ts b/frontend/src/lib/coverage.test.ts
new file mode 100644
index 0000000..cf59d54
--- /dev/null
+++ b/frontend/src/lib/coverage.test.ts
@@ -0,0 +1,43 @@
+import { describe, expect, it } from 'vitest';
+import { summarizeCoverage, type CoverageEntry } from './coverage';
+
+describe('summarizeCoverage', () => {
+ const entry = (o: Partial<CoverageEntry>): CoverageEntry => ({
+ instrument: '600000',
+ market: 'SH',
+ asset_type: 'stock',
+ requested_start: '',
+ requested_end: '',
+ actual_start: '',
+ actual_end: '',
+ row_count: 1,
+ ...o
+ });
+
+ it('lists unaligned starts without invented dates', () => {
+ const rows = [
+ entry({ instrument: 'A', actual_start: '2018-01-02', actual_end: '2024-12-31', requested_start: '2015-01-01' }),
+ entry({ instrument: 'B', actual_start: '2020-01-02', actual_end: '2024-12-31', requested_start: '2015-01-01' })
+ ];
+ const s = summarizeCoverage(rows);
+ expect(s.common.start).toBe('2020-01-02');
+ expect(s.common.end).toBe('2024-12-31');
+ expect(s.warnings.includes('B 起始数据较其他标的更晚(2020-01-02)')).toBe(true);
+ });
+
+ it('reports missing rows', () => {
+ const rows = [entry({ instrument: 'C', row_count: 0, actual_start: '', actual_end: '' })];
+ const s = summarizeCoverage(rows);
+ expect(s.warnings.includes('C 没有返回任何数据行')).toBe(true);
+ expect(s.common.start).toBeNull();
+ });
+
+ it('reports different end dates', () => {
+ const rows = [
+ entry({ instrument: 'A', actual_start: '2020-01-02', actual_end: '2024-12-31' }),
+ entry({ instrument: 'B', actual_start: '2020-01-02', actual_end: '2024-11-29' })
+ ];
+ const s = summarizeCoverage(rows);
+ expect(s.warnings.some((w) => w.includes('B 较早结束'))).toBe(true);
+ });
+});