Skip to content

Commit

Permalink
Add iPhone 15 devices (#376)
Browse files Browse the repository at this point in the history
* Add iPhone 15 Devices

* Fix lint violations

* Improve implementation

Co-authored-by: Christopher Fuller <[email protected]>

---------

Co-authored-by: Christopher Fuller <[email protected]>
  • Loading branch information
tinder-garricnahapetian and tinder-cfuller authored Apr 18, 2024
1 parent b0ad58e commit b4b93b5
Show file tree
Hide file tree
Showing 492 changed files with 1,057 additions and 20 deletions.
84 changes: 84 additions & 0 deletions Sources/SnapshotTestingExtensions/UITraitCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,88 @@ extension UITraitCollection {
])
}
}

internal static func iPhone15(_ orientation: ViewImageConfig.Orientation) -> UITraitCollection {
let base: [UITraitCollection] = [
UITraitCollection(forceTouchCapability: .unavailable),
UITraitCollection(layoutDirection: .leftToRight),
UITraitCollection(preferredContentSizeCategory: .medium),
UITraitCollection(userInterfaceIdiom: .phone)
]
return switch orientation {
case .landscape:
UITraitCollection(traitsFrom: base + [
UITraitCollection(horizontalSizeClass: .regular),
UITraitCollection(verticalSizeClass: .compact)
])
case .portrait:
UITraitCollection(traitsFrom: base + [
UITraitCollection(horizontalSizeClass: .compact),
UITraitCollection(verticalSizeClass: .regular)
])
}
}

internal static func iPhone15Plus(_ orientation: ViewImageConfig.Orientation) -> UITraitCollection {
let base: [UITraitCollection] = [
UITraitCollection(forceTouchCapability: .unavailable),
UITraitCollection(layoutDirection: .leftToRight),
UITraitCollection(preferredContentSizeCategory: .medium),
UITraitCollection(userInterfaceIdiom: .phone)
]
return switch orientation {
case .landscape:
UITraitCollection(traitsFrom: base + [
UITraitCollection(horizontalSizeClass: .regular),
UITraitCollection(verticalSizeClass: .compact)
])
case .portrait:
UITraitCollection(traitsFrom: base + [
UITraitCollection(horizontalSizeClass: .compact),
UITraitCollection(verticalSizeClass: .regular)
])
}
}

internal static func iPhone15Pro(_ orientation: ViewImageConfig.Orientation) -> UITraitCollection {
let base: [UITraitCollection] = [
UITraitCollection(forceTouchCapability: .unavailable),
UITraitCollection(layoutDirection: .leftToRight),
UITraitCollection(preferredContentSizeCategory: .medium),
UITraitCollection(userInterfaceIdiom: .phone)
]
return switch orientation {
case .landscape:
UITraitCollection(traitsFrom: base + [
UITraitCollection(horizontalSizeClass: .regular),
UITraitCollection(verticalSizeClass: .compact)
])
case .portrait:
UITraitCollection(traitsFrom: base + [
UITraitCollection(horizontalSizeClass: .compact),
UITraitCollection(verticalSizeClass: .regular)
])
}
}

internal static func iPhone15ProMax(_ orientation: ViewImageConfig.Orientation) -> UITraitCollection {
let base: [UITraitCollection] = [
UITraitCollection(forceTouchCapability: .unavailable),
UITraitCollection(layoutDirection: .leftToRight),
UITraitCollection(preferredContentSizeCategory: .medium),
UITraitCollection(userInterfaceIdiom: .phone)
]
return switch orientation {
case .landscape:
UITraitCollection(traitsFrom: base + [
UITraitCollection(horizontalSizeClass: .regular),
UITraitCollection(verticalSizeClass: .compact)
])
case .portrait:
UITraitCollection(traitsFrom: base + [
UITraitCollection(horizontalSizeClass: .compact),
UITraitCollection(verticalSizeClass: .regular)
])
}
}
}
56 changes: 56 additions & 0 deletions Sources/SnapshotTestingExtensions/ViewImageConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,60 @@ extension ViewImageConfig {
}
return ViewImageConfig(safeArea: safeArea, size: size, traits: .iPhone14ProMax(orientation))
}

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

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

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

