cpd_2022_zi/test/timer_provider_test.dart

44 lines
1.4 KiB
Dart
Raw Normal View History

2023-03-03 00:17:56 +01:00
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);
});
}