feat(app): run and stage artifacts share one gallery grid with image thumbnails and file-type icons
This commit is contained in:
@@ -0,0 +1,148 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_tile.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_fetch.dart';
|
||||
|
||||
import 'artifact_visit_list_fixture.dart';
|
||||
|
||||
/// A 1x1 transparent PNG.
|
||||
final _png = Uint8List.fromList(const [
|
||||
0x89,
|
||||
0x50,
|
||||
0x4E,
|
||||
0x47,
|
||||
0x0D,
|
||||
0x0A,
|
||||
0x1A,
|
||||
0x0A,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x0D,
|
||||
0x49,
|
||||
0x48,
|
||||
0x44,
|
||||
0x52,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x01,
|
||||
0x08,
|
||||
0x06,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x1F,
|
||||
0x15,
|
||||
0xC4,
|
||||
0x89,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x0D,
|
||||
0x49,
|
||||
0x44,
|
||||
0x41,
|
||||
0x54,
|
||||
0x78,
|
||||
0x9C,
|
||||
0x63,
|
||||
0x00,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
0x05,
|
||||
0x00,
|
||||
0x01,
|
||||
0x0D,
|
||||
0x0A,
|
||||
0x2D,
|
||||
0xB4,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x49,
|
||||
0x45,
|
||||
0x4E,
|
||||
0x44,
|
||||
0xAE,
|
||||
0x42,
|
||||
0x60,
|
||||
0x82,
|
||||
]);
|
||||
|
||||
Widget _host(Widget tile) => MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Center(child: SizedBox(width: 180, child: tile)),
|
||||
),
|
||||
);
|
||||
|
||||
void main() {
|
||||
testWidgets('an image tile shows its thumbnail through the app fetch', (
|
||||
tester,
|
||||
) async {
|
||||
final fetched = <Uri>[];
|
||||
final image = recordedArtifact(
|
||||
'shot.png',
|
||||
url: '/artifacts/1/1/shot.png',
|
||||
contentType: 'image/png',
|
||||
sizeBytes: 70,
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
ArtifactTile(
|
||||
group: visitGroup(artifacts: [image]),
|
||||
artifact: image,
|
||||
selected: false,
|
||||
configuredEndpoint: 'ws://127.0.0.1:8081/connect',
|
||||
fetch: (uri) async {
|
||||
fetched.add(uri);
|
||||
return ArtifactFetchResult(status: 200, bytes: _png);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(fetched, [
|
||||
Uri.parse('http://127.0.0.1:8081/artifacts/1/1/shot.png'),
|
||||
]);
|
||||
expect(find.byType(Image), findsOneWidget);
|
||||
expect(find.text('shot.png'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a file without a thumbnail shows its kind of file', (
|
||||
tester,
|
||||
) async {
|
||||
var fetches = 0;
|
||||
final archive = recordedArtifact(
|
||||
'result.zip',
|
||||
url: '/artifacts/1/1/result.zip',
|
||||
contentType: 'application/zip',
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
ArtifactTile(
|
||||
group: visitGroup(artifacts: [archive]),
|
||||
artifact: archive,
|
||||
selected: false,
|
||||
configuredEndpoint: 'ws://127.0.0.1:8081/connect',
|
||||
fetch: (uri) async {
|
||||
fetches++;
|
||||
return ArtifactFetchResult(status: 200, bytes: _png);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(fetches, 0);
|
||||
expect(find.byIcon(Icons.folder_zip_outlined), findsOneWidget);
|
||||
expect(find.byType(Image), findsNothing);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user