Created
February 10, 2023 12:28
-
-
Save Jxrgxn/5824d0352799a416b877b722ef7c122a to your computer and use it in GitHub Desktop.
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
import XCTest | |
import CoreLocation | |
class RBLocationManagerTests: XCTestCase { | |
var locationManager: RBLocationManager! | |
override func setUp() { | |
super.setUp() | |
locationManager = RBLocationManager.shared | |
} | |
func testRequestLocationsPermissions() { | |
let authorizationExpectation = expectation(description: "Location authorization") | |
locationManager.requestLocationsPermissions() | |
locationManager.locationManager.requestWhenInUseAuthorization() | |
locationManager.locationManager.requestAlwaysAuthorization() | |
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { | |
XCTAssertEqual(self.locationManager.locationManager.authorizationStatus, CLAuthorizationStatus.authorizedWhenInUse) | |
authorizationExpectation.fulfill() | |
} | |
waitForExpectations(timeout: 2.0, handler: nil) | |
} | |
func testRequestAlwaysAuthorization() { | |
let authorizationExpectation = expectation(description: "Location authorization") | |
locationManager.requestAlwaysAuthorization() | |
locationManager.locationManager.requestAlwaysAuthorization() | |
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { | |
XCTAssertEqual(self.locationManager.locationManager.authorizationStatus, CLAuthorizationStatus.authorizedAlways) | |
authorizationExpectation.fulfill() | |
} | |
waitForExpectations(timeout: 2.0, handler: nil) | |
} | |
func testValidLocation() { | |
let locationExpectation = expectation(description: "Location validation") | |
locationManager.startLocationServices() | |
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { | |
let validLocation = self.locationManager.validLocation() | |
XCTAssertNotNil(validLocation) | |
locationExpectation.fulfill() | |
} | |
waitForExpectations(timeout: 2.0, handler: nil) | |
} | |
func testNeedsLocationPermissions() { | |
XCTAssertFalse(locationManager.needsLocationPermissions()) | |
} | |
func testUserLocationPermissions() { | |
XCTAssertEqual(locationManager.userLocationPermissions(), "when_in_use") | |
} | |
func testStartLocationServices() { | |
let authorizationExpectation = expectation(description: "Location authorization") | |
locationManager.startLocationServices() | |
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { | |
XCTAssertEqual(self.locationManager.locationManager.authorizationStatus, CLAuthorizationStatus.authorizedAlways) | |
authorizationExpectation.fulfill() | |
} | |
waitForExpectations(timeout: 2.0, handler: nil) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment