cpd_2022_zi/test/provider/timer_provider_test.dart

41 lines
1.5 KiB
Dart
Raw Normal View History

2023-03-03 00:17:56 +01:00
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', () {
2023-03-06 18:36:10 +01:00
final timerProvider = TimerProvider();
timerProvider.startTimer(const Duration(seconds: 10));
expect(timerProvider.started, true);
2023-03-03 00:17:56 +01:00
});
2023-03-06 18:36:10 +01:00
test('Elapsed time should increase and be less than or equal to the duration',
() {
final timerProvider = TimerProvider();
timerProvider.startTimer(const Duration(seconds: 10));
final initialElapsedSeconds = timerProvider.elapsedSeconds;
// Wait for the timer to tick at least once.
Future.delayed(const Duration(seconds: 2), () {
expect(timerProvider.elapsedSeconds, greaterThan(initialElapsedSeconds));
expect(timerProvider.elapsedSeconds, lessThanOrEqualTo(10));
});
2023-03-03 00:17:56 +01:00
});
2023-03-06 18:36:10 +01:00
test('Timer should stop and set started to false', () {
final timerProvider = TimerProvider();
timerProvider.startTimer(const Duration(seconds: 10));
timerProvider.stopTimer();
expect(timerProvider.started, false);
});
2023-03-03 00:17:56 +01:00
2023-03-06 18:36:10 +01:00
test('Elapsed seconds should be 0 when timer is not running', () {
final timerProvider = TimerProvider();
expect(timerProvider.elapsedSeconds, 0);
});
2023-03-03 00:17:56 +01:00
2023-03-06 18:36:10 +01:00
test('Timer should stop and set started to false when duration is 0', () {
final timerProvider = TimerProvider();
timerProvider.startTimer(const Duration(seconds: 0));
expect(timerProvider.started, false);
});
2023-03-03 00:17:56 +01:00
}