public static func iPhone15ProMax(_ orientation: Orientation) -> ViewImageConfig {
let safeArea: UIEdgeInsets
let size: CGSize
switch orientation {
case .landscape:
safeArea = UIEdgeInsets(top: 0, left: 59, bottom: 21, right: 59)
size = CGSize(width: 932, height: 430)
case .portrait:
safeArea = UIEdgeInsets(top: 59, left: 0, bottom: 34, right: 0)
size = CGSize(width: 430, height: 932)
}
return ViewImageConfig(safeArea: safeArea, size: size, traits: .iPhone15ProMax(orientation))
}
}
55 changes: 44 additions & 11 deletions Tests/LayoutTests/Support/Device.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ internal enum Device: CustomStringConvertible {
case iPhone14Plus(Orientation)
case iPhone14Pro(Orientation)
case iPhone14ProMax(Orientation)
case iPhone15(Orientation)
case iPhone15Plus(Orientation)
case iPhone15Pro(Orientation)
case iPhone15ProMax(Orientation)

internal enum Orientation {

Expand Down Expand Up @@ -61,6 +65,19 @@ internal enum Device: CustomStringConvertible {
[.iPhone14ProMax(.portrait), .iPhone14ProMax(.landscape)]
}

internal static var iPhone15: [Self] {
[.iPhone15(.portrait), .iPhone15(.landscape)]
}
internal static var iPhone15Plus: [Self] {
[.iPhone15Plus(.portrait), .iPhone15Plus(.landscape)]
}
internal static var iPhone15Pro: [Self] {
[.iPhone15Pro(.portrait), .iPhone15Pro(.landscape)]
}
internal static var iPhone15ProMax: [Self] {
[.iPhone15ProMax(.portrait), .iPhone15ProMax(.landscape)]
}

internal static var allTestDevices: [Self] {
portraitTestDevices + landscapeTestDevices
}
Expand All @@ -75,7 +92,11 @@ internal enum Device: CustomStringConvertible {
.iPhone14(.portrait),
.iPhone14Plus(.portrait),
.iPhone14Pro(.portrait),
.iPhone14ProMax(.portrait)
.iPhone14ProMax(.portrait),
.iPhone15(.portrait),
.iPhone15Plus(.portrait),
.iPhone15Pro(.portrait),
.iPhone15ProMax(.portrait)
]
}

Expand All @@ -89,7 +110,11 @@ internal enum Device: CustomStringConvertible {
.iPhone14(.landscape),
.iPhone14Plus(.landscape),
.iPhone14Pro(.landscape),
.iPhone14ProMax(.landscape)
.iPhone14ProMax(.landscape),
.iPhone15(.landscape),
.iPhone15Plus(.landscape),
.iPhone15Pro(.landscape),
.iPhone15ProMax(.landscape)
]
}

