import 'dart:async'; 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); }); }); }