cpd_2022_zi/test/widget_tests/timer_widget_test.dart

31 lines
1.1 KiB
Dart
Raw Permalink Normal View History

2023-03-06 23:42:11 +01:00
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:provider/provider.dart';
import 'package:smoke_cess_app/providers/timer_provider.dart';
import 'package:smoke_cess_app/utils/timer_util.dart';
import 'package:smoke_cess_app/widgets/timer_widget.dart';
void main() {
group('TimerWidget', () {
testWidgets('should display duration', (WidgetTester tester) async {
TimerProvider timerProvider = TimerProvider();
Duration duration = const Duration(minutes: 1);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: ChangeNotifierProvider(
create: (context) => timerProvider,
child: TimerWidget(duration: duration)))),
);
final durationTextFinder = find.text(formatTime(duration.inSeconds));
expect(durationTextFinder, findsOneWidget);
timerProvider.startTimer(duration);
await tester.pump(const Duration(seconds: 1));
expect(durationTextFinder, findsNothing);
expect(find.text(formatTime(duration.inSeconds - 1)), findsOneWidget);
});
});
}