Skip to content

Commit

Permalink
Add iPhone 14 Devices via new SnapshotTestingExtensions target (#241)
Browse files Browse the repository at this point in the history
* Add iPhone 14 Devices

* Record using Xcode 14.3.1

* Fix formatting

* Introduce SnapshotTestingExtensions

* Fix Package files

* Improve formatting

Co-authored-by: Christopher Fuller <christopher.fuller@gotinder.com>

* Fix Package file

* Improve implementation

Co-authored-by: Christopher Fuller <christopher.fuller@gotinder.com>

* Remove extra spaces

Co-authored-by: Christopher Fuller <christopher.fuller@gotinder.com>

* Update swift.yml

* Update Makefile

---------

Co-authored-by: Christopher Fuller <christopher.fuller@gotinder.com>
  • Loading branch information
tinder-garricnahapetian and tinder-cfuller authored Apr 16, 2024
1 parent b56a7ff commit b0ad58e
Show file tree
Hide file tree
Showing 497 changed files with 1,110 additions and 6 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@ jobs:
run: >
xcodebuild
build-for-testing
-scheme "Layout"
-scheme "Layout-Package"
-destination "name=$SIMULATOR,OS=latest"
SWIFT_TREAT_WARNINGS_AS_ERRORS=YES
- name: Test
run: >
xcodebuild
test-without-building
-scheme "Layout"
-scheme "Layout-Package"
-destination "name=$SIMULATOR,OS=latest"
- name: Delete snapshots
run: make delete-snapshots
- name: Record snapshots
run: >
xcodebuild
test-without-building
-scheme "Layout"
-scheme "Layout-Package"
-destination "name=$SIMULATOR,OS=latest"
continue-on-error: true
- name: Validate recorded snapshots
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ analyze:
@DERIVED_DATA="$$(mktemp -d)"; \
XCODEBUILD_LOG="$$DERIVED_DATA/xcodebuild.log"; \
xcodebuild \
-scheme "$(target)" \
-scheme "$(target)-Package" \
-destination "$(destination)" \
-derivedDataPath "$$DERIVED_DATA" \
-configuration "Debug" \
Expand Down
9 changes: 9 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ let package = Package(
.library(
name: "Layout",
targets: ["Layout"]),
.library(
name: "SnapshotTestingExtensions",
targets: ["SnapshotTestingExtensions"]),
],
dependencies: [
.package(
Expand All @@ -23,10 +26,16 @@ let package = Package(
targets: [
.target(
name: "Layout"),
.target(
name: "SnapshotTestingExtensions",
dependencies: [
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
]),
.testTarget(
name: "LayoutTests",
dependencies: [
"Layout",
"SnapshotTestingExtensions",
"Nimble",
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
],
Expand Down
13 changes: 13 additions & 0 deletions Package@swift-5.10.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ let package = Package(
.library(
name: "Layout",
targets: ["Layout"]),
.library(
name: "SnapshotTestingExtensions",
targets: ["SnapshotTestingExtensions"]),
],
dependencies: [
.package(
Expand All @@ -34,10 +37,20 @@ let package = Package(
plugins: [
.plugin(name: SwiftLint.plugin),
]),
.target(
name: "SnapshotTestingExtensions",
dependencies: [
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
],
swiftSettings: .swiftSettings,
plugins: [
.plugin(name: SwiftLint.plugin),
]),
.testTarget(
name: "LayoutTests",
dependencies: [
"Layout",
"SnapshotTestingExtensions",
"Nimble",
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
],
Expand Down
13 changes: 13 additions & 0 deletions Package@swift-5.9.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ let package = Package(
.library(
name: "Layout",
targets: ["Layout"]),
.library(
name: "SnapshotTestingExtensions",
targets: ["SnapshotTestingExtensions"]),
],
dependencies: [
.package(
Expand All @@ -34,10 +37,20 @@ let package = Package(
plugins: [
.plugin(name: SwiftLint.plugin),
]),
.target(
name: "SnapshotTestingExtensions",
dependencies: [
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
],
swiftSettings: .swiftSettings,
plugins: [
.plugin(name: SwiftLint.plugin),
]),
.testTarget(
name: "LayoutTests",
dependencies: [
"Layout",
"SnapshotTestingExtensions",
"Nimble",
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
],
Expand Down
98 changes: 98 additions & 0 deletions Sources/SnapshotTestingExtensions/UITraitCollection.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
//
// All Contributions by Match Group
//
// Copyright © 2024 Tinder (Match Group, LLC)
//
// Licensed under the Match Group Modified 3-Clause BSD License.
// See https://github.com/Tinder/Layout/blob/main/LICENSE for license information.
//

import SnapshotTesting
import UIKit

extension UITraitCollection {

internal static func iPhone14(_ 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 iPhone14Plus(_ 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 iPhone14Pro(_ 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 iPhone14ProMax(_ 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)
])
}
}
}
70 changes: 70 additions & 0 deletions Sources/SnapshotTestingExtensions/ViewImageConfig.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// All Contributions by Match Group
//
// Copyright © 2024 Tinder (Match Group, LLC)
//
// Licensed under the Match Group Modified 3-Clause BSD License.
// See https://github.com/Tinder/Layout/blob/main/LICENSE for license information.
//

import SnapshotTesting
import UIKit

extension ViewImageConfig {

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

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

public static func iPhone14Pro(_ 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: .iPhone14Pro(orientation))
}

public static func iPhone14ProMax(_ 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: .iPhone14ProMax(orientation))
}
}
40 changes: 38 additions & 2 deletions Tests/LayoutTests/Support/Device.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ internal enum Device: CustomStringConvertible {
case iPhoneX(Orientation)
case iPhone13(Orientation)
case iPhone13mini(Orientation)
case iPhone14(Orientation)
case iPhone14Plus(Orientation)
case iPhone14Pro(Orientation)
case iPhone14ProMax(Orientation)

internal enum Orientation {

Expand Down Expand Up @@ -41,6 +45,22 @@ internal enum Device: CustomStringConvertible {
[.iPhone13mini(.portrait), .iPhone13mini(.landscape)]
}

internal static var iPhone14: [Self] {
[.iPhone14(.portrait), .iPhone14(.landscape)]
}

internal static var iPhone14Plus: [Self] {
[.iPhone14Plus(.portrait), .iPhone14Plus(.landscape)]
}

internal static var iPhone14Pro: [Self] {
[.iPhone14Pro(.portrait), .iPhone14Pro(.landscape)]
}

internal static var iPhone14ProMax: [Self] {
[.iPhone14ProMax(.portrait), .iPhone14ProMax(.landscape)]
}

internal static var allTestDevices: [Self] {
portraitTestDevices + landscapeTestDevices
}
Expand All @@ -51,7 +71,11 @@ internal enum Device: CustomStringConvertible {
.iPhoneSE(.portrait),
.iPhoneX(.portrait),
.iPhone13(.portrait),
.iPhone13mini(.portrait)
.iPhone13mini(.portrait),
.iPhone14(.portrait),
.iPhone14Plus(.portrait),
.iPhone14Pro(.portrait),
.iPhone14ProMax(.portrait)
]
}

Expand All @@ -61,7 +85,11 @@ internal enum Device: CustomStringConvertible {
.iPhoneSE(.landscape),
.iPhoneX(.landscape),
.iPhone13(.landscape),
.iPhone13mini(.landscape)
.iPhone13mini(.landscape),
.iPhone14(.landscape),
.iPhone14Plus(.landscape),
.iPhone14Pro(.landscape),
.iPhone14ProMax(.landscape)
]
}

Expand Down Expand Up @@ -95,6 +123,14 @@ internal enum Device: CustomStringConvertible {
return "iPhone 13 - \(orientation)"
case let .iPhone13mini(orientation):
return "iPhone 13 mini - \(orientation)"
case let .iPhone14(orientation):
return "iPhone 14 - \(orientation)"
case let .iPhone14Plus(orientation):
return "iPhone 14 Plus - \(orientation)"
case let .iPhone14Pro(orientation):
return "iPhone 14 Pro - \(orientation)"
case let .iPhone14ProMax(orientation):
return "iPhone 14 Pro Max - \(orientation)"
}
}
}
9 changes: 9 additions & 0 deletions Tests/LayoutTests/Support/SnapshotTesting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import Nimble
import SnapshotTesting
import SnapshotTestingExtensions
import UIKit
import XCTest

Expand Down Expand Up @@ -72,6 +73,14 @@ extension Device {
return .iPhone13(orientation.configOrientation)
case let .iPhone13mini(orientation):
return .iPhone13Mini(orientation.configOrientation)
case let .iPhone14(orientation):
return .iPhone14(orientation.configOrientation)
case let .iPhone14Plus(orientation):
return .iPhone14Plus(orientation.configOrientation)
case let .iPhone14Pro(orientation):
return .iPhone14Pro(orientation.configOrientation)
case let .iPhone14ProMax(orientation):
return .iPhone14ProMax(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: 428, height: 926)>
| <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.
Loading

0 comments on commit b0ad58e

Please sign in to comment.