forked from maplibre/swiftui-dsl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor refactoring; introduce more snapshot tests to make things cleaner
- Loading branch information
1 parent
875aff8
commit c22d05d
Showing
14 changed files
with
103 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 14 additions & 26 deletions
40
Tests/MapLibreSwiftUITests/Models/MapCamera/MapViewCameraTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,37 @@ | ||
import CoreLocation | ||
import SnapshotTesting | ||
import XCTest | ||
@testable import MapLibreSwiftUI | ||
|
||
final class MapViewCameraTests: XCTestCase { | ||
func testCenterCamera() { | ||
let expectedCoordinate = CLLocationCoordinate2D(latitude: 12.3, longitude: 23.4) | ||
let pitch: CameraPitch = .freeWithinRange(minimum: 12, maximum: 34) | ||
let direction: CLLocationDirection = 23 | ||
|
||
let camera = MapViewCamera.center(expectedCoordinate, zoom: 12, pitch: pitch, direction: direction) | ||
|
||
XCTAssertEqual(camera.state, .centered(onCoordinate: expectedCoordinate)) | ||
XCTAssertEqual(camera.zoom, 12) | ||
XCTAssertEqual(camera.pitch, pitch) | ||
XCTAssertEqual(camera.direction, direction) | ||
let camera = MapViewCamera.center( | ||
CLLocationCoordinate2D(latitude: 12.3, longitude: 23.4), | ||
zoom: 5, | ||
pitch: .freeWithinRange(minimum: 12, maximum: 34), | ||
direction: 23 | ||
) | ||
|
||
assertSnapshot(of: camera, as: .dump) | ||
} | ||
|
||
func testTrackingUserLocation() { | ||
let pitch: CameraPitch = .freeWithinRange(minimum: 12, maximum: 34) | ||
let camera = MapViewCamera.trackUserLocation(pitch: pitch) | ||
let camera = MapViewCamera.trackUserLocation(zoom: 10, pitch: pitch) | ||
|
||
XCTAssertEqual(camera.state, .trackingUserLocation) | ||
XCTAssertEqual(camera.zoom, 10) | ||
XCTAssertEqual(camera.pitch, pitch) | ||
XCTAssertEqual(camera.direction, 0) | ||
assertSnapshot(of: camera, as: .dump) | ||
} | ||
|
||
func testTrackUserLocationWithCourse() { | ||
let pitch: CameraPitch = .freeWithinRange(minimum: 12, maximum: 34) | ||
let camera = MapViewCamera.trackUserLocationWithCourse(zoom: 18, pitch: pitch) | ||
|
||
XCTAssertEqual(camera.state, .trackingUserLocationWithCourse) | ||
XCTAssertEqual(camera.zoom, 18) | ||
XCTAssertEqual(camera.pitch, pitch) | ||
XCTAssertEqual(camera.direction, 0) | ||
assertSnapshot(of: camera, as: .dump) | ||
} | ||
|
||
func testTrackUserLocationWithHeading() { | ||
let camera = MapViewCamera.trackUserLocationWithHeading() | ||
let camera = MapViewCamera.trackUserLocationWithHeading(zoom: 10, pitch: .free) | ||
|
||
XCTAssertEqual(camera.state, .trackingUserLocationWithHeading) | ||
XCTAssertEqual(camera.zoom, 10) | ||
XCTAssertEqual(camera.pitch, .free) | ||
XCTAssertEqual(camera.direction, 0) | ||
assertSnapshot(of: camera, as: .dump) | ||
} | ||
|
||
// TODO: Add additional camera tests once behaviors are added (e.g. rect) | ||
} |
1 change: 1 addition & 0 deletions
1
...eSwiftUITests/Models/MapCamera/__Snapshots__/CameraStateTests/testCenterCameraState.1.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CameraState.centered(onCoordinate: CLLocationCoordinate2D(latitude: 12.3, longitude: 23.4)) |
1 change: 1 addition & 0 deletions
1
Tests/MapLibreSwiftUITests/Models/MapCamera/__Snapshots__/CameraStateTests/testRect.1.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CameraState.rect(northeast: CLLocationCoordinate2D(latitude: 12.3, longitude: 23.4), southwest: CLLocationCoordinate2D(latitude: 34.5, longitude: 45.6)) |
1 change: 1 addition & 0 deletions
1
...iftUITests/Models/MapCamera/__Snapshots__/CameraStateTests/testTrackingUserLocation.1.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CameraState.trackingUserLocation |
1 change: 1 addition & 0 deletions
1
.../Models/MapCamera/__Snapshots__/CameraStateTests/testTrackingUserLocationWithCourse.1.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CameraState.trackingUserLocationWithCourse |
1 change: 1 addition & 0 deletions
1
...Models/MapCamera/__Snapshots__/CameraStateTests/testTrackingUserLocationWithHeading.1.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CameraState.trackingUserLocationWithHeading |
13 changes: 13 additions & 0 deletions
13
...ibreSwiftUITests/Models/MapCamera/__Snapshots__/MapViewCameraTests/testCenterCamera.1.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
▿ MapViewCamera | ||
- direction: 23.0 | ||
- lastReasonForChange: Optional<CameraChangeReason>.none | ||
▿ pitch: CameraPitch | ||
▿ freeWithinRange: (2 elements) | ||
- minimum: 12.0 | ||
- maximum: 34.0 | ||
▿ state: CameraState | ||
▿ centered: (1 element) | ||
▿ onCoordinate: CLLocationCoordinate2D | ||
- latitude: 12.3 | ||
- longitude: 23.4 | ||
- zoom: 5.0 |
10 changes: 10 additions & 0 deletions
10
...s/Models/MapCamera/__Snapshots__/MapViewCameraTests/testTrackUserLocationWithCourse.1.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
▿ MapViewCamera | ||
- direction: 0.0 | ||
▿ lastReasonForChange: Optional<CameraChangeReason> | ||
- some: CameraChangeReason.programmatic | ||
▿ pitch: CameraPitch | ||
▿ freeWithinRange: (2 elements) | ||
- minimum: 12.0 | ||
- maximum: 34.0 | ||
- state: CameraState.CameraState.trackingUserLocationWithCourse | ||
- zoom: 18.0 |
7 changes: 7 additions & 0 deletions
7
.../Models/MapCamera/__Snapshots__/MapViewCameraTests/testTrackUserLocationWithHeading.1.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
▿ MapViewCamera | ||
- direction: 0.0 | ||
▿ lastReasonForChange: Optional<CameraChangeReason> | ||
- some: CameraChangeReason.programmatic | ||
- pitch: CameraPitch.free | ||
- state: CameraState.CameraState.trackingUserLocationWithHeading | ||
- zoom: 10.0 |
10 changes: 10 additions & 0 deletions
10
...tUITests/Models/MapCamera/__Snapshots__/MapViewCameraTests/testTrackingUserLocation.1.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
▿ MapViewCamera | ||
- direction: 0.0 | ||
▿ lastReasonForChange: Optional<CameraChangeReason> | ||
- some: CameraChangeReason.programmatic | ||
▿ pitch: CameraPitch | ||
▿ freeWithinRange: (2 elements) | ||
- minimum: 12.0 | ||
- maximum: 34.0 | ||
- state: CameraState.CameraState.trackingUserLocation | ||
- zoom: 10.0 |