Skip to content

Commit

Permalink
update snapshot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mltbnz committed Aug 8, 2024
1 parent 95c8aef commit cff19f4
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-snapshot-testing.git",
"state" : {
"revision" : "c097f955b4e724690f0fc8ffb7a6d4b881c9c4e3",
"version" : "1.17.2"
"revision" : "6d932a79e7173b275b96c600c86c603cf84f153c",
"version" : "1.17.4"
}
},
{
Expand Down
23 changes: 13 additions & 10 deletions CriticalMapsKit/Sources/TestHelper/XCTestCase+Additions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ private let operatingSystemVersion = ProcessInfo().operatingSystemVersion
public extension XCTestCase {
private func enforceSnapshotDevice() {
let is2XDevice = UIScreen.main.scale >= 2
let isMinVersion14 = operatingSystemVersion.majorVersion >= 15
let isMinVersion16 = operatingSystemVersion.majorVersion >= 16

guard is2XDevice, isMinVersion14 else {
guard is2XDevice, isMinVersion16 else {
fatalError("Screenshot test device should use @2x screen scale and iOS 14.4")
}
}
Expand Down Expand Up @@ -48,6 +48,7 @@ public extension XCTestCase {
func assertViewSnapshot<V: View>(
_ view: V,
height: CGFloat? = nil,
width: CGFloat = 375,
sloppy: Bool = false,
file: StaticString = #file,
testName: String = #function,
Expand All @@ -57,16 +58,18 @@ public extension XCTestCase {

var layout = SwiftUISnapshotLayout.device(config: .iPhone8)
if let height = height {
layout = .fixed(width: 375, height: height)
layout = .fixed(width: width, height: height)
}
let precision: Float = (sloppy ? XCTestCase.sloppyPrecision : 1)

assertSnapshot(
matching: view,
as: .image(precision: precision, layout: layout),
file: file,
testName: testName,
line: line
)
withSnapshotTesting(diffTool: .ksdiff) {
assertSnapshot(
of: view,
as: .image(precision: precision, layout: layout),
file: file,
testName: testName,
line: line
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class UserTrackingButtonSnapshotTests: XCTestCase {
)
)

assertViewSnapshot(sut, height: 60, sloppy: true)
assertViewSnapshot(sut, height: 60, width: 60, sloppy: true)
}

@MainActor
Expand All @@ -24,7 +24,7 @@ final class UserTrackingButtonSnapshotTests: XCTestCase {
)
)

assertViewSnapshot(sut, height: 60, sloppy: true)
assertViewSnapshot(sut, height: 60, width: 60, sloppy: true)
}

@MainActor
Expand All @@ -36,6 +36,6 @@ final class UserTrackingButtonSnapshotTests: XCTestCase {
)
)

assertViewSnapshot(sut, height: 60, sloppy: true)
assertViewSnapshot(sut, height: 60, width: 60, sloppy: true)
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit cff19f4

Please sign in to comment.