Create widget_timer_button_test.dart

main
Hinrik Ehrenfried 2023-03-06 11:39:41 +01:00
parent ca3f8ef52a
commit e426f47a08
1 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,35 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:smoke_cess_app/widgets/timer_button.dart';
void main() {
testWidgets('TimerButton should display icon & color and react to click', (WidgetTester tester) async {
// Define the icon and color
final Icon icon = Icon(Icons.play_arrow);
final Color color = Colors.green;
// Build the TimerButton
var clicked = false;
await tester.pumpWidget(
MaterialApp(
home: TimerButton(
onClicked: () => clicked = true,
icon: icon,
color: color,
),
),
);
// Verify that the icon and color are displayed
expect(find.byWidgetPredicate((widget) => widget is CircleAvatar && widget.child == icon ), findsOneWidget);
expect(find.byWidgetPredicate((widget) => widget is CircleAvatar && widget.backgroundColor == color ), findsOneWidget);
// Tap the button
await tester.tap(find.byType(InkWell));
await tester.pump();
// Verify that the onClicked callback was called
expect(clicked, true);
});
}