Create widget_timer_button_test.dart
parent
ca3f8ef52a
commit
e426f47a08
|
@ -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);
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue