From e426f47a0848ebaf9bd6987ee202b52061e52312 Mon Sep 17 00:00:00 2001 From: "h.ehrenfried" <2012537@stud.hs-mannheim.de> Date: Mon, 6 Mar 2023 11:39:41 +0100 Subject: [PATCH] Create widget_timer_button_test.dart --- test/widget_timer_button_test.dart | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 test/widget_timer_button_test.dart diff --git a/test/widget_timer_button_test.dart b/test/widget_timer_button_test.dart new file mode 100644 index 0000000..6491896 --- /dev/null +++ b/test/widget_timer_button_test.dart @@ -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); + }); +}