diff --git a/test/widget_tests/timer_widget_test.dart b/test/widget_tests/timer_widget_test.dart new file mode 100644 index 0000000..9275262 --- /dev/null +++ b/test/widget_tests/timer_widget_test.dart @@ -0,0 +1,32 @@ +import 'dart:async'; + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:provider/provider.dart'; +import 'package:smoke_cess_app/providers/timer_provider.dart'; +import 'package:smoke_cess_app/utils/timer_util.dart'; +import 'package:smoke_cess_app/widgets/timer_widget.dart'; + +void main() { + group('TimerWidget', () { + testWidgets('should display duration', (WidgetTester tester) async { + TimerProvider timerProvider = TimerProvider(); + Duration duration = const Duration(minutes: 1); + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: ChangeNotifierProvider( + create: (context) => timerProvider, + child: TimerWidget(duration: duration)))), + ); + + final durationTextFinder = find.text(formatTime(duration.inSeconds)); + expect(durationTextFinder, findsOneWidget); + + timerProvider.startTimer(duration); + await tester.pump(const Duration(seconds: 1)); + expect(durationTextFinder, findsNothing); + expect(find.text(formatTime(duration.inSeconds - 1)), findsOneWidget); + }); + }); +}