Skip to content
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

GitAuto: Add a widget test for lib/components/badge/gf_badge.dart #10

Merged
merged 2 commits into from
Feb 14, 2025

Conversation

gitauto-for-dev[bot]
Copy link

@gitauto-for-dev gitauto-for-dev bot commented Feb 14, 2025

Resolves #7

Why is this feature needed?

Adding unit tests for the GFBadge component ensures its behavior remains consistent and reliable. These tests help catch regressions when future changes are made to the badge, ensuring that the text and child properties as well as default styling remain intact.

What and how are we changing? Why this approach?

We have introduced a new test file (test/components/badge/gf_badge_test.dart) to cover the functionality of the GFBadge component. The tests check three main scenarios:

  • When text is provided, the badge displays the provided text.
  • When no text is provided and a child widget is passed, the badge renders the child widget.
  • The component uses default properties (size and color) when they are not explicitly set.

This approach leverages Flutter's widget testing framework to simulate rendering in a MaterialApp and Scaffold environment, ensuring that the GFBadge behaves as expected in a real application context.

What actions are required from users?

No direct user action is required. This change is internal and intended for developers and CI pipelines to automatically verify component behavior with each change.

How does it work? (Technical details)

  • The tests are written using Flutter's widget testing utilities provided in the flutter_test package.
  • The first test verifies that a GFBadge with text displays the correct text by searching for it in the widget tree.
  • The second test confirms that if a GFBadge is given a child widget (instead of text), that child widget is rendered properly.
  • The third test inspects the default properties of the GFBadge by directly reading widget parameters and asserting they match the expected default size and color (GFSize.SMALL and GFColors.DANGER).
  • The tests wrap the GFBadge in a MaterialApp and Scaffold to provide the necessary context for rendering.

Is it backwards compatible?

Yes, these changes are strictly adding tests. There are no modifications to production code, so the backward compatibility of the GFBadge component remains unaffected.

Any other considerations?

  • Alternative testing strategies (such as integration or golden tests) were considered, but widget tests provide a balance between speed and comprehensive coverage for our current needs.
  • Future improvements might include testing additional properties or custom configurations of the GFBadge component if the component's API is extended.
git fetch origin
git checkout gitauto-wes/issue-7-20250214-120836
git pull origin gitauto-wes/issue-7-20250214-120836

Copy link
Author

gitauto-for-dev bot commented Feb 14, 2025

Committed the Check Run test error fix! Running it again...

@hiroshinishio hiroshinishio changed the title GitAuto: Add a unit test for lib/components/badge/gf_badge.dart GitAuto: Add a widget test for lib/components/badge/gf_badge.dart Feb 14, 2025
@hiroshinishio hiroshinishio merged commit daa5a44 into master Feb 14, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a widget test for lib/components/badge/gf_badge.dart
1 participant