feat(app): add recorded artifact gallery to the native run detail
This commit is contained in:
@@ -0,0 +1,161 @@
|
||||
import 'package:flutter/cupertino.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/artifacts/ui/artifact_gallery_action.dart';
|
||||
import 'package:pipelines_app/features/runs/data/runs_repository.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_view.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/runs_controller.dart';
|
||||
|
||||
import '../../artifacts/domain/artifact_fixtures.dart';
|
||||
|
||||
enum _Platform { material, cupertino }
|
||||
|
||||
class _FakeGateway implements ApiGateway {
|
||||
_FakeGateway(this.detail);
|
||||
final JsonMap detail;
|
||||
|
||||
@override
|
||||
Stream<JsonMap> get frames => const Stream<JsonMap>.empty();
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
||||
if (type != 'get_run') throw UnsupportedError(type);
|
||||
return Future.value({'run_detail': detail});
|
||||
}
|
||||
}
|
||||
|
||||
JsonMap _run({required List<JsonMap> steps}) => <String, dynamic>{
|
||||
'id': 21,
|
||||
'title': 'Artifacts wiring run',
|
||||
'name': 'gallery',
|
||||
'status': 'succeeded',
|
||||
'steps': steps,
|
||||
};
|
||||
|
||||
Future<void> _pumpDetail(
|
||||
WidgetTester tester,
|
||||
_Platform platform,
|
||||
RunsController controller,
|
||||
ApiGateway gateway,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(500, 1200);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final view = RunDetailView(
|
||||
controller: controller,
|
||||
gateway: gateway,
|
||||
onBack: () {},
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
platform == _Platform.material
|
||||
? MaterialApp(home: Scaffold(body: view))
|
||||
: CupertinoApp(
|
||||
builder: (context, app) => Theme(
|
||||
data: ThemeData(platform: TargetPlatform.iOS),
|
||||
child: app!,
|
||||
),
|
||||
home: CupertinoPageScaffold(child: view),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Future<RunsController> _loaded(ApiGateway gateway) async {
|
||||
final controller = RunsController(RunsRepository(gateway));
|
||||
await controller.select(21);
|
||||
return controller;
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final platform in _Platform.values) {
|
||||
testWidgets('${platform.name}: the action opens the recorded groups', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = _FakeGateway(
|
||||
_run(
|
||||
steps: [
|
||||
step(
|
||||
stage: 'implementer',
|
||||
sequence: 1,
|
||||
artifacts: [
|
||||
artifact(
|
||||
'build.log',
|
||||
contentType: 'text/plain',
|
||||
sizeBytes: 2337,
|
||||
),
|
||||
],
|
||||
),
|
||||
step(
|
||||
stage: 'reviewer',
|
||||
sequence: 2,
|
||||
artifacts: [
|
||||
artifact(
|
||||
'shot.png',
|
||||
contentType: 'image/png',
|
||||
sizeBytes: 80544,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
final controller = await _loaded(gateway);
|
||||
addTearDown(controller.dispose);
|
||||
await _pumpDetail(tester, platform, controller, gateway);
|
||||
|
||||
expect(find.byKey(runArtifactsButtonKey), findsOneWidget);
|
||||
await tester.tap(find.byKey(runArtifactsButtonKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Artifacts · 2 recorded'), findsOneWidget);
|
||||
expect(find.text('build.log'), findsOneWidget);
|
||||
expect(find.text('shot.png'), findsOneWidget);
|
||||
expect(find.text('implementer · visit 1'), findsOneWidget);
|
||||
expect(find.text('reviewer · visit 1'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('the action is offered only when the detail has steps', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = _FakeGateway(_run(steps: const []));
|
||||
final controller = await _loaded(gateway);
|
||||
addTearDown(controller.dispose);
|
||||
await _pumpDetail(tester, _Platform.material, controller, gateway);
|
||||
expect(find.byKey(runArtifactsButtonKey), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a recorded empty capture keeps its explicit wording', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = _FakeGateway(
|
||||
_run(
|
||||
steps: [step(stage: 'reviewer', visit: 1, artifacts: const [])],
|
||||
),
|
||||
);
|
||||
final controller = await _loaded(gateway);
|
||||
addTearDown(controller.dispose);
|
||||
await _pumpDetail(tester, _Platform.material, controller, gateway);
|
||||
|
||||
await tester.tap(find.byKey(runArtifactsButtonKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('No artifacts recorded for this run.'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('an unavailable capture is never reported as empty', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = _FakeGateway(
|
||||
_run(steps: [step(stage: 'reviewer', visit: 1, includeArtifacts: false)]),
|
||||
);
|
||||
final controller = await _loaded(gateway);
|
||||
addTearDown(controller.dispose);
|
||||
await _pumpDetail(tester, _Platform.material, controller, gateway);
|
||||
|
||||
await tester.tap(find.byKey(runArtifactsButtonKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Artifacts · capture unavailable'), findsOneWidget);
|
||||
expect(find.text('No artifacts recorded for this run.'), findsNothing);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user