From ca3f8ef52a3627bf3002ccf55e39b3ba8ee3655f Mon Sep 17 00:00:00 2001 From: "h.ehrenfried" <2012537@stud.hs-mannheim.de> Date: Fri, 3 Mar 2023 00:17:56 +0100 Subject: [PATCH] added timer_provider_tests --- test/timer_provider_test.dart | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 test/timer_provider_test.dart diff --git a/test/timer_provider_test.dart b/test/timer_provider_test.dart new file mode 100644 index 0000000..ba5b89f --- /dev/null +++ b/test/timer_provider_test.dart @@ -0,0 +1,43 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:smoke_cess_app/providers/timer_provider.dart'; + +void main() { + test('Timer should start and set started to true', () { + final timerProvider = TimerProvider(); + timerProvider.startTimer(Duration(seconds: 10)); + expect(timerProvider.started, true); + }); + + test('Elapsed time should increase and be less than or equal to the duration', () { + final timerProvider = TimerProvider(); + timerProvider.startTimer(Duration(seconds: 10)); + final initialElapsedSeconds = timerProvider.elapsedSeconds; + // Wait for the timer to tick at least once. + Future.delayed(Duration(seconds: 2), () { + expect(timerProvider.elapsedSeconds, greaterThan(initialElapsedSeconds)); + expect(timerProvider.elapsedSeconds, lessThanOrEqualTo(10)); + }); +}); + +test('Timer should stop and set started to false', () { + final timerProvider = TimerProvider(); + timerProvider.startTimer(Duration(seconds: 10)); + timerProvider.stopTimer(); + expect(timerProvider.started, false); +}); + +test('Elapsed seconds should be 0 when timer is not running', () { + final timerProvider = TimerProvider(); + expect(timerProvider.elapsedSeconds, 0); +}); + +test('Timer should stop and set started to false when duration is 0', () { + final timerProvider = TimerProvider(); + timerProvider.startTimer(Duration(seconds: 0)); + expect(timerProvider.started, false); +}); + + +} +