Files
MyGoNavi/frontend/src/components/DataExportDialog.columns.test.ts
Syngnat 15fba1d89f feat(import-export): 优化数据表导入导出能力
- 修复表格格式导出时空值显示为 null 的问题
- 支持按列导出并保持字段顺序
- 支持导入列与数据库字段映射及冲突校验
- 隔离并发导入任务进度并完善元数据回退

Fixes #646
2026-07-18 15:17:54 +08:00

65 lines
1.9 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import {
normalizeDataExportDialogValues,
resolveDataExportColumns,
validateDataExportDialogValues,
type DataExportScopeOption,
} from './DataExportDialog';
const scopeOptions: DataExportScopeOption[] = [
{ value: 'all', label: 'All rows' },
];
describe('DataExportDialog column selection', () => {
it('selects every available column by default in source order', () => {
expect(resolveDataExportColumns(undefined, ['id', 'name', 'created_at'])).toEqual([
'id',
'name',
'created_at',
]);
expect(normalizeDataExportDialogValues(
scopeOptions,
{ format: 'csv', scope: 'all' },
false,
['id', 'name', 'created_at'],
).columns).toEqual(['id', 'name', 'created_at']);
});
it('drops unknown and duplicate selections while preserving available column order', () => {
expect(resolveDataExportColumns(
['created_at', 'missing', 'id', 'created_at'],
['id', 'name', 'created_at'],
)).toEqual(['id', 'created_at']);
});
it('requires at least one column when columns are available', () => {
const values = normalizeDataExportDialogValues(
scopeOptions,
{ format: 'csv', scope: 'all', columns: [] },
false,
['id', 'name'],
);
expect(validateDataExportDialogValues(values, scopeOptions, false, ['id', 'name'])).toBeTruthy();
expect(validateDataExportDialogValues(
{ ...values, columns: ['name'] },
scopeOptions,
false,
['id', 'name'],
)).toBeNull();
});
it('keeps legacy exports without a column catalog unrestricted', () => {
const values = normalizeDataExportDialogValues(
scopeOptions,
{ format: 'csv', scope: 'all' },
false,
);
expect(values.columns).toBeUndefined();
expect(validateDataExportDialogValues(values, scopeOptions)).toBeNull();
});
});