Skip to content

Commit

Permalink
Fix failing camera animator related tests (#2124)
Browse files Browse the repository at this point in the history
- Properly dispose camera animator's status observations in tests
- Use weak reference to the camera animation in the runner's observation so the animator can be released upon pausing/stopping
  • Loading branch information
maios authored Apr 23, 2024
1 parent a374270 commit 5528f34
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Sources/MapboxMaps/Camera/CameraAnimatorsRunner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ internal final class CameraAnimatorsRunner: CameraAnimatorsRunnerProtocol {
func add(_ animator: CameraAnimatorProtocol) {
allCameraAnimators.add(animator)

animator.onCameraAnimatorStatusChanged.observe { [weak self] status in
animator.onCameraAnimatorStatusChanged.observe { [weak self, weak animator] status in
guard let animator else { return }
switch status {
case .started:
self?.cameraAnimatorDidStartRunning(animator)
Expand Down
5 changes: 3 additions & 2 deletions Tests/MapboxMapsTests/Camera/BasicCameraAnimatorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,10 @@ final class BasicCameraAnimatorTests: XCTestCase {

func testOnStarted() {
var isStarted = false
let token = animator.onStarted.observe {
var cancelables = Set<AnyCancelable>()
animator.onStarted.observe {
isStarted = true
}
}.store(in: &cancelables)

impl.$onCameraAnimatorStatusChanged.send(.started)
XCTAssertTrue(isStarted)
Expand Down
5 changes: 2 additions & 3 deletions Tests/MapboxMapsTests/Camera/FlyToCameraAnimatorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ final class FlyToCameraAnimatorTests: XCTestCase {

func testOnStarted() {
var isStarted = false
let token = flyToCameraAnimator.onStarted.observe {
flyToCameraAnimator.onStarted.observe {
isStarted = true
}
}.store(in: &cancelables)

flyToCameraAnimator.startAnimation()
XCTAssertTrue(isStarted)
Expand All @@ -231,7 +231,6 @@ final class FlyToCameraAnimatorTests: XCTestCase {

func testOnCancelled() {
var isCancelled = false
var cancelables = Set<AnyCancelable>()
flyToCameraAnimator.onFinished.observe {
XCTFail("animator is not finished")
}.store(in: &cancelables)
Expand Down

0 comments on commit 5528f34

Please sign in to comment.