Skip to content

Add ViewImageConfig for iPhone 14, iPhone 14 Plus, iPhone 14 Pro and iPhone 14 Pro Max #662

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
68 changes: 68 additions & 0 deletions Sources/SnapshotTesting/Common/View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,74 @@ public struct ViewImageConfig {
return .init(safeArea: safeArea, size: size, traits: .iPhone13ProMax(orientation))
}

public static let iPhone14 = ViewImageConfig.iPhone14(.portrait)

public static func iPhone14(_ orientation: Orientation) -> ViewImageConfig {
let safeArea: UIEdgeInsets
let size: CGSize
switch orientation {
case .landscape:
safeArea = .init(top: 0, left: 47, bottom: 21, right: 47)
size = .init(width: 844, height: 390)
case .portrait:
safeArea = .init(top: 47, left: 0, bottom: 34, right: 0)
size = .init(width: 390, height: 844)
}

return .init(safeArea: safeArea, size: size, traits: UITraitCollection.iPhone14(orientation))
Copy link

Choose a reason for hiding this comment

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

I don't think UITraitCollection.iPhone14(orientation) compiles because we don't have the iPhone 14 UITraitCollection defined anywhere.

}

public static let iPhone14Plus = ViewImageConfig.iPhone14Plus(.portrait)

public static func iPhone14Plus(_ orientation: Orientation) -> ViewImageConfig {
let safeArea: UIEdgeInsets
let size: CGSize
switch orientation {
case .landscape:
safeArea = .init(top: 0, left: 47, bottom: 21, right: 47)
size = .init(width: 926, height: 428)
case .portrait:
safeArea = .init(top: 47, left: 0, bottom: 34, right: 0)
size = .init(width: 428, height: 926)
}

return .init(safeArea: safeArea, size: size, traits: .iPhone14Plus(orientation))
}

public static let iPhone14Pro = ViewImageConfig.iPhone14Pro(.portrait)

public static func iPhone14Pro(_ orientation: Orientation) -> ViewImageConfig {
let safeArea: UIEdgeInsets
let size: CGSize
switch orientation {
case .landscape:
safeArea = .init(top: 0, left: 59, bottom: 21, right: 59)
size = .init(width: 852, height: 393)
case .portrait:
safeArea = .init(top: 59, left: 0, bottom: 34, right: 0)
size = .init(width: 393, height: 852)
}

return .init(safeArea: safeArea, size: size, traits: .iPhone14Pro(orientation))
}

public static let iPhone14ProMax = ViewImageConfig.iPhone14ProMax(.portrait)

public static func iPhone14ProMax(_ orientation: Orientation) -> ViewImageConfig {
let safeArea: UIEdgeInsets
let size: CGSize
switch orientation {
case .landscape:
safeArea = .init(top: 0, left: 59, bottom: 21, right: 59)
size = .init(width: 932, height: 430)
case .portrait:
safeArea = .init(top: 59, left: 0, bottom: 34, right: 0)
size = .init(width: 430, height: 932)
}

return .init(safeArea: safeArea, size: size, traits: .iPhone14ProMax(orientation))
}

public static let iPadMini = ViewImageConfig.iPadMini(.landscape)

