Skip to content

Commit

Permalink
Make snapshot helpers reproducible (expect tests to fail)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthetechie committed Aug 24, 2024
1 parent b84df18 commit d454902
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
18 changes: 11 additions & 7 deletions Tests/MapLibreSwiftUITests/Examples/MapControlsTests.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import CoreLocation
import MapLibreSwiftDSL
import SnapshotTesting
import XCTest
@testable import MapLibreSwiftUI

final class MapControlsTests: XCTestCase {
// NOTE: The map views in this test intentionally have a non-north orientation
// so that the compass will be rendered if present.

@MainActor
func testEmptyControls() {
assertView {
MapView(styleURL: demoTilesURL)
MapView(styleURL: demoTilesURL, camera: .constant(.center(CLLocationCoordinate2D(), zoom: 4, direction: 45)))
.mapControls {
// No controls
}
Expand All @@ -17,7 +21,7 @@ final class MapControlsTests: XCTestCase {
@MainActor
func testLogoOnly() {
assertView {
MapView(styleURL: demoTilesURL)
MapView(styleURL: demoTilesURL, camera: .constant(.center(CLLocationCoordinate2D(), zoom: 4, direction: 45)))
.mapControls {
LogoView()
}
Expand All @@ -27,7 +31,7 @@ final class MapControlsTests: XCTestCase {
@MainActor
func testLogoChangePosition() {
assertView {
MapView(styleURL: demoTilesURL)
MapView(styleURL: demoTilesURL, camera: .constant(.center(CLLocationCoordinate2D(), zoom: 4, direction: 45)))
.mapControls {
LogoView()
.position(.topLeft)
Expand All @@ -38,7 +42,7 @@ final class MapControlsTests: XCTestCase {
@MainActor
func testCompassOnly() {
assertView {

Check failure on line 44 in Tests/MapLibreSwiftUITests/Examples/MapControlsTests.swift

View workflow job for this annotation

GitHub Actions / test (MapLibreSwiftUI-Package, platform=iOS Simulator,name=iPhone 15,OS=17.5)

testCompassOnly, failed - Snapshot does not match reference.
MapView(styleURL: demoTilesURL)
MapView(styleURL: demoTilesURL, camera: .constant(.center(CLLocationCoordinate2D(), zoom: 4, direction: 45)))
.mapControls {
CompassView()
}
Expand All @@ -48,7 +52,7 @@ final class MapControlsTests: XCTestCase {
@MainActor
func testCompassChangePosition() {
assertView {

Check failure on line 54 in Tests/MapLibreSwiftUITests/Examples/MapControlsTests.swift

View workflow job for this annotation

GitHub Actions / test (MapLibreSwiftUI-Package, platform=iOS Simulator,name=iPhone 15,OS=17.5)

testCompassChangePosition, failed - Snapshot does not match reference.
MapView(styleURL: demoTilesURL)
MapView(styleURL: demoTilesURL, camera: .constant(.center(CLLocationCoordinate2D(), zoom: 4, direction: 45)))
.mapControls {
CompassView()
.position(.topLeft)
Expand All @@ -59,7 +63,7 @@ final class MapControlsTests: XCTestCase {
@MainActor
func testAttributionOnly() {
assertView {

Check failure on line 65 in Tests/MapLibreSwiftUITests/Examples/MapControlsTests.swift

View workflow job for this annotation

GitHub Actions / test (MapLibreSwiftUI-Package, platform=iOS Simulator,name=iPhone 15,OS=17.5)

testAttributionOnly, failed - Snapshot does not match reference.
MapView(styleURL: demoTilesURL)
MapView(styleURL: demoTilesURL, camera: .constant(.center(CLLocationCoordinate2D(), zoom: 4, direction: 45)))
.mapControls {
AttributionButton()
}
Expand All @@ -69,7 +73,7 @@ final class MapControlsTests: XCTestCase {
@MainActor
func testAttributionChangePosition() {
assertView {

Check failure on line 75 in Tests/MapLibreSwiftUITests/Examples/MapControlsTests.swift

View workflow job for this annotation

GitHub Actions / test (MapLibreSwiftUI-Package, platform=iOS Simulator,name=iPhone 15,OS=17.5)

testAttributionChangePosition, failed - Snapshot does not match reference.
MapView(styleURL: demoTilesURL)
MapView(styleURL: demoTilesURL, camera: .constant(.center(CLLocationCoordinate2D(), zoom: 4, direction: 45)))
.mapControls {
AttributionButton()
.position(.topLeft)
Expand Down
3 changes: 3 additions & 0 deletions Tests/MapLibreSwiftUITests/Support/XCTestAssertView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extension XCTestCase {
func assertView(
named name: String? = nil,
record: Bool = false,
colorScheme: ColorScheme = .light,
frame: CGSize = CGSize(width: 430, height: 932),
expectation _: XCTestExpectation? = nil,
@ViewBuilder content: () -> some View,
Expand All @@ -15,7 +16,9 @@ extension XCTestCase {
line: UInt = #line
) {
let view = content()
.environment(\.colorScheme, colorScheme)
.frame(width: frame.width, height: frame.height)
.background(Color(red: 130 / 255, green: 203 / 255, blue: 114 / 255))

assertSnapshot(of: view,
as: .image(precision: 0.9, perceptualPrecision: 0.95),
Expand Down

0 comments on commit d454902

Please sign in to comment.