test(local): cover shared link access and video readiness; fix lint dependency

This commit is contained in:
Codex
2026-10-14 21:37:42 +03:00
parent a06a589936
commit d25c946c29
4 changed files with 125 additions and 4 deletions
@@ -0,0 +1,63 @@
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 = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.toggle',
StandardMessageCodec(),
);
late _Controller controller;
late VideoPlayerNotifier notifier;
setUp(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockDecodedMessageHandler<Object?>(
wakelock,
(_) async => <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.setMockDecodedMessageHandler<Object?>(
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);
});
}