Skip to content

Commit 97109a0

Browse files
committed
lightbox test [nfc]: Tighten test cases using a checkPositionsRelative
This makes some of these test cases quite a bit shorter, without losing any information that's relevant to what the test is about. Partly that comes by removing some tokens (like `kTestVideoDuration`) that were repetitive and not the interesting aspect of the test. Partly it comes by then as a result being able to collapse three lines into one line at each of these steps. That brings the different parts of the test closer together and makes them easier to see all at once.
1 parent 1e2143c commit 97109a0

File tree

1 file changed

+23
-37
lines changed

1 file changed

+23
-37
lines changed

test/widgets/lightbox_test.dart

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,16 @@ void main() {
240240
check(platform.position).equals(video);
241241
}
242242

243+
/// Like [checkPositions], but expressed in units of [kTestVideoDuration].
244+
void checkPositionsRelative(WidgetTester tester, {
245+
required double slider,
246+
required double video,
247+
}) {
248+
checkPositions(tester,
249+
slider: kTestVideoDuration * slider,
250+
video: kTestVideoDuration * video);
251+
}
252+
243253
(Offset, Offset) calculateSliderDimensions(WidgetTester tester) {
244254
const padding = 24.0;
245255
final rect = tester.getRect(find.byType(Slider));
@@ -306,9 +316,7 @@ void main() {
306316

307317
await tester.pump(kTestVideoDuration * 0.5);
308318
platform.pumpEvents();
309-
checkPositions(tester,
310-
slider: kTestVideoDuration * 0.5,
311-
video: kTestVideoDuration * 0.5);
319+
checkPositionsRelative(tester, slider: 0.5, video: 0.5);
312320
check(platform.isCompleted).isFalse();
313321
check(platform.isPlaying).isTrue();
314322

@@ -324,18 +332,14 @@ void main() {
324332
// At exactly the end of the video.
325333
await tester.pump(const Duration(milliseconds: 500));
326334
platform.pumpEvents();
327-
checkPositions(tester,
328-
slider: kTestVideoDuration,
329-
video: kTestVideoDuration);
335+
checkPositionsRelative(tester, slider: 1.0, video: 1.0);
330336
check(platform.isCompleted).isTrue(); // completed
331337
check(platform.isPlaying).isFalse(); // stopped playing
332338

333339
// After the video ended.
334340
await tester.pump(const Duration(milliseconds: 500));
335341
platform.pumpEvents();
336-
checkPositions(tester,
337-
slider: kTestVideoDuration,
338-
video: kTestVideoDuration);
342+
checkPositionsRelative(tester, slider: 1.0, video: 1.0);
339343
check(platform.isCompleted).isTrue();
340344
check(platform.isPlaying).isFalse();
341345
});
@@ -350,33 +354,23 @@ void main() {
350354
// gesture increments.
351355
final gesture = await tester.startGesture(trackStartPos);
352356
await tester.pump();
353-
checkPositions(tester,
354-
slider: Duration.zero,
355-
video: Duration.zero);
357+
checkPositionsRelative(tester, slider: 0.0, video: 0.0);
356358

357359
await gesture.moveBy(trackLength * 0.2);
358360
await tester.pump();
359-
checkPositions(tester,
360-
slider: kTestVideoDuration * 0.2,
361-
video: Duration.zero);
361+
checkPositionsRelative(tester, slider: 0.2, video: 0.0);
362362

363363
await gesture.moveBy(trackLength * 0.4);
364364
await tester.pump();
365-
checkPositions(tester,
366-
slider: kTestVideoDuration * 0.6,
367-
video: Duration.zero);
365+
checkPositionsRelative(tester, slider: 0.6, video: 0.0);
368366

369-
await gesture.moveBy(-trackLength * 0.2);
367+
await gesture.moveBy(trackLength * -0.2);
370368
await tester.pump();
371-
checkPositions(tester,
372-
slider: kTestVideoDuration * 0.4,
373-
video: Duration.zero);
369+
checkPositionsRelative(tester, slider: 0.4, video: 0.0);
374370

375371
await gesture.up();
376372
await tester.pump();
377-
checkPositions(tester,
378-
slider: kTestVideoDuration * 0.4,
379-
video: kTestVideoDuration * 0.4);
373+
checkPositionsRelative(tester, slider: 0.4, video: 0.4);
380374

381375
// Verify seekTo is called only once.
382376
check(platform.callLog.where((v) => v == 'seekTo').length).equals(1);
@@ -390,21 +384,15 @@ void main() {
390384

391385
final gesture = await tester.startGesture(trackStartPos);
392386
await tester.pump();
393-
checkPositions(tester,
394-
slider: Duration.zero,
395-
video: Duration.zero);
387+
checkPositionsRelative(tester, slider: 0.0, video: 0.0);
396388

397389
await gesture.moveBy(trackLength * 0.5);
398390
await tester.pump();
399-
checkPositions(tester,
400-
slider: kTestVideoDuration * 0.5,
401-
video: Duration.zero);
391+
checkPositionsRelative(tester, slider: 0.5, video: 0.0);
402392

403393
await gesture.up();
404394
await tester.pump();
405-
checkPositions(tester,
406-
slider: kTestVideoDuration * 0.5,
407-
video: kTestVideoDuration * 0.5);
395+
checkPositionsRelative(tester, slider: 0.5, video: 0.5);
408396

409397
final basePosition = kTestVideoDuration * 0.5;
410398
Duration actualElapsed = basePosition;
@@ -424,9 +412,7 @@ void main() {
424412
if (actualElapsed.inMilliseconds % 500 == 0) {
425413
lastPolled += const Duration(milliseconds: 500);
426414
}
427-
checkPositions(tester,
428-
slider: lastPolled,
429-
video: actualElapsed);
415+
checkPositions(tester, slider: lastPolled, video: actualElapsed);
430416
}
431417
});
432418
});

0 commit comments

Comments
 (0)