added timer_provider_tests

main
Hinrik Ehrenfried 2023-03-03 00:17:56 +01:00
parent 76e7309467
commit ca3f8ef52a
1 changed files with 43 additions and 0 deletions

View File

@ -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);
});
}