为什么:红线第 8 条门禁立即生效,要求 Flutter 测试命名合规;此前 155 条用例名是英文自然语言 或中文描述,合规数 0/155,属存量欠账,按"先补齐再上新功能"在本批处理。 - 25 个测试文件、155 条用例改名,按「文件 + 旧名」精确定位,每条断言命中恰好 1 次才替换 - 只改名字字面量:改动行 155 删 + 155 增,无一行不含字符串字面量(断言与用例体零改动) - 门禁:dart analyze lib test = No issues found;flutter test = 155 全过
98 lines
2.9 KiB
Dart
98 lines
2.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:nontonki/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_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);
|
|
await gesture.up();
|
|
await tester.pumpAndSettle();
|
|
expect(target, isNotNull);
|
|
expect(target!, greaterThan(const Duration(seconds: 3)));
|
|
expect(target!, lessThan(const Duration(seconds: 12)));
|
|
});
|
|
|
|
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);
|
|
});
|
|
}
|