import 'package:cutdex/app/editor_theme.dart'; import 'package:cutdex/features/preview/fullscreen_playback_bar.dart'; import 'package:cutdex/l10n/l10n.dart'; import 'package:cutdex_sdk/timeline/model.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { testWidgets( 'fullscreen transport previews during dragging and settles on release', (tester) async { final seeks = []; final updates = []; final ends = []; var starts = 0; var plays = 0; var exits = 0; const second = TimelineClock.ticksPerSecond; await tester.pumpWidget( MaterialApp( theme: EditorTheme.penDark, localizationsDelegates: AppLocalizations.localizationsDelegates, supportedLocales: AppLocalizations.supportedLocales, locale: const Locale('en'), home: Scaffold( body: Center( child: SizedBox( width: 560, child: FullscreenPlaybackBar( positionTick: second, durationTick: 48 * 60 * second, frameTick: second ~/ 30, playing: false, onPlayPause: () => plays++, onSeek: seeks.add, onExit: () => exits++, onScrubStart: () => starts++, onScrubUpdate: updates.add, onScrubEnd: ends.add, ), ), ), ), ), ); expect(find.text('00:01'), findsOneWidget); expect(find.text('-47:59'), findsOneWidget); await tester.tap(find.byTooltip('Play')); await tester.tap(find.byTooltip('Exit fullscreen')); expect(plays, 1); expect(exits, 1); await tester.tap(find.byTooltip('Previous frame')); await tester.tap(find.byTooltip('Next frame')); expect(seeks, [second - second ~/ 30, second + second ~/ 30]); seeks.clear(); final rect = tester.getRect(find.byKey(const Key('fullscreen-progress'))); final gesture = await tester.startGesture( Offset(rect.left + 20, rect.center.dy), ); await gesture.moveTo(rect.center); await tester.pump(); expect(seeks, isEmpty); expect(starts, 1); expect(updates, isNotEmpty); expect(updates.last, closeTo(24 * 60 * second, second)); expect(ends, isEmpty); await gesture.up(); await tester.pump(); expect(ends, hasLength(1)); expect(ends.single, closeTo(24 * 60 * second, second)); await tester.tap(find.byTooltip('Go to start')); expect(seeks.last, 0); expect(tester.takeException(), isNull); }, ); testWidgets('empty fullscreen transport stays usable at narrow widths', ( tester, ) async { await tester.pumpWidget( MaterialApp( localizationsDelegates: AppLocalizations.localizationsDelegates, supportedLocales: AppLocalizations.supportedLocales, locale: const Locale('en'), home: Scaffold( body: Center( child: SizedBox( width: 280, child: FullscreenPlaybackBar( positionTick: 0, durationTick: 0, frameTick: TimelineClock.ticksPerSecond ~/ 30, playing: false, onPlayPause: null, onSeek: null, onExit: () {}, onScrubStart: null, onScrubUpdate: null, onScrubEnd: null, ), ), ), ), ), ); expect(tester.widget(find.byType(Slider)).onChanged, isNull); expect( tester .widget(find.byKey(const Key('preview-fullscreen'))) .onPressed, isNotNull, ); expect(tester.takeException(), isNull); }); }