Skip to content

Commit

Permalink
Fix UI snapshots. (#3585)
Browse files Browse the repository at this point in the history
* Remove old snapshots.

* Add a check for the correct simulator name.

* Record mismatched snapshots.

* Regenerate more snapshots using a (temporary) higher precision.

* Fix snapshot.
  • Loading branch information
pixlwave authored Dec 4, 2024
1 parent 0085c20 commit ab21520
Show file tree
Hide file tree
Showing 145 changed files with 170 additions and 365 deletions.
27 changes: 18 additions & 9 deletions UITests/Sources/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ enum Application {
guard deviceModel == requirediPhoneSimulator || deviceModel == requirediPadSimulator else {
fatalError("Running on \(deviceModel) but we only support \(requirediPhoneSimulator) and \(requirediPadSimulator).")
}
guard UIDevice.current.snapshotName == "iPhone-18.1" || UIDevice.current.snapshotName == "iPad-18.1" else {
fatalError("Running on a simulator that hasn't been renamed to match the expected snapshot filenames.")
}
}
}

Expand Down Expand Up @@ -91,15 +94,7 @@ extension XCUIApplication {
}

private var deviceName: String {
var name = UIDevice.current.name

// When running with parallel execution simulators are named "Clone 2 of iPhone 14" etc.
// Tidy this prefix out of the name to generate snapshots with the correct name.
if name.starts(with: "Clone "), let range = name.range(of: " of ") {
name = String(name[range.upperBound...])
}

return name
UIDevice.current.snapshotName
}

private var localeCode: String {
Expand All @@ -118,6 +113,20 @@ extension XCUIApplication {
}
}

private extension UIDevice {
var snapshotName: String {
var name = name

// When running with parallel execution simulators are named "Clone 2 of iPhone 14" etc.
// Tidy this prefix out of the name to generate snapshots with the correct name.
if name.starts(with: "Clone "), let range = name.range(of: " of ") {
name = String(name[range.upperBound...])
}

return name
}
}

private extension UIImage {
/// Adjusts the image by cropping it with the given edge insets.
func inset(by insets: UIEdgeInsets) -> UIImage {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

This file was deleted.

Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Loading

0 comments on commit ab21520

Please sign in to comment.