feat(app): artifact viewer shows CSV and TSV files as tables
This commit is contained in:
@@ -23,9 +23,9 @@ const _endpoint = 'ws://127.0.0.1:8081/connect';
|
||||
final Uint8List _bytes = Uint8List.fromList(<int>[7, 8, 9]);
|
||||
|
||||
final ArtifactRecord _record = ArtifactRecord.fromJson(<String, dynamic>{
|
||||
'name': 'report.csv',
|
||||
'url': '/artifacts/1/1/report.csv',
|
||||
'content_type': 'text/csv',
|
||||
'name': 'report.zip',
|
||||
'url': '/artifacts/1/1/report.zip',
|
||||
'content_type': 'application/zip',
|
||||
'size_bytes': 3,
|
||||
});
|
||||
|
||||
@@ -115,10 +115,10 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(saved, hasLength(1));
|
||||
expect(saved.single.name, 'report.csv');
|
||||
expect(saved.single.mimeType, 'text/csv');
|
||||
expect(saved.single.name, 'report.zip');
|
||||
expect(saved.single.mimeType, 'application/zip');
|
||||
expect(saved.single.bytes, _bytes);
|
||||
expect(find.text('Downloaded report.csv.'), findsOneWidget);
|
||||
expect(find.text('Downloaded report.zip.'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Share starts one file transfer, not a link', (tester) async {
|
||||
@@ -130,7 +130,7 @@ void main() {
|
||||
await tester.tap(find.text('Share'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(shared.single.name, 'report.csv');
|
||||
expect(shared.single.name, 'report.zip');
|
||||
expect(shared.single.byteLength, 3);
|
||||
expect(find.text('File shared.'), findsOneWidget);
|
||||
});
|
||||
@@ -223,7 +223,7 @@ void main() {
|
||||
stage: 'review',
|
||||
visit: 1,
|
||||
artifacts: <JsonMap>[
|
||||
artifact('report.csv', contentType: 'text/csv', sizeBytes: 3),
|
||||
artifact('report.zip', contentType: 'application/zip', sizeBytes: 3),
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -235,7 +235,7 @@ void main() {
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.text('report.csv'));
|
||||
await tester.tap(find.text('report.zip'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(AlertDialog), findsOneWidget);
|
||||
expect(find.text('Download'), findsOneWidget);
|
||||
@@ -246,7 +246,7 @@ void main() {
|
||||
await tester.tap(find.text('Download'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(saved.single.bytes, _bytes);
|
||||
expect(find.text('Downloaded report.csv.'), findsOneWidget);
|
||||
expect(find.text('Downloaded report.zip.'), findsOneWidget);
|
||||
expect(find.byType(AlertDialog), findsOneWidget);
|
||||
});
|
||||
|
||||
@@ -299,7 +299,7 @@ void main() {
|
||||
stage: 'review',
|
||||
visit: 1,
|
||||
artifacts: <JsonMap>[
|
||||
artifact('report.csv', contentType: 'text/csv', sizeBytes: 3),
|
||||
artifact('report.zip', contentType: 'application/zip', sizeBytes: 3),
|
||||
],
|
||||
),
|
||||
];
|
||||
@@ -326,7 +326,7 @@ void main() {
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('report.csv'));
|
||||
await tester.tap(find.text('report.zip'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
|
||||
@@ -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'),
|
||||
],
|
||||
),
|
||||
]);
|
||||
|
||||
@@ -14,7 +14,7 @@ enum _Platform { material, cupertino }
|
||||
JsonMap _recorded(
|
||||
String name, {
|
||||
String url = '',
|
||||
String contentType = 'text/csv',
|
||||
String contentType = 'application/zip',
|
||||
int sizeBytes = 2048,
|
||||
}) => artifact(
|
||||
name,
|
||||
@@ -37,7 +37,7 @@ List<JsonMap> _steps() => <JsonMap>[
|
||||
sequence: 2,
|
||||
visit: 1,
|
||||
artifacts: [
|
||||
_recorded('result.csv'),
|
||||
_recorded('result.zip'),
|
||||
_recorded('notes.md', contentType: 'text/markdown'),
|
||||
],
|
||||
),
|
||||
@@ -45,7 +45,7 @@ List<JsonMap> _steps() => <JsonMap>[
|
||||
stage: 'review',
|
||||
sequence: 3,
|
||||
visit: 2,
|
||||
artifacts: [_recorded('result.csv', url: '/artifacts/1/2/result.csv')],
|
||||
artifacts: [_recorded('result.zip', url: '/artifacts/1/2/result.zip')],
|
||||
),
|
||||
];
|
||||
|
||||
@@ -101,7 +101,7 @@ void main() {
|
||||
expect(find.text('build · visit 1'), findsOneWidget);
|
||||
expect(find.text('review · visit 1'), findsOneWidget);
|
||||
expect(find.text('review · visit 2'), findsOneWidget);
|
||||
expect(find.text('result.csv'), findsNWidgets(2));
|
||||
expect(find.text('result.zip'), findsNWidgets(2));
|
||||
expect(find.text('notes.md'), findsOneWidget);
|
||||
expect(find.text('text/markdown · 2.0\u00a0KiB'), findsOneWidget);
|
||||
});
|
||||
@@ -111,7 +111,7 @@ void main() {
|
||||
) async {
|
||||
final steps = _steps();
|
||||
await _pumpGallery(tester, platform, steps);
|
||||
await tester.tap(find.text('result.csv').at(1));
|
||||
await tester.tap(find.text('result.zip').at(1));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final groups = artifactGroups(steps);
|
||||
@@ -138,7 +138,7 @@ void main() {
|
||||
step(
|
||||
stage: 'review',
|
||||
visit: 1,
|
||||
artifacts: [_recorded('result.csv'), _recorded('notes.md')],
|
||||
artifacts: [_recorded('result.zip'), _recorded('notes.md')],
|
||||
skipped: 2,
|
||||
truncated: 3,
|
||||
),
|
||||
@@ -147,7 +147,7 @@ void main() {
|
||||
find.text('Artifacts · 2 recorded · partial capture'),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tester.tap(find.text('result.csv'));
|
||||
await tester.tap(find.text('result.zip'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
_inDialog(_Platform.material, 'Artifacts · 2 recorded · partial capture'),
|
||||
@@ -201,7 +201,7 @@ void main() {
|
||||
stage: 'review',
|
||||
visit: 1,
|
||||
artifacts: [
|
||||
_recorded('result.csv', url: '/artifacts/1/1/result.csv'),
|
||||
_recorded('result.zip', url: '/artifacts/1/1/result.zip'),
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -211,13 +211,13 @@ void main() {
|
||||
return true;
|
||||
},
|
||||
);
|
||||
await tester.tap(find.text('result.csv'));
|
||||
await tester.tap(find.text('result.zip'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(_inDialog(_Platform.material, 'Open'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(opened, [
|
||||
Uri.parse('http://127.0.0.1:8081/artifacts/1/1/result.csv'),
|
||||
Uri.parse('http://127.0.0.1:8081/artifacts/1/1/result.zip'),
|
||||
]);
|
||||
expect(find.text('Link opened externally.'), findsOneWidget);
|
||||
expect(find.byType(AlertDialog), findsNothing);
|
||||
@@ -230,10 +230,10 @@ void main() {
|
||||
step(
|
||||
stage: 'review',
|
||||
visit: 1,
|
||||
artifacts: [_recorded('result.csv', url: '//evil.test/result.csv')],
|
||||
artifacts: [_recorded('result.zip', url: '//evil.test/result.zip')],
|
||||
),
|
||||
], configuredEndpoint: 'ws://127.0.0.1:8081/connect');
|
||||
await tester.tap(find.text('result.csv'));
|
||||
await tester.tap(find.text('result.zip'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
_inDialog(
|
||||
@@ -255,15 +255,15 @@ void main() {
|
||||
visit: 1,
|
||||
artifacts: [
|
||||
<String, dynamic>{
|
||||
'name': 'result.csv',
|
||||
'name': 'result.zip',
|
||||
'url': '',
|
||||
'content_type': 'text/csv',
|
||||
'content_type': 'application/zip',
|
||||
'size_bytes': 10,
|
||||
},
|
||||
],
|
||||
),
|
||||
]);
|
||||
await tester.tap(find.text('result.csv'));
|
||||
await tester.tap(find.text('result.zip'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
_inDialog(_Platform.material, 'No artifact URL recorded.'),
|
||||
@@ -300,7 +300,7 @@ void main() {
|
||||
stage: 'review',
|
||||
visit: 1,
|
||||
artifacts: [
|
||||
_recorded('result.csv', url: '/artifacts/1/1/result.csv'),
|
||||
_recorded('result.zip', url: '/artifacts/1/1/result.zip'),
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -310,12 +310,12 @@ void main() {
|
||||
return true;
|
||||
},
|
||||
);
|
||||
await tester.tap(find.text('result.csv'));
|
||||
await tester.tap(find.text('result.zip'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(_inDialog(_Platform.material, 'Copy link'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(copied, ['http://127.0.0.1:8081/artifacts/1/1/result.csv']);
|
||||
expect(copied, ['http://127.0.0.1:8081/artifacts/1/1/result.zip']);
|
||||
expect(opened, isEmpty);
|
||||
expect(find.text('Link copied.'), findsOneWidget);
|
||||
});
|
||||
@@ -339,14 +339,14 @@ void main() {
|
||||
step(
|
||||
stage: 'review',
|
||||
visit: 1,
|
||||
artifacts: [_recorded('first.csv')],
|
||||
artifacts: [_recorded('first.zip')],
|
||||
skipped: 2,
|
||||
),
|
||||
step(
|
||||
stage: 'review',
|
||||
sequence: 2,
|
||||
visit: 2,
|
||||
artifacts: [_recorded('second.csv')],
|
||||
artifacts: [_recorded('second.zip')],
|
||||
truncated: 3,
|
||||
),
|
||||
]);
|
||||
@@ -371,7 +371,7 @@ void main() {
|
||||
step(
|
||||
stage: 'review',
|
||||
visit: 1,
|
||||
artifacts: [_recorded('result.csv')],
|
||||
artifacts: [_recorded('result.zip')],
|
||||
skipped: 2,
|
||||
truncated: 3,
|
||||
),
|
||||
@@ -379,7 +379,7 @@ void main() {
|
||||
stage: 'review',
|
||||
sequence: 2,
|
||||
visit: 2,
|
||||
artifacts: [_recorded('later.csv')],
|
||||
artifacts: [_recorded('later.zip')],
|
||||
),
|
||||
], focusIndex: 0);
|
||||
|
||||
@@ -395,12 +395,12 @@ void main() {
|
||||
find.text('3 files omitted by artifact capture limits.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('later.csv'), findsNothing);
|
||||
expect(find.text('later.zip'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a complete capture adds no header notes', (tester) async {
|
||||
await _pumpGallery(tester, _Platform.material, [
|
||||
step(stage: 'review', visit: 1, artifacts: [_recorded('result.csv')]),
|
||||
step(stage: 'review', visit: 1, artifacts: [_recorded('result.zip')]),
|
||||
]);
|
||||
|
||||
expect(find.text('Artifact · 1 recorded'), findsOneWidget);
|
||||
@@ -420,7 +420,7 @@ void main() {
|
||||
stage: 'review',
|
||||
sequence: visit,
|
||||
visit: visit,
|
||||
artifacts: [_recorded('file$visit.csv')],
|
||||
artifacts: [_recorded('file$visit.zip')],
|
||||
skipped: 1,
|
||||
),
|
||||
], surface: const Size(360, 640));
|
||||
@@ -437,8 +437,8 @@ void main() {
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tester.scrollUntilVisible(find.text('file10.csv'), 200);
|
||||
expect(find.text('file10.csv'), findsOneWidget);
|
||||
await tester.scrollUntilVisible(find.text('file10.zip'), 200);
|
||||
expect(find.text('file10.zip'), findsOneWidget);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -453,7 +453,7 @@ void main() {
|
||||
stage: 'review',
|
||||
visit: 1,
|
||||
artifacts: [
|
||||
_recorded('result.csv', url: '/artifacts/1/1/result.csv'),
|
||||
_recorded('result.zip', url: '/artifacts/1/1/result.zip'),
|
||||
],
|
||||
skipped: 12,
|
||||
truncated: 34,
|
||||
@@ -474,8 +474,8 @@ void main() {
|
||||
find.text('34 files omitted by artifact capture limits.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tester.scrollUntilVisible(find.text('result.csv'), 200);
|
||||
expect(find.text('result.csv'), findsOneWidget);
|
||||
await tester.scrollUntilVisible(find.text('result.zip'), 200);
|
||||
expect(find.text('result.zip'), findsOneWidget);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -487,11 +487,11 @@ void main() {
|
||||
stage: 'review',
|
||||
visit: 1,
|
||||
artifacts: [
|
||||
_recorded('result.csv', url: '/artifacts/1/1/result.csv'),
|
||||
_recorded('result.zip', url: '/artifacts/1/1/result.zip'),
|
||||
],
|
||||
),
|
||||
], configuredEndpoint: 'ws://127.0.0.1:8081/connect');
|
||||
await tester.tap(find.text('result.csv'));
|
||||
await tester.tap(find.text('result.zip'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
double orderOf(String label) {
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_table.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_table_view.dart';
|
||||
|
||||
Widget _host(String text, {String delimiter = ','}) => MaterialApp(
|
||||
home: Scaffold(
|
||||
body: SingleChildScrollView(
|
||||
child: ArtifactTableView(text: text, delimiter: delimiter),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
void main() {
|
||||
testWidgets('a CSV draws its header and cells, padding short rows', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(_host('id,name,score\n1,alpha,9\n2,"beta, b"\n'));
|
||||
final table = tester.widget<Table>(find.byType(Table));
|
||||
expect(table.children, hasLength(3));
|
||||
expect(table.children.every((row) => row.children.length == 3), isTrue);
|
||||
for (final text in ['id', 'name', 'score', 'alpha', 'beta, b']) {
|
||||
expect(find.text(text), findsOneWidget, reason: text);
|
||||
}
|
||||
expect(
|
||||
(table.children.first.decoration as BoxDecoration?)?.color,
|
||||
isNotNull,
|
||||
);
|
||||
expect(find.textContaining('Showing'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a capped table says how many rows it omits', (tester) async {
|
||||
final text = List.generate(
|
||||
artifactTableRowLimit + 20,
|
||||
(i) => 'r$i,v$i',
|
||||
).join('\n');
|
||||
await tester.pumpWidget(_host(text));
|
||||
expect(
|
||||
find.text(
|
||||
'Showing $artifactTableRowLimit of ${artifactTableRowLimit + 20} '
|
||||
'rows. Open the file for the rest.',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('an empty table says so', (tester) async {
|
||||
await tester.pumpWidget(_host(''));
|
||||
expect(find.text('The table is empty.'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user