Expand All @@ -114,23 +139,31 @@ internal enum Device: CustomStringConvertible {
internal var name: String {
switch self {
case let .iPhone8(orientation):
return "iPhone 8 - \(orientation)"
"iPhone 8 - \(orientation)"
case let .iPhoneSE(orientation):
return "iPhone SE - \(orientation)"
"iPhone SE - \(orientation)"
case let .iPhoneX(orientation):
return "iPhone X - \(orientation)"
"iPhone X - \(orientation)"
case let .iPhone13(orientation):
return "iPhone 13 - \(orientation)"
"iPhone 13 - \(orientation)"
case let .iPhone13mini(orientation):
return "iPhone 13 mini - \(orientation)"
"iPhone 13 mini - \(orientation)"
case let .iPhone14(orientation):
return "iPhone 14 - \(orientation)"
"iPhone 14 - \(orientation)"
case let .iPhone14Plus(orientation):
return "iPhone 14 Plus - \(orientation)"
"iPhone 14 Plus - \(orientation)"
case let .iPhone14Pro(orientation):
return "iPhone 14 Pro - \(orientation)"
"iPhone 14 Pro - \(orientation)"
case let .iPhone14ProMax(orientation):
return "iPhone 14 Pro Max - \(orientation)"
"iPhone 14 Pro Max - \(orientation)"
case let .iPhone15(orientation):
"iPhone 15 - \(orientation)"
case let .iPhone15Plus(orientation):
"iPhone 15 Plus - \(orientation)"
case let .iPhone15Pro(orientation):
"iPhone 15 Pro - \(orientation)"
case let .iPhone15ProMax(orientation):
"iPhone 15 Pro Max - \(orientation)"
}
}
}
26 changes: 17 additions & 9 deletions Tests/LayoutTests/Support/SnapshotTesting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,31 @@ extension Device {
internal var config: ViewImageConfig {
switch self {
case let .iPhone8(orientation):
return .iPhone8(orientation.configOrientation)
.iPhone8(orientation.configOrientation)
case let .iPhoneSE(orientation):
return .iPhoneSe(orientation.configOrientation)
.iPhoneSe(orientation.configOrientation)
case let .iPhoneX(orientation):
return .iPhoneX(orientation.configOrientation)
.iPhoneX(orientation.configOrientation)
case let .iPhone13(orientation):
return .iPhone13(orientation.configOrientation)
.iPhone13(orientation.configOrientation)
case let .iPhone13mini(orientation):
return .iPhone13Mini(orientation.configOrientation)
.iPhone13Mini(orientation.configOrientation)
case let .iPhone14(orientation):
return .iPhone14(orientation.configOrientation)
.iPhone14(orientation.configOrientation)
case let .iPhone14Plus(orientation):
return .iPhone14Plus(orientation.configOrientation)
.iPhone14Plus(orientation.configOrientation)
case let .iPhone14Pro(orientation):
return .iPhone14Pro(orientation.configOrientation)
.iPhone14Pro(orientation.configOrientation)
case let .iPhone14ProMax(orientation):
return .iPhone14ProMax(orientation.configOrientation)
.iPhone14ProMax(orientation.configOrientation)
case let .iPhone15(orientation):
.iPhone15(orientation.configOrientation)
case let .iPhone15Plus(orientation):
.iPhone15Plus(orientation.configOrientation)
case let .iPhone15Pro(orientation):
.iPhone15Pro(orientation.configOrientation)
case let .iPhone15ProMax(orientation):
.iPhone15ProMax(orientation.configOrientation)
}
}
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<View; frame = (x: 0, y: 0, width: 430, height: 932)>
| <View; name = Pink; frame = (x: 10, y: 20, width: 50, height: 100)>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<View; frame = (x: 0, y: 0, width: 430, height: 932)>
| <View; name = Pink; frame = (x: 10, y: 20, width: 50, height: 100)>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<View; frame = (x: 0, y: 0, width: 393, height: 852)>
| <View; name = Pink; frame = (x: 10, y: 20, width: 50, height: 100)>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<View; frame = (x: 0, y: 0, width: 393, height: 852)>
| <View; name = Pink; frame = (x: 10, y: 20, width: 50, height: 100)>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<View; frame = (x: 0, y: 0, width: 430, height: 932)>
| <View; name = Pink; frame = (x: 370, y: 20, width: 50, height: 100)>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<View; frame = (x: 0, y: 0, width: 430, height: 932)>
| <View; name = Pink; frame = (x: 370, y: 20, width: 50, height: 100)>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<View; frame = (x: 0, y: 0, width: 393, height: 852)>
| <View; name = Pink; frame = (x: 333, y: 20, width: 50, height: 100)>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<View; frame = (x: 0, y: 0, width: 393, height: 852)>
| <View; name = Pink; frame = (x: 333, y: 20, width: 50, height: 100)>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 430, height: 932)>
| <View; name = Pink; frame = (x: 165, y: 416, width: 100, height: 100)>
| <UILabel; frame = (322 456; 51.3333 20.3333); text = 'Layout'; userInteractionEnabled = NO; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <_UILabelLayer>>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 430, height: 932)>
| <View; name = Pink; frame = (x: 165, y: 416, width: 100, height: 100)>
| <UILabel; frame = (322 456; 51.3333 20.3333); text = 'Layout'; userInteractionEnabled = NO; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <_UILabelLayer>>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 393, height: 852)>
| <View; name = Pink; frame = (x: 146.666667, y: 376, width: 100, height: 100)>
| <UILabel; frame = (294 416; 51.3333 20.3333); text = 'Layout'; userInteractionEnabled = NO; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <_UILabelLayer>>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 393, height: 852)>
| <View; name = Pink; frame = (x: 146.666667, y: 376, width: 100, height: 100)>
| <UILabel; frame = (294 416; 51.3333 20.3333); text = 'Layout'; userInteractionEnabled = NO; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <_UILabelLayer>>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 430, height: 932)>
| <View; name = Pink; frame = (x: 165, y: 416, width: 100, height: 100)>
| <UILabel; frame = (322 456; 51.3333 20.3333); text = 'Layout'; userInteractionEnabled = NO; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <_UILabelLayer>>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 430, height: 932)>
| <View; name = Pink; frame = (x: 165, y: 416, width: 100, height: 100)>
| <UILabel; frame = (322 456; 51.3333 20.3333); text = 'Layout'; userInteractionEnabled = NO; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <_UILabelLayer>>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 393, height: 852)>
| <View; name = Pink; frame = (x: 146.666667, y: 376, width: 100, height: 100)>
| <UILabel; frame = (294 416; 51.3333 20.3333); text = 'Layout'; userInteractionEnabled = NO; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <_UILabelLayer>>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 393, height: 852)>
| <View; name = Pink; frame = (x: 146.666667, y: 376, width: 100, height: 100)>
| <UILabel; frame = (294 416; 51.3333 20.3333); text = 'Layout'; userInteractionEnabled = NO; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <_UILabelLayer>>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 430, height: 932)>
| <View; name = Pink; frame = (x: 0, y: 59, width: 430, height: 839)>
| <View; name = Blue; frame = (x: 199, y: 450, width: 32, height: 32)>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 430, height: 932)>
| <View; name = Pink; frame = (x: 0, y: 59, width: 430, height: 839)>
| <View; name = Blue; frame = (x: 199, y: 450, width: 32, height: 32)>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 393, height: 852)>
| <View; name = Pink; frame = (x: 0, y: 59, width: 393, height: 759)>
| <View; name = Blue; frame = (x: 180.666667, y: 410, width: 32, height: 32)>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 393, height: 852)>
| <View; name = Pink; frame = (x: 0, y: 59, width: 393, height: 759)>
| <View; name = Blue; frame = (x: 180.666667, y: 410, width: 32, height: 32)>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<View; frame = (x: 0, y: 0, width: 430, height: 932)>
| <View; name = Pink; frame = (x: 0, y: 0, width: 430, height: 932)>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<View; frame = (x: 0, y: 0, width: 430, height: 932)>
| <View; name = Pink; frame = (x: 0, y: 0, width: 430, height: 932)>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<View; frame = (x: 0, y: 0, width: 393, height: 852)>
| <View; name = Pink; frame = (x: 0, y: 0, width: 393, height: 852)>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<View; frame = (x: 0, y: 0, width: 393, height: 852)>
| <View; name = Pink; frame = (x: 0, y: 0, width: 393, height: 852)>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit b4b93b5

Please sign in to comment.