diff --git a/Tests/MapLibreSwiftUITests/Examples/MapControlsTests.swift b/Tests/MapLibreSwiftUITests/Examples/MapControlsTests.swift index 529dfec..eefa484 100644 --- a/Tests/MapLibreSwiftUITests/Examples/MapControlsTests.swift +++ b/Tests/MapLibreSwiftUITests/Examples/MapControlsTests.swift @@ -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 } @@ -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() } @@ -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) @@ -38,7 +42,7 @@ final class MapControlsTests: XCTestCase { @MainActor func testCompassOnly() { assertView { - MapView(styleURL: demoTilesURL) + MapView(styleURL: demoTilesURL, camera: .constant(.center(CLLocationCoordinate2D(), zoom: 4, direction: 45))) .mapControls { CompassView() } @@ -48,7 +52,7 @@ final class MapControlsTests: XCTestCase { @MainActor func testCompassChangePosition() { assertView { - MapView(styleURL: demoTilesURL) + MapView(styleURL: demoTilesURL, camera: .constant(.center(CLLocationCoordinate2D(), zoom: 4, direction: 45))) .mapControls { CompassView() .position(.topLeft) @@ -59,7 +63,7 @@ final class MapControlsTests: XCTestCase { @MainActor func testAttributionOnly() { assertView { - MapView(styleURL: demoTilesURL) + MapView(styleURL: demoTilesURL, camera: .constant(.center(CLLocationCoordinate2D(), zoom: 4, direction: 45))) .mapControls { AttributionButton() } @@ -69,7 +73,7 @@ final class MapControlsTests: XCTestCase { @MainActor func testAttributionChangePosition() { assertView { - MapView(styleURL: demoTilesURL) + MapView(styleURL: demoTilesURL, camera: .constant(.center(CLLocationCoordinate2D(), zoom: 4, direction: 45))) .mapControls { AttributionButton() .position(.topLeft) diff --git a/Tests/MapLibreSwiftUITests/Support/XCTestAssertView.swift b/Tests/MapLibreSwiftUITests/Support/XCTestAssertView.swift index 1f48166..5fcf06f 100644 --- a/Tests/MapLibreSwiftUITests/Support/XCTestAssertView.swift +++ b/Tests/MapLibreSwiftUITests/Support/XCTestAssertView.swift @@ -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, @@ -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),