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
Merged
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
31 changes: 31 additions & 0 deletions SnapshotTests/SnapshotTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,34 @@ extension Snapshotting where Value == UIView, Format == UIImage {
)
}
}

extension Snapshotting where Value == UIViewController, Format == UIImage {
private static var commonTraitCollection: [UITraitCollection] = [
.init(layoutDirection: .leftToRight),
.init(userInterfaceIdiom: .phone),
.init(horizontalSizeClass: .regular),
.init(verticalSizeClass: .compact),
]

static var extra3LargeFontStrategyLandscape: Self {
let traits = UITraitCollection(traitsFrom: [
.init(preferredContentSizeCategory: .accessibilityExtraExtraExtraLarge)
] + commonTraitCollection)
let safeArea: UIEdgeInsets = .init(top: 0, left: 47, bottom: 21, right: 47)
let size: CGSize = .init(width: 844, height: 390)
let viewImageConfig: ViewImageConfig = .init(safeArea: safeArea, size: size, traits: traits)

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

let traits = UITraitCollection(traitsFrom: [
.init(preferredContentSizeCategory: .medium),
] + commonTraitCollection)
let safeArea: UIEdgeInsets = .init(top: 0, left: 47, bottom: 21, right: 47)
let size: CGSize = .init(width: 844, height: 390)
let viewImageConfig: ViewImageConfig = .init(safeArea: safeArea, size: size, traits: traits)

return Self.image(on: viewImageConfig)
}
}