From 8a6728a1f6fefede662550117f7e23b479d61956 Mon Sep 17 00:00:00 2001 From: Crondung <1922635@stud.hs-mannheim.de> Date: Mon, 6 Mar 2023 23:42:11 +0100 Subject: [PATCH] add timer widget test --- test/widget_tests/timer_widget_test.dart | 32 ++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 test/widget_tests/timer_widget_test.dart 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); + }); + }); +}