cpd_2022_zi/test/widget_timer_button_test.dart

36 lines
1.1 KiB
Dart

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);
});
}