feat(app): artifact viewer shows CSV and TSV files as tables
This commit is contained in:
@@ -111,7 +111,6 @@ void main() {
|
||||
);
|
||||
for (final (contentType, name) in <(String, String)>[
|
||||
('text/html', 'session.html'),
|
||||
('text/csv', 'rows.csv'),
|
||||
('application/zip', 'bundle.zip'),
|
||||
('application/octet-stream', 'blob.bin'),
|
||||
('', ''),
|
||||
|
||||
@@ -85,7 +85,6 @@ void main() {
|
||||
|
||||
test('unsupported types are explicit instead of a fake preview', () {
|
||||
for (final record in <ArtifactRecord>[
|
||||
_record('result.csv', contentType: 'text/csv'),
|
||||
_record('bundle.zip', contentType: 'application/zip'),
|
||||
]) {
|
||||
final plan = _plan(record);
|
||||
@@ -103,4 +102,14 @@ void main() {
|
||||
expect(plan.message, isEmpty);
|
||||
expect(plan.resolved, isNotNull);
|
||||
});
|
||||
|
||||
test('CSV and TSV are tables, with their own delimiter', () {
|
||||
final csv = _plan(_record('result.csv', contentType: 'text/csv'));
|
||||
expect(csv.kind, ArtifactPreviewKind.table);
|
||||
expect(csv.canFetch, isTrue);
|
||||
expect(csv.delimiter, ',');
|
||||
final tsv = _plan(_record('rows.tsv', contentType: 'text/plain'));
|
||||
expect(tsv.kind, ArtifactPreviewKind.table);
|
||||
expect(tsv.delimiter, '\t');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_table.dart';
|
||||
|
||||
void main() {
|
||||
test('plain rows split on the delimiter', () {
|
||||
final table = parseArtifactTable('id,name\n1,alpha\n2,beta\n');
|
||||
expect(table.rows, [
|
||||
['id', 'name'],
|
||||
['1', 'alpha'],
|
||||
['2', 'beta'],
|
||||
]);
|
||||
expect(table.totalRows, 3);
|
||||
expect(table.truncated, isFalse);
|
||||
expect(table.columnCount, 2);
|
||||
});
|
||||
|
||||
test('quoted fields keep delimiters, line breaks and doubled quotes', () {
|
||||
final table = parseArtifactTable(
|
||||
'k,v\r\n"a,b","line1\nline2"\r\n"say ""hi""",\r\n',
|
||||
);
|
||||
expect(table.rows, [
|
||||
['k', 'v'],
|
||||
['a,b', 'line1\nline2'],
|
||||
['say "hi"', ''],
|
||||
]);
|
||||
});
|
||||
|
||||
test('ragged rows are kept as recorded', () {
|
||||
final table = parseArtifactTable('a,b,c\n1\n1,2,3,4');
|
||||
expect(table.rows, [
|
||||
['a', 'b', 'c'],
|
||||
['1'],
|
||||
['1', '2', '3', '4'],
|
||||
]);
|
||||
expect(table.columnCount, 4);
|
||||
});
|
||||
|
||||
test('tab-separated values use the tab delimiter', () {
|
||||
final table = parseArtifactTable('a\tb\n1\t2', delimiter: '\t');
|
||||
expect(table.rows, [
|
||||
['a', 'b'],
|
||||
['1', '2'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('a large file is capped and says how many rows it has', () {
|
||||
final text = List.generate(10, (i) => 'r$i').join('\n');
|
||||
final table = parseArtifactTable(text, limit: 4);
|
||||
expect(table.rows, hasLength(4));
|
||||
expect(table.totalRows, 10);
|
||||
expect(table.truncated, isTrue);
|
||||
});
|
||||
|
||||
test('an empty file has no rows', () {
|
||||
expect(parseArtifactTable('').rows, isEmpty);
|
||||
expect(parseArtifactTable('\n').totalRows, 0);
|
||||
});
|
||||
}
|
||||
@@ -42,6 +42,7 @@ void main() {
|
||||
'main.py',
|
||||
'clip.mp4',
|
||||
'memory.txt',
|
||||
'rows.csv',
|
||||
'output.md',
|
||||
]);
|
||||
expect(pagedArtifacts(const []), isEmpty);
|
||||
@@ -163,7 +164,7 @@ void main() {
|
||||
artifacts: <Map<String, dynamic>>[
|
||||
artifact('session.html', contentType: 'text/html'),
|
||||
artifact('bundle.zip', contentType: 'application/zip'),
|
||||
artifact('result.csv', contentType: 'text/csv'),
|
||||
artifact('report.pdf', contentType: 'application/pdf'),
|
||||
],
|
||||
),
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user