Skip to content

Commit d454902

Browse files
committed
Make snapshot helpers reproducible (expect tests to fail)
1 parent b84df18 commit d454902

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

Tests/MapLibreSwiftUITests/Examples/MapControlsTests.swift

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
import CoreLocation
12
import MapLibreSwiftDSL
23
import SnapshotTesting
34
import XCTest
45
@testable import MapLibreSwiftUI
56

67
final class MapControlsTests: XCTestCase {
8+
// NOTE: The map views in this test intentionally have a non-north orientation
9+
// so that the compass will be rendered if present.
10+
711
@MainActor
812
func testEmptyControls() {
913
assertView {
10-
MapView(styleURL: demoTilesURL)
14+
MapView(styleURL: demoTilesURL, camera: .constant(.center(CLLocationCoordinate2D(), zoom: 4, direction: 45)))
1115
.mapControls {
1216
// No controls
1317
}
@@ -17,7 +21,7 @@ final class MapControlsTests: XCTestCase {
1721
@MainActor
1822
func testLogoOnly() {
1923
assertView {
20-
MapView(styleURL: demoTilesURL)
24+
MapView(styleURL: demoTilesURL, camera: .constant(.center(CLLocationCoordinate2D(), zoom: 4, direction: 45)))
2125
.mapControls {
2226
LogoView()
2327
}
@@ -27,7 +31,7 @@ final class MapControlsTests: XCTestCase {
2731
@MainActor
2832
func testLogoChangePosition() {
2933
assertView {
30-
MapView(styleURL: demoTilesURL)
34+
MapView(styleURL: demoTilesURL, camera: .constant(.center(CLLocationCoordinate2D(), zoom: 4, direction: 45)))
3135
.mapControls {
3236
LogoView()
3337
.position(.topLeft)
@@ -38,7 +42,7 @@ final class MapControlsTests: XCTestCase {
3842
@MainActor
3943
func testCompassOnly() {
4044
assertView {
41-
MapView(styleURL: demoTilesURL)
45+
MapView(styleURL: demoTilesURL, camera: .constant(.center(CLLocationCoordinate2D(), zoom: 4, direction: 45)))
4246
.mapControls {
4347
CompassView()
4448
}
@@ -48,7 +52,7 @@ final class MapControlsTests: XCTestCase {
4852
@MainActor
4953
func testCompassChangePosition() {
5054
assertView {
51-
MapView(styleURL: demoTilesURL)
55+
MapView(styleURL: demoTilesURL, camera: .constant(.center(CLLocationCoordinate2D(), zoom: 4, direction: 45)))
5256
.mapControls {
5357
CompassView()
5458
.position(.topLeft)
@@ -59,7 +63,7 @@ final class MapControlsTests: XCTestCase {
5963
@MainActor
6064
func testAttributionOnly() {
6165
assertView {
62-
MapView(styleURL: demoTilesURL)
66+
MapView(styleURL: demoTilesURL, camera: .constant(.center(CLLocationCoordinate2D(), zoom: 4, direction: 45)))
6367
.mapControls {
6468
AttributionButton()
6569
}
@@ -69,7 +73,7 @@ final class MapControlsTests: XCTestCase {
6973
@MainActor
7074
func testAttributionChangePosition() {
7175
assertView {
72-
MapView(styleURL: demoTilesURL)
76+
MapView(styleURL: demoTilesURL, camera: .constant(.center(CLLocationCoordinate2D(), zoom: 4, direction: 45)))
7377
.mapControls {
7478
AttributionButton()
7579
.position(.topLeft)

Tests/MapLibreSwiftUITests/Support/XCTestAssertView.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ extension XCTestCase {
77
func assertView(
88
named name: String? = nil,
99
record: Bool = false,
10+
colorScheme: ColorScheme = .light,
1011
frame: CGSize = CGSize(width: 430, height: 932),
1112
expectation _: XCTestExpectation? = nil,
1213
@ViewBuilder content: () -> some View,
@@ -15,7 +16,9 @@ extension XCTestCase {
1516
line: UInt = #line
1617
) {
1718
let view = content()
19+
.environment(\.colorScheme, colorScheme)
1820
.frame(width: frame.width, height: frame.height)
21+
.background(Color(red: 130 / 255, green: 203 / 255, blue: 114 / 255))
1922

2023
assertSnapshot(of: view,
2124
as: .image(precision: 0.9, perceptualPrecision: 0.95),

0 commit comments

Comments
 (0)