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 landscape snapshot testing capability #774

Merged

Conversation

rasmustautsglia
Copy link
Contributor

This PR adds a capability to snapshot test screens in landscape, both with regular and large font.

MOB-2653

Copy link
Contributor

@gersonnoboa gersonnoboa left a comment

Choose a reason for hiding this comment

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

And then we should do

assertSnapshot(
    matching: viewController, 
    as: .extra3LargeFontStrategyLandscape,
    named: ...
)

correct? Or as: .imageLandscape also.

Copy link
Contributor

@igorkravchenko igorkravchenko left a comment

Choose a reason for hiding this comment

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

Looks cool. Added some comments regarding reusing trait collections. It is such great idea to have landscape mode tested 👍

let traits = UITraitCollection(traitsFrom: [
.init(forceTouchCapability: .available),
.init(layoutDirection: .leftToRight),
.init(preferredContentSizeCategory: .medium),
Copy link
Contributor

Choose a reason for hiding this comment

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

It says preferredContentSizeCategory is .medium here, but below it overrides it with .accessibilityExtraExtraExtraLarge). Seem like medium is unnecessary?

Suggested change
.init(preferredContentSizeCategory: .medium),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed 3a0d35b

extension Snapshotting where Value == UIViewController, Format == UIImage {
static var extra3LargeFontStrategyLandscape: Self {
let traits = UITraitCollection(traitsFrom: [
.init(forceTouchCapability: .available),
Copy link
Contributor

Choose a reason for hiding this comment

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

Where do we use forceTouchCapability?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't as far as I know. Those traits were taken from the other available iPhone models, because unfortunately iPhone 13 is not available. Perhaps this allows some other kind of testing and those traits are just bundled together for easier use.

return Self.image(on: viewImageConfig)
}

static var imageLandscape: Self {
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like most of the trait collection items are the same, so we can put them in one reusable list:

private static var commonTraitCollection: [UITraitCollection] = [
        .init(forceTouchCapability: .available),
        .init(layoutDirection: .leftToRight),
        .init(preferredContentSizeCategory: .medium),
        .init(userInterfaceIdiom: .phone),
        .init(horizontalSizeClass: .regular),
        .init(verticalSizeClass: .compact),
    ]

static var extra3LargeFontStrategyLandscape: Self {
        let traits = UITraitCollection(traitsFrom: [
            .init(preferredContentSizeCategory: .accessibilityExtraExtraExtraLarge)
        ] + commonTraitCollection)
/// .....

static var imageLandscape: Self {
        let traits = UITraitCollection(traitsFrom: commonTraitCollection)
/// .....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed 3a0d35b

@rasmustautsglia
Copy link
Contributor Author

!squash

This PR adds a capability to snapshot test screens in landscape, both
with regular and large font.

MOB-2653
@sm-deployer sm-deployer force-pushed the Add-landscape-snapshot-testing-capability branch from b7bea6b to 3d55c01 Compare September 20, 2023 07:30
@rasmustautsglia rasmustautsglia merged commit 3091a1e into development Sep 20, 2023
1 check passed
@rasmustautsglia rasmustautsglia deleted the Add-landscape-snapshot-testing-capability branch September 20, 2023 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants