cpd_2022_zi/test/unit_tests/timer_provider_test.dart

35 lines
1.2 KiB
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(const 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(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));
});
});
test('Timer should stop and set started to false', () {
final timerProvider = TimerProvider();
timerProvider.startTimer(const 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);
});
}