public static func iPadMini(_ orientation: Orientation) -> ViewImageConfig {
Expand Down
32 changes: 32 additions & 0 deletions Tests/SnapshotTestingTests/SnapshotTestingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,10 @@ final class SnapshotTestingTests: XCTestCase {
assertSnapshot(matching: viewController, as: .image(on: .iPhoneX), named: "iphone-x")
assertSnapshot(matching: viewController, as: .image(on: .iPhoneXr), named: "iphone-xr")
assertSnapshot(matching: viewController, as: .image(on: .iPhoneXsMax), named: "iphone-xs-max")
assertSnapshot(matching: viewController, as: .image(on: .iPhone14), named: "iphone-14")
assertSnapshot(matching: viewController, as: .image(on: .iPhone14Plus), named: "iphone-14-plus")
assertSnapshot(matching: viewController, as: .image(on: .iPhone14Pro), named: "iphone-14-pro")
assertSnapshot(matching: viewController, as: .image(on: .iPhone14ProMax), named: "iphone-14-pro-max")
assertSnapshot(matching: viewController, as: .image(on: .iPadMini), named: "ipad-mini")
assertSnapshot(matching: viewController, as: .image(on: .iPad9_7), named: "ipad-9-7")
assertSnapshot(matching: viewController, as: .image(on: .iPad10_2), named: "ipad-10-2")
Expand All @@ -485,6 +489,10 @@ final class SnapshotTestingTests: XCTestCase {
assertSnapshot(matching: viewController, as: .recursiveDescription(on: .iPhoneX), named: "iphone-x")
assertSnapshot(matching: viewController, as: .recursiveDescription(on: .iPhoneXr), named: "iphone-xr")
assertSnapshot(matching: viewController, as: .recursiveDescription(on: .iPhoneXsMax), named: "iphone-xs-max")
assertSnapshot(matching: viewController, as: .recursiveDescription(on: .iPhone14), named: "iphone-14")
assertSnapshot(matching: viewController, as: .recursiveDescription(on: .iPhone14Plus), named: "iphone-14-plus")
assertSnapshot(matching: viewController, as: .recursiveDescription(on: .iPhone14Pro), named: "iphone-14-pro")
assertSnapshot(matching: viewController, as: .recursiveDescription(on: .iPhone14ProMax), named: "iphone-14-pro-max")
assertSnapshot(matching: viewController, as: .recursiveDescription(on: .iPadMini), named: "ipad-mini")
assertSnapshot(matching: viewController, as: .recursiveDescription(on: .iPad9_7), named: "ipad-9-7")
assertSnapshot(matching: viewController, as: .recursiveDescription(on: .iPad10_2), named: "ipad-10-2")
Expand All @@ -498,6 +506,10 @@ final class SnapshotTestingTests: XCTestCase {
assertSnapshot(matching: viewController, as: .image(on: .iPhoneX(.portrait)), named: "iphone-x")
assertSnapshot(matching: viewController, as: .image(on: .iPhoneXr(.portrait)), named: "iphone-xr")
assertSnapshot(matching: viewController, as: .image(on: .iPhoneXsMax(.portrait)), named: "iphone-xs-max")
assertSnapshot(matching: viewController, as: .image(on: .iPhone14(.portrait)), named: "iphone-14")
assertSnapshot(matching: viewController, as: .image(on: .iPhone14Plus(.portrait)), named: "iphone-14-plus")
assertSnapshot(matching: viewController, as: .image(on: .iPhone14Pro(.portrait)), named: "iphone-14-pro")
assertSnapshot(matching: viewController, as: .image(on: .iPhone14ProMax(.portrait)), named: "iphone-14-pro-max")
assertSnapshot(matching: viewController, as: .image(on: .iPadMini(.landscape)), named: "ipad-mini")
assertSnapshot(matching: viewController, as: .image(on: .iPad9_7(.landscape)), named: "ipad-9-7")
assertSnapshot(matching: viewController, as: .image(on: .iPad10_2(.landscape)), named: "ipad-10-2")
Expand Down Expand Up @@ -553,6 +565,14 @@ final class SnapshotTestingTests: XCTestCase {
matching: viewController, as: .image(on: .iPhoneXr(.landscape)), named: "iphone-xr-alternative")
assertSnapshot(
matching: viewController, as: .image(on: .iPhoneXsMax(.landscape)), named: "iphone-xs-max-alternative")
assertSnapshot(
matching: viewController, as: .image(on: .iPhone14(.landscpae)), named: "iphone-14-alternative")
assertSnapshot(
matching: viewController, as: .image(on: .iPhone14Plus(.landscpae)), named: "iphone-14-plus-alternative")
assertSnapshot(
matching: viewController, as: .image(on: .iPhone14Pro(.landscpae)), named: "iphone-14-pro-alternative")
assertSnapshot(
matching: viewController, as: .image(on: .iPhone14ProMax(.landscpae)), named: "iphone-14-pro-max-alternative")
assertSnapshot(
matching: viewController, as: .image(on: .iPadMini(.portrait)), named: "ipad-mini-alternative")
assertSnapshot(
Expand Down Expand Up @@ -664,6 +684,10 @@ final class SnapshotTestingTests: XCTestCase {
assertSnapshot(matching: viewController, as: .image(on: .iPhoneX(.portrait)), named: "iphone-x")
assertSnapshot(matching: viewController, as: .image(on: .iPhoneXr(.portrait)), named: "iphone-xr")
assertSnapshot(matching: viewController, as: .image(on: .iPhoneXsMax(.portrait)), named: "iphone-xs-max")
assertSnapshot(matching: viewController, as: .image(on: .iPhone14(.portrait)), named: "iphone-14")
assertSnapshot(matching: viewController, as: .image(on: .iPhone14Plus(.portrait)), named: "iphone-14-plus")
assertSnapshot(matching: viewController, as: .image(on: .iPhone14Pro(.portrait)), named: "iphone-14-pro")
assertSnapshot(matching: viewController, as: .image(on: .iPhone14ProMax(.portrait)), named: "iphone-14-pro-max")
assertSnapshot(matching: viewController, as: .image(on: .iPadMini(.landscape)), named: "ipad-mini")
assertSnapshot(matching: viewController, as: .image(on: .iPad9_7(.landscape)), named: "ipad-9-7")
assertSnapshot(matching: viewController, as: .image(on: .iPad10_2(.landscape)), named: "ipad-10-2")
Expand All @@ -683,6 +707,14 @@ final class SnapshotTestingTests: XCTestCase {
matching: viewController, as: .image(on: .iPhoneXr(.landscape)), named: "iphone-xr-alternative")
assertSnapshot(
matching: viewController, as: .image(on: .iPhoneXsMax(.landscape)), named: "iphone-xs-max-alternative")
assertSnapshot(
matching: viewController, as: .image(on: .iPhone14(.landscape)), named: "iphone-14-alternative")
assertSnapshot(
matching: viewController, as: .image(on: .iPhone14Plus(.landscape)), named: "iphone-14-plus-alternative")
assertSnapshot(
matching: viewController, as: .image(on: .iPhone14Pro(.landscape)), named: "iphone-14-pro-alternative")
assertSnapshot(
matching: viewController, as: .image(on: .iPhone14ProMax(.landscape)), named: "iphone-14-pro-max-alternative")
assertSnapshot(
matching: viewController, as: .image(on: .iPadMini(.portrait)), named: "ipad-mini-alternative")
assertSnapshot(
Expand Down