import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/features/artifacts/domain/artifact_preview.dart'; import 'package:pipelines_app/features/artifacts/domain/artifact_url.dart'; import 'package:pipelines_app/features/artifacts/ui/artifact_video_player.dart'; import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_content.dart'; import 'package:video_player/video_player.dart'; /// A controller whose platform work is scripted: [initialize] completes or /// fails only when the test says so, and nothing reaches a video plugin. class _ScriptedController extends VideoPlayerController { _ScriptedController(super.uri) : super.networkUrl(); final ready = Completer(); int plays = 0; @override Future initialize() => ready.future; @override Future play() async => plays++; } Widget _body(ArtifactVideoControllerFactory factory) => MaterialApp( home: Scaffold( body: ArtifactPreviewBody( plan: ArtifactPreviewPlan( kind: ArtifactPreviewKind.video, resolved: ResolvedArtifactUrl( uri: Uri.parse('http://127.0.0.1:8080/artifacts/7/clip.mp4'), external: false, ), message: '', ), loading: false, markdownBuilder: defaultArtifactMarkdown, videoControllerFactory: factory, ), ), ); void main() { testWidgets('a video preview streams its resolved url and never autoplays', ( tester, ) async { final opened = []; late _ScriptedController controller; await tester.pumpWidget( _body((uri) { opened.add(uri); return controller = _ScriptedController(uri); }), ); expect(find.byType(ArtifactVideoPlayer), findsOneWidget); expect(opened.single.path, '/artifacts/7/clip.mp4'); expect(find.byType(CircularProgressIndicator), findsOneWidget); expect(controller.plays, 0); }); testWidgets('a video that cannot be opened says so', (tester) async { late _ScriptedController controller; await tester.pumpWidget( _body((uri) => controller = _ScriptedController(uri)), ); controller.ready.completeError(StateError('unsupported codec')); await tester.pump(); expect(find.text(artifactVideoError), findsOneWidget); }); }