78 lines
2.3 KiB
Dart
78 lines
2.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/core/api_gateway.dart';
|
|
import 'package:pipelines_app/features/search/domain/search_target.dart';
|
|
import 'package:pipelines_app/features/search/ui/search_result_view.dart';
|
|
|
|
class _Gateway implements ApiGateway {
|
|
@override
|
|
Stream<JsonMap> get frames => const Stream.empty();
|
|
|
|
@override
|
|
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
|
expect(type, 'get_run');
|
|
expect(fields, {'run_id': 7});
|
|
return {
|
|
'run_detail': {'id': 7, 'pipeline_id': 3, 'version': 2},
|
|
};
|
|
}
|
|
}
|
|
|
|
final _hit = <String, dynamic>{
|
|
'kind': 'artifact',
|
|
'target': '/artifacts/7/2/shot.png',
|
|
'artifact': {
|
|
'run_id': 7,
|
|
'sequence': 2,
|
|
'name': 'shot.png',
|
|
'content_type': 'image/png',
|
|
'size_bytes': 10,
|
|
'url': '/artifacts/7/2/shot.png',
|
|
},
|
|
};
|
|
|
|
void main() {
|
|
testWidgets('an artifact hit shows its picture and opens stage, run or '
|
|
'pipeline', (tester) async {
|
|
final opened = <JsonMap>[];
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: SearchArtifactScope(
|
|
gateway: _Gateway(),
|
|
onOpen: opened.add,
|
|
child: Builder(
|
|
builder: (context) => ListTile(
|
|
leading: searchArtifactThumbnail(context, _hit),
|
|
title: const Text('shot.png'),
|
|
trailing: searchArtifactActions(context, _hit),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
expect(
|
|
find.byKey(const ValueKey('search.thumbnail./artifacts/7/2/shot.png')),
|
|
findsOneWidget,
|
|
);
|
|
|
|
Future<void> choose(String label) async {
|
|
await tester.tap(find.byTooltip('Open…'));
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.text(label));
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
await choose('Open stage');
|
|
expect(opened.last, same(_hit));
|
|
await choose('Open run');
|
|
expect(opened.last['target'], 'run:7');
|
|
expect(searchTargetFor(opened.last), isA<ResolvedSearchTarget>());
|
|
await choose('Open pipeline');
|
|
expect(opened.last['target'], 'pipeline:3:v2');
|
|
// The app's opener accepts the hit the action builds.
|
|
expect(searchTargetFor(opened.last), isA<ResolvedSearchTarget>());
|
|
});
|
|
}
|