Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make snapshot helpers reproducible #49

Merged
merged 3 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import XCTest

final class CameraPreviewTests: XCTestCase {
func testCameraPreview() {
assertView(named: "CameraPreview") {
assertView {
CameraDirectManipulationPreview(
styleURL: URL(string: "https://demotiles.maplibre.org/style.json")!
)
Expand Down
87 changes: 56 additions & 31 deletions Tests/MapLibreSwiftUITests/Examples/MapControlsTests.swift
Original file line number Diff line number Diff line change
@@ -1,79 +1,104 @@
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)
.mapControls {
// No controls
}
MapView(
styleURL: demoTilesURL,
camera: .constant(.center(CLLocationCoordinate2D(), zoom: 4, direction: 45))
)
.mapControls {
// No controls
}
}
}

@MainActor
func testLogoOnly() {
assertView {
MapView(styleURL: demoTilesURL)
.mapControls {
LogoView()
}
MapView(
styleURL: demoTilesURL,
camera: .constant(.center(CLLocationCoordinate2D(), zoom: 4, direction: 45))
)
.mapControls {
LogoView()
}
}
}

@MainActor
func testLogoChangePosition() {
assertView {
MapView(styleURL: demoTilesURL)
.mapControls {
LogoView()
.position(.topLeft)
}
MapView(
styleURL: demoTilesURL,
camera: .constant(.center(CLLocationCoordinate2D(), zoom: 4, direction: 45))
)
.mapControls {
LogoView()
.position(.topLeft)
}
}
}

@MainActor
func testCompassOnly() {
assertView {
MapView(styleURL: demoTilesURL)
.mapControls {
CompassView()
}
MapView(
styleURL: demoTilesURL,
camera: .constant(.center(CLLocationCoordinate2D(), zoom: 4, direction: 45))
)
.mapControls {
CompassView()
}
}
}

@MainActor
func testCompassChangePosition() {
assertView {
MapView(styleURL: demoTilesURL)
.mapControls {
CompassView()
.position(.topLeft)
}
MapView(
styleURL: demoTilesURL,
camera: .constant(.center(CLLocationCoordinate2D(), zoom: 4, direction: 45))
)
.mapControls {
CompassView()
.position(.topLeft)
}
}
}

@MainActor
func testAttributionOnly() {
assertView {
MapView(styleURL: demoTilesURL)
.mapControls {
AttributionButton()
}
MapView(
styleURL: demoTilesURL,
camera: .constant(.center(CLLocationCoordinate2D(), zoom: 4, direction: 45))
)
.mapControls {
AttributionButton()
}
}
}

@MainActor
func testAttributionChangePosition() {
assertView {
MapView(styleURL: demoTilesURL)
.mapControls {
AttributionButton()
.position(.topLeft)
}
MapView(
styleURL: demoTilesURL,
camera: .constant(.center(CLLocationCoordinate2D(), zoom: 4, direction: 45))
)
.mapControls {
AttributionButton()
.position(.topLeft)
}
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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.
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.
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.
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.
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
Loading