158 lines
4.6 KiB
Dart
158 lines
4.6 KiB
Dart
// Author: fruit.com.cn
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:fruitshorts/pages/player/widgets/seek_progress_bar.dart';
|
|
import 'package:video_player/video_player.dart';
|
|
|
|
void main() {
|
|
test('should_keep_seek_target_inside_playable_duration_when_dragging', () {
|
|
const duration = Duration(seconds: 12);
|
|
expect(seekPositionForFraction(0, duration), Duration.zero);
|
|
expect(
|
|
seekPositionForFraction(0.5, duration),
|
|
greaterThan(const Duration(seconds: 5)),
|
|
);
|
|
expect(seekPositionForFraction(1, duration), lessThan(duration));
|
|
});
|
|
|
|
testWidgets('should_show_loading_track_when_controller_is_missing', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: SeekProgressBar(
|
|
valueListenable: null,
|
|
semanticsLabel: 'Seek video',
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
expect(find.byKey(const Key('progress-loading')), findsOneWidget);
|
|
expect(find.byType(Slider), findsNothing);
|
|
});
|
|
|
|
testWidgets('should_switch_between_loading_track_and_slider', (tester) async {
|
|
final video = ValueNotifier<VideoPlayerValue>(
|
|
const VideoPlayerValue(
|
|
duration: Duration(seconds: 12),
|
|
position: Duration(seconds: 3),
|
|
isInitialized: true,
|
|
isBuffering: true,
|
|
),
|
|
);
|
|
addTearDown(video.dispose);
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: SeekProgressBar(
|
|
valueListenable: video,
|
|
semanticsLabel: 'Seek video',
|
|
onSeek: (_) async {},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
expect(find.byKey(const Key('progress-loading')), findsOneWidget);
|
|
expect(find.byType(Slider), findsNothing);
|
|
expect(find.textContaining('00:12'), findsNothing);
|
|
|
|
video.value = const VideoPlayerValue(
|
|
duration: Duration(seconds: 12),
|
|
position: Duration(seconds: 3),
|
|
isInitialized: true,
|
|
);
|
|
await tester.pump();
|
|
|
|
expect(find.byKey(const Key('progress-loading')), findsNothing);
|
|
expect(find.byType(Slider), findsOneWidget);
|
|
});
|
|
|
|
testWidgets(
|
|
'should_preview_while_dragging_and_seek_on_release_when_slider_is_horizontal',
|
|
(tester) async {
|
|
final video = ValueNotifier<VideoPlayerValue>(
|
|
const VideoPlayerValue(
|
|
duration: Duration(seconds: 12),
|
|
position: Duration(seconds: 3),
|
|
isInitialized: true,
|
|
),
|
|
);
|
|
addTearDown(video.dispose);
|
|
var started = 0;
|
|
Duration? target;
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: Center(
|
|
child: SizedBox(
|
|
width: 300,
|
|
child: SeekProgressBar(
|
|
valueListenable: video,
|
|
semanticsLabel: 'Seek video',
|
|
onScrubStart: () => started++,
|
|
onSeek: (position) async {
|
|
target = position;
|
|
},
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
final gesture = await tester.startGesture(
|
|
tester.getCenter(find.byType(Slider)),
|
|
);
|
|
await gesture.moveBy(const Offset(120, 0));
|
|
await tester.pump();
|
|
expect(started, 1);
|
|
expect(target, isNull);
|
|
expect(find.textContaining('/ 00:12'), findsOneWidget);
|
|
await gesture.up();
|
|
await tester.pumpAndSettle();
|
|
expect(target, isNotNull);
|
|
expect(target!, greaterThan(const Duration(seconds: 3)));
|
|
expect(target!, lessThan(const Duration(seconds: 12)));
|
|
expect(find.textContaining('/ 00:12'), findsNothing);
|
|
},
|
|
);
|
|
|
|
testWidgets('should_show_time_only_while_dragging_when_seek_bar_is_compact', (
|
|
tester,
|
|
) async {
|
|
final video = ValueNotifier<VideoPlayerValue>(
|
|
const VideoPlayerValue(
|
|
duration: Duration(seconds: 12),
|
|
position: Duration(seconds: 3),
|
|
isInitialized: true,
|
|
),
|
|
);
|
|
addTearDown(video.dispose);
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: SeekProgressBar(
|
|
valueListenable: video,
|
|
semanticsLabel: 'Seek video',
|
|
onSeek: (_) async {},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
expect(find.textContaining('00:12'), findsNothing);
|
|
final gesture = await tester.startGesture(
|
|
tester.getCenter(find.byType(Slider)),
|
|
);
|
|
await gesture.moveBy(const Offset(40, 0));
|
|
await tester.pump();
|
|
expect(find.textContaining('/ 00:12'), findsOneWidget);
|
|
await gesture.up();
|
|
await tester.pumpAndSettle();
|
|
expect(find.textContaining('00:12'), findsNothing);
|
|
});
|
|
}
|