58 lines
2.3 KiB
Dart
58 lines
2.3 KiB
Dart
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:immich_mobile/providers/asset_viewer/video_player_provider.dart';
|
|
import 'package:mocktail/mocktail.dart';
|
|
import 'package:native_video_player/native_video_player.dart';
|
|
|
|
class _Controller extends Mock implements NativeVideoPlayerController {}
|
|
|
|
class _PlaybackInfo extends Mock implements PlaybackInfo {}
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
const wakelock = 'dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.toggle';
|
|
late _Controller controller;
|
|
late VideoPlayerNotifier notifier;
|
|
|
|
setUp(() {
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMessageHandler(
|
|
wakelock,
|
|
(_) async => const StandardMessageCodec().encodeMessage(<Object?>[null]),
|
|
);
|
|
final playback = _PlaybackInfo();
|
|
when(() => playback.status).thenReturn(PlaybackStatus.stopped);
|
|
when(() => playback.position).thenReturn(0);
|
|
controller = _Controller();
|
|
when(() => controller.playbackInfo).thenReturn(playback);
|
|
when(() => controller.videoInfo).thenReturn(VideoInfo.fromJson({'width': 1920, 'height': 1080, 'duration': 5000}));
|
|
when(() => controller.play()).thenAnswer((_) async {});
|
|
notifier = VideoPlayerNotifier()..attachController(controller);
|
|
});
|
|
|
|
tearDown(() async {
|
|
notifier.dispose();
|
|
await Future<void>.delayed(Duration.zero);
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMessageHandler(wakelock, null);
|
|
});
|
|
|
|
test('newly loaded stopped video offers playback', () {
|
|
notifier.onNativePlaybackReady();
|
|
expect(notifier.state.status, VideoPlaybackStatus.paused);
|
|
expect(notifier.state.duration, const Duration(seconds: 5));
|
|
});
|
|
|
|
testWidgets('stopped ready event cancels the pending buffering indicator', (tester) async {
|
|
await notifier.play();
|
|
notifier.onNativePlaybackReady();
|
|
await tester.pump(const Duration(seconds: 2));
|
|
expect(notifier.state.status, VideoPlaybackStatus.paused);
|
|
});
|
|
|
|
test('ready event preserves replay after playback has completed', () {
|
|
notifier.onNativeStatusChanged();
|
|
expect(notifier.state.status, VideoPlaybackStatus.completed);
|
|
notifier.onNativePlaybackReady();
|
|
expect(notifier.state.status, VideoPlaybackStatus.completed);
|
|
});
|
|
}
|