diff --git a/flutter_news_example/packages/news_blocks_ui/pubspec.yaml b/flutter_news_example/packages/news_blocks_ui/pubspec.yaml index 43195ca83..a4a9482c5 100644 --- a/flutter_news_example/packages/news_blocks_ui/pubspec.yaml +++ b/flutter_news_example/packages/news_blocks_ui/pubspec.yaml @@ -22,7 +22,7 @@ dependencies: url_launcher: ^6.1.7 url_launcher_platform_interface: ^2.1.1 video_player: ^2.4.2 - video_player_platform_interface: ^5.1.4 + video_player_platform_interface: ^6.0.1 dev_dependencies: fake_async: ^1.3.0 diff --git a/flutter_news_example/packages/news_blocks_ui/test/helpers/fake_video_player_platform.dart b/flutter_news_example/packages/news_blocks_ui/test/helpers/fake_video_player_platform.dart new file mode 100644 index 000000000..bfc223c0e --- /dev/null +++ b/flutter_news_example/packages/news_blocks_ui/test/helpers/fake_video_player_platform.dart @@ -0,0 +1,104 @@ +import 'dart:async'; + +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:video_player_platform_interface/video_player_platform_interface.dart'; + +class FakeVideoPlayerPlatform extends VideoPlayerPlatform { + Completer initialized = Completer(); + List calls = []; + List dataSources = []; + final Map> streams = + >{}; + bool forceInitError = false; + int nextTextureId = 0; + final Map _positions = {}; + + @override + Future create(DataSource dataSource) async { + calls.add('create'); + final stream = StreamController(); + streams[nextTextureId] = stream; + if (forceInitError) { + stream.addError( + PlatformException( + code: 'VideoError', + message: 'Video player had error XYZ', + ), + ); + } else { + stream.add( + VideoEvent( + eventType: VideoEventType.initialized, + size: const Size(100, 100), + duration: const Duration(seconds: 1), + ), + ); + } + dataSources.add(dataSource); + return nextTextureId++; + } + + @override + Future dispose(int textureId) async { + calls.add('dispose'); + } + + @override + Future init() async { + calls.add('init'); + initialized.complete(true); + } + + @override + Stream videoEventsFor(int textureId) { + return streams[textureId]!.stream; + } + + @override + Future pause(int textureId) async { + calls.add('pause'); + } + + @override + Future play(int textureId) async { + calls.add('play'); + } + + @override + Future getPosition(int textureId) async { + calls.add('position'); + return _positions[textureId] ?? Duration.zero; + } + + @override + Future seekTo(int textureId, Duration position) async { + calls.add('seekTo'); + _positions[textureId] = position; + } + + @override + Future setLooping(int textureId, bool looping) async { + calls.add('setLooping'); + } + + @override + Future setVolume(int textureId, double volume) async { + calls.add('setVolume'); + } + + @override + Future setPlaybackSpeed(int textureId, double speed) async { + calls.add('setPlaybackSpeed'); + } + + @override + Future setMixWithOthers(bool mixWithOthers) async { + calls.add('setMixWithOthers'); + } + + @override + Widget buildView(int textureId) { + return Texture(textureId: textureId); + } +} diff --git a/flutter_news_example/packages/news_blocks_ui/test/helpers/helpers.dart b/flutter_news_example/packages/news_blocks_ui/test/helpers/helpers.dart index c292ee528..68a6a3151 100644 --- a/flutter_news_example/packages/news_blocks_ui/test/helpers/helpers.dart +++ b/flutter_news_example/packages/news_blocks_ui/test/helpers/helpers.dart @@ -1,3 +1,4 @@ +export 'fake_video_player_platform.dart'; export 'path_provider.dart'; export 'pump_app.dart'; export 'pump_content_themed_app.dart'; diff --git a/flutter_news_example/packages/news_blocks_ui/test/src/video_introduction_test.dart b/flutter_news_example/packages/news_blocks_ui/test/src/video_introduction_test.dart index d2897e710..a159cab95 100644 --- a/flutter_news_example/packages/news_blocks_ui/test/src/video_introduction_test.dart +++ b/flutter_news_example/packages/news_blocks_ui/test/src/video_introduction_test.dart @@ -6,6 +6,7 @@ import 'package:mocktail_image_network/mocktail_image_network.dart'; import 'package:news_blocks/news_blocks.dart'; import 'package:news_blocks_ui/news_blocks_ui.dart'; import 'package:news_blocks_ui/src/widgets/widgets.dart'; +import 'package:video_player_platform_interface/video_player_platform_interface.dart'; import '../helpers/helpers.dart'; @@ -19,7 +20,13 @@ void main() { 'and prices are finally falling'; group('VideoIntroduction', () { - setUpAll(setUpTolerantComparator); + setUpAll( + () { + final fakeVideoPlayerPlatform = FakeVideoPlayerPlatform(); + VideoPlayerPlatform.instance = fakeVideoPlayerPlatform; + setUpTolerantComparator(); + }, + ); testWidgets('renders correctly', (tester) async { final technologyVideoIntroduction = VideoIntroductionBlock( diff --git a/flutter_news_example/packages/news_blocks_ui/test/src/video_test.dart b/flutter_news_example/packages/news_blocks_ui/test/src/video_test.dart index e8edd5ba6..a1779b899 100644 --- a/flutter_news_example/packages/news_blocks_ui/test/src/video_test.dart +++ b/flutter_news_example/packages/news_blocks_ui/test/src/video_test.dart @@ -4,11 +4,19 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:news_blocks/news_blocks.dart'; import 'package:news_blocks_ui/news_blocks_ui.dart'; import 'package:news_blocks_ui/src/widgets/widgets.dart'; +import 'package:video_player_platform_interface/video_player_platform_interface.dart'; import '../helpers/helpers.dart'; void main() { group('Video', () { + setUp( + () { + final fakeVideoPlayerPlatform = FakeVideoPlayerPlatform(); + VideoPlayerPlatform.instance = fakeVideoPlayerPlatform; + }, + ); + testWidgets('renders InlineVideo with correct video', (tester) async { const block = VideoBlock(videoUrl: 'videoUrl'); @@ -28,11 +36,14 @@ void main() { testWidgets('renders ProgressIndicator when loading', (tester) async { const block = VideoBlock(videoUrl: 'videoUrl'); - await tester.pumpApp( + await tester.pumpWidget( Video(block: block), ); - expect(find.byType(ProgressIndicator), findsOneWidget); + expect( + find.byType(ProgressIndicator, skipOffstage: false), + findsOneWidget, + ); }); }); } diff --git a/flutter_news_example/packages/news_blocks_ui/test/src/widgets/inline_video_test.dart b/flutter_news_example/packages/news_blocks_ui/test/src/widgets/inline_video_test.dart index 344837ad5..4b5235ef9 100644 --- a/flutter_news_example/packages/news_blocks_ui/test/src/widgets/inline_video_test.dart +++ b/flutter_news_example/packages/news_blocks_ui/test/src/widgets/inline_video_test.dart @@ -4,11 +4,19 @@ import 'package:flutter/material.dart' hide ProgressIndicator; import 'package:flutter_test/flutter_test.dart'; import 'package:news_blocks_ui/src/widgets/widgets.dart'; import 'package:video_player/video_player.dart'; +import 'package:video_player_platform_interface/video_player_platform_interface.dart'; import '../../helpers/helpers.dart'; void main() { group('InlineVideo', () { + setUp( + () { + final fakeVideoPlayerPlatform = FakeVideoPlayerPlatform(); + VideoPlayerPlatform.instance = fakeVideoPlayerPlatform; + }, + ); + testWidgets('renders progressIndicator when loading', (tester) async { const progressIndicatorKey = Key('__progress_indicator__'); final controller = FakeVideoPlayerController(); diff --git a/flutter_news_example/pubspec.lock b/flutter_news_example/pubspec.lock index 6f8b9c6cd..294ad9167 100644 --- a/flutter_news_example/pubspec.lock +++ b/flutter_news_example/pubspec.lock @@ -1658,13 +1658,13 @@ packages: source: hosted version: "2.3.8" video_player_platform_interface: - dependency: transitive + dependency: "direct main" description: name: video_player_platform_interface sha256: "318a6d20577e1c78cf0bf40670883cc571ea860c72a4f7426d7dacce4bdd4343" url: "https://pub.dev" source: hosted - version: "5.1.4" + version: "6.0.1" video_player_web: dependency: transitive description: diff --git a/flutter_news_example/pubspec.yaml b/flutter_news_example/pubspec.yaml index ff4c8894e..af98d67ae 100644 --- a/flutter_news_example/pubspec.yaml +++ b/flutter_news_example/pubspec.yaml @@ -84,6 +84,7 @@ dependencies: user_repository: path: packages/user_repository very_good_analysis: ^4.0.0 + video_player_platform_interface: ^6.0.1 visibility_detector: ^0.3.3 dev_dependencies: diff --git a/flutter_news_example/test/article/helpers/fake_video_player_platform.dart b/flutter_news_example/test/article/helpers/fake_video_player_platform.dart new file mode 100644 index 000000000..bfc223c0e --- /dev/null +++ b/flutter_news_example/test/article/helpers/fake_video_player_platform.dart @@ -0,0 +1,104 @@ +import 'dart:async'; + +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:video_player_platform_interface/video_player_platform_interface.dart'; + +class FakeVideoPlayerPlatform extends VideoPlayerPlatform { + Completer initialized = Completer(); + List calls = []; + List dataSources = []; + final Map> streams = + >{}; + bool forceInitError = false; + int nextTextureId = 0; + final Map _positions = {}; + + @override + Future create(DataSource dataSource) async { + calls.add('create'); + final stream = StreamController(); + streams[nextTextureId] = stream; + if (forceInitError) { + stream.addError( + PlatformException( + code: 'VideoError', + message: 'Video player had error XYZ', + ), + ); + } else { + stream.add( + VideoEvent( + eventType: VideoEventType.initialized, + size: const Size(100, 100), + duration: const Duration(seconds: 1), + ), + ); + } + dataSources.add(dataSource); + return nextTextureId++; + } + + @override + Future dispose(int textureId) async { + calls.add('dispose'); + } + + @override + Future init() async { + calls.add('init'); + initialized.complete(true); + } + + @override + Stream videoEventsFor(int textureId) { + return streams[textureId]!.stream; + } + + @override + Future pause(int textureId) async { + calls.add('pause'); + } + + @override + Future play(int textureId) async { + calls.add('play'); + } + + @override + Future getPosition(int textureId) async { + calls.add('position'); + return _positions[textureId] ?? Duration.zero; + } + + @override + Future seekTo(int textureId, Duration position) async { + calls.add('seekTo'); + _positions[textureId] = position; + } + + @override + Future setLooping(int textureId, bool looping) async { + calls.add('setLooping'); + } + + @override + Future setVolume(int textureId, double volume) async { + calls.add('setVolume'); + } + + @override + Future setPlaybackSpeed(int textureId, double speed) async { + calls.add('setPlaybackSpeed'); + } + + @override + Future setMixWithOthers(bool mixWithOthers) async { + calls.add('setMixWithOthers'); + } + + @override + Widget buildView(int textureId) { + return Texture(textureId: textureId); + } +} diff --git a/flutter_news_example/test/article/helpers/helpers.dart b/flutter_news_example/test/article/helpers/helpers.dart new file mode 100644 index 000000000..a84c4f072 --- /dev/null +++ b/flutter_news_example/test/article/helpers/helpers.dart @@ -0,0 +1 @@ +export 'fake_video_player_platform.dart'; diff --git a/flutter_news_example/test/article/widgets/article_content_item_test.dart b/flutter_news_example/test/article/widgets/article_content_item_test.dart index 3d31c96c4..10b07da4a 100644 --- a/flutter_news_example/test/article/widgets/article_content_item_test.dart +++ b/flutter_news_example/test/article/widgets/article_content_item_test.dart @@ -7,13 +7,20 @@ import 'package:flutter_news_example/slideshow/slideshow.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:news_blocks/news_blocks.dart'; import 'package:news_blocks_ui/news_blocks_ui.dart'; +import 'package:video_player_platform_interface/video_player_platform_interface.dart'; import 'package:visibility_detector/visibility_detector.dart'; import '../../helpers/helpers.dart'; +import '../helpers/helpers.dart'; void main() { initMockHydratedStorage(); + void setUpVideoPlayerPlatform() { + final fakeVideoPlayerPlatform = FakeVideoPlayerPlatform(); + VideoPlayerPlatform.instance = fakeVideoPlayerPlatform; + } + group('ArticleContentItem', () { testWidgets( 'renders DividerHorizontal ' @@ -131,6 +138,7 @@ void main() { testWidgets( 'renders Video ' 'for VideoBlock', (tester) async { + setUpVideoPlayerPlatform(); const block = VideoBlock(videoUrl: 'videoUrl'); await tester.pumpApp(ArticleContentItem(block: block)); expect( @@ -169,6 +177,8 @@ void main() { testWidgets( 'renders VideoIntroduction ' 'for VideoIntroductionBlock', (tester) async { + setUpVideoPlayerPlatform(); + final block = VideoIntroductionBlock( category: PostCategory.technology, title: 'title',