Skip to content

Snapshot tests for the flutter code#60

Merged
gabrielbmoro merged 9 commits intomainfrom
feature/screenshot-support-flutter
Aug 14, 2025
Merged

Snapshot tests for the flutter code#60
gabrielbmoro merged 9 commits intomainfrom
feature/screenshot-support-flutter

Conversation

@gabrielbmoro
Copy link
Copy Markdown
Collaborator

@gabrielbmoro gabrielbmoro commented Aug 7, 2025

Description

This update enhances our snapshot testing infrastructure and test cases for CraftD Flutter components.

Bug fixes:

  • textAllCaps
  • fillMaxSize
  • backgroundColor

It closes:

Check list

  • The tests were executed and passed successfully.
  • Code changes follow the project style guidelines.
  • Tests have been added if applicable.
  • Did you subscribe to the channel?😛

textColorHex: '#800080',
backgroundHex: '#000000',
textSize: '24.0',
textAllCaps: true,
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is really weird, it looks like all caps is not working

flutter:
fonts:
- family: Roboto
fonts:
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default, flutter needs a font to the test env


jobs:
build:
runs-on: macos-latest # Use macOS because I generated the golden images in my macoOS
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to run this on macos, considering I generated the golden images on my macos laptop

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Aug 7, 2025

🦙 MegaLinter status: ⚠️ WARNING

Descriptor Linter Files Fixed Errors Warnings Elapsed time
⚠️ KOTLIN detekt yes 93 no 3.8s
⚠️ MARKDOWN markdown-table-formatter 19 1 0 0.23s
✅ YAML prettier 15 0 0 0.83s

See detailed report in MegaLinter reports

You could have the same capabilities but better runtime performances if you use a MegaLinter flavor:

MegaLinter is graciously provided by OX Security

This commit introduces two new properties to the `CraftDButton` widget:

- `fillMaxSize`: When set to `true`, the button will expand to fill the available width.
- `textAllCaps`: When set to `true`, the button's text will be displayed in uppercase.

Corresponding snapshot tests have been added to verify these new functionalities.
The `CraftDText` widget was also updated to respect the `textAllCaps` property.
…Tests

This commit introduces snapshot tests for the `CraftDText` widget and refactors existing snapshot tests for the `CraftDButton` widget.

**CraftDText Snapshot Tests:**
- Added two new snapshot tests for `CraftDText`:
    - `craftd_text_allcaps_false_snapshot.png`: Verifies the rendering of `CraftDText` with `textAllCaps` set to `false`.
    - `craftd_text_allcaps_true_snapshot.png`: Verifies the rendering of `CraftDText` with `textAllCaps` set to `true`.

**CraftDButton Snapshot Tests Refactoring:**
- Renamed and updated existing `CraftDButton` snapshot tests to improve clarity and reflect the tested property:
    - `craftd_button_allcaps_snapshot.png` was removed and its test case modified to test `fillMaxSize: false`, resulting in `craftd_button_fill_max_size_false_snapshot.png`.
    - `craftd_button_fill_max_size_snapshot.png` was renamed to `craftd_button_fill_max_size_true_snapshot.png` to explicitly indicate that `fillMaxSize` is `true`.
- Adjusted the properties (text color, background color, `textAllCaps`, `fillMaxSize`) in the `CraftDButton` test cases to align with the new snapshot test names and the properties being tested.
The `CraftDText` widget was not applying the background color specified in `textProperties`. This commit fixes the issue by setting the `backgroundColor` in the `TextStyle`.

Additionally, this commit:
- Adds default values for text properties in snapshot tests to improve readability and maintainability.
- Introduces new snapshot tests for `CraftDText` to cover different scenarios:
    - Text with orange text color
    - Text with orange background color
    - Text with a big font size
- Updates existing snapshot images to reflect the changes.
Adds a golden file test for the `CraftDEmpty` widget to ensure its visual representation remains consistent.
@gabrielbmoro gabrielbmoro changed the title Start craftd snapshot tests for flutter Snapshot tests for the flutter code Aug 7, 2025
@gabrielbmoro gabrielbmoro marked this pull request as ready for review August 7, 2025 22:53
@override
Widget build(BuildContext context) {
if (buttonProperties.fillMaxSize == true) {
return SizedBox(
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug fix: fillMaxSize was not working properly


@override
Widget build(BuildContext context) {
final String text = textProperties.textAllCaps == true
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug fix: textAllCaps was not working properly

? double.tryParse(textProperties.textSize!)
: 16.0,
color: CraftDColor.hexToColor(textProperties.textColorHex),
backgroundColor: CraftDColor.hexToColor(textProperties.backgroundHex),
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug fix: backgroundColor was not working properly

The `flutter test` command was removed from the Flutter snapshot tests workflow. This is because the tests are already being run by the integration tests.
branches:
- main
paths:
- "flutter/**"
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any changes in the flutter source set will trigger this workflow

branches:
- main
paths:
- "flutter/craftd_widget/lib/presentation/ui/**"
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any changes in the ui folder (inside of flutter package) will trigger this workflow

@gabrielbmoro gabrielbmoro self-assigned this Aug 9, 2025
Copy link
Copy Markdown
Contributor

@rviannaoliveira rviannaoliveira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good work

@gabrielbmoro gabrielbmoro merged commit 0e4e67a into main Aug 14, 2025
5 checks passed
@gabrielbmoro gabrielbmoro deleted the feature/screenshot-support-flutter branch August 14, 2025 16:09
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.

2 participants