Skip to content

GitAuto: Add a widget test for lib/components/button/gf_button.dart #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions test/components/button/gf_button_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:getwidget/getwidget.dart';

void main() {
testWidgets('GFButton renders correctly and responds to tap', (WidgetTester tester) async {
bool tapped = false;
await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: GFButton(
text: 'Test Button',
onPressed: () {
tapped = true;
},
),
),
));

// Verify the GFButton renders with correct text
expect(find.text('Test Button'), findsOneWidget);

// Tap the button.
await tester.tap(find.byType(GFButton));
await tester.pump();

expect(tapped, isTrue);
});

testWidgets('GFButton disabled state works correctly', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: GFButton(
text: 'Disabled Button',
onPressed: null,
),
),
));

// The button should be disabled, we check that text exists
expect(find.text('Disabled Button'), findsOneWidget);

// Tapping should not trigger anything
await tester.tap(find.byType(GFButton));
await tester.pump();
});
}