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

Add a sample snapshot test for a SwiftUI View #600

Merged
merged 5 commits into from
Dec 17, 2024

Conversation

pinarol
Copy link
Contributor

@pinarol pinarol commented Dec 13, 2024

Closes part of #539

Description

Adds a snapshot test for AvatarPickerProfileView to demonstrate how we can do snapshot testing for SwiftUI Views.

Uses Snapshotting.image(...) strategy from the existing snapshot library. It is a snapshot strategy for comparing SwiftUI Views based on pixel equality. There are different layout types we can pass, but .sizeThatFits didn't work well for this view not sure why. So I just used .device and put some red borders around the content so the bounds are also visible and comparable.

Testing Steps

CI green.

@pinarol pinarol marked this pull request as ready for review December 13, 2024 17:07
@wpmobilebot
Copy link

wpmobilebot commented Dec 13, 2024

Gravatar Prototype Build📲 You can test the changes from this Pull Request in Gravatar Prototype Build by scanning the QR code below to install the corresponding build.
App NameGravatar Prototype Build Gravatar Prototype Build
Build Number1897
Version1.0
Bundle IDcom.automattic.gravatar-sdk-demo-uikit.prototype-build
Commitb8ed089
App Center BuildGravatar SDK Demo - UIKit #482
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

Copy link
Contributor

@etoledom etoledom left a comment

Choose a reason for hiding this comment

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

Just a question:
Is there a way to snapshot only de view without the whole bound of the device screen?

@pinarol
Copy link
Contributor Author

pinarol commented Dec 16, 2024

Can you check again? @etoledom I think I found a way to make .sizeThatFits work by applying a custom .frame(...)

Copy link
Contributor

@etoledom etoledom left a comment

Choose a reason for hiding this comment

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

Looks great 👍

@pinarol pinarol merged commit 1b7d579 into trunk Dec 17, 2024
9 checks passed
@pinarol pinarol deleted the wppinar/add-snapshot-tests-for-swiftui branch December 17, 2024 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants