diff --git a/CHANGELOG.md b/CHANGELOG.md index 863458b10..8ae47e89d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,14 @@ Guide: https://keepachangelog.com/en/1.0.0/ - [Offline] Added OfflineIndexObserver which accepts two blocks for indexChanged or error events. This can be assigned to the offline search engine to receive state updates. +- [Offline] Change default tileset name to `mbx-main` +- [Tests] Fix Offline tests and re-enable. +- [Tests] Add `offlineResultsUpdated` delegate function to `SearchEngineDelegateStub`. +- [Tests] Demonstrate providing a `Geometry(point: NSValue(mkCoordinate: CLLocationCoordinate2D))` with `TileRegionLoadOptions.build` function. +- [Core] Increment minimum MapboxCommon version from 24.0.0 to 24.2.0. + +**MapboxCommon**: v24.2.0 + ## 2.0.0-rc.3 - [Core] Add `SearchResultAccuracy.proximate` case which "is a known address point but does not intersect a known rooftop/parcel." diff --git a/Cartfile b/Cartfile index f4021b2b4..530d47dbc 100644 --- a/Cartfile +++ b/Cartfile @@ -1,2 +1,2 @@ binary "https://api.mapbox.com/downloads/v2/carthage/search-core-sdk/MapboxCoreSearch.xcframework.json" == 2.0.0-alpha.14 -binary "https://api.mapbox.com/downloads/v2/carthage/mapbox-common/MapboxCommon.json" == 24.0.0 +binary "https://api.mapbox.com/downloads/v2/carthage/mapbox-common/MapboxCommon.json" == 24.2.0 \ No newline at end of file diff --git a/Cartfile.resolved b/Cartfile.resolved index a1c6204fe..0cf38f59e 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,2 +1,2 @@ -binary "https://api.mapbox.com/downloads/v2/carthage/mapbox-common/MapboxCommon.json" "24.0.0" +binary "https://api.mapbox.com/downloads/v2/carthage/mapbox-common/MapboxCommon.json" "24.2.0" binary "https://api.mapbox.com/downloads/v2/carthage/search-core-sdk/MapboxCoreSearch.xcframework.json" "2.0.0-alpha.14" diff --git a/Package.swift b/Package.swift index c2df3da6a..e36ab2f8c 100644 --- a/Package.swift +++ b/Package.swift @@ -6,7 +6,7 @@ import Foundation let (coreSearchVersion, coreSearchVersionHash) = ("2.0.0-alpha.14", "c3e61341f2beb1b8043f3c71caccdd9bea12a23f221cb90eb452e2abe299c3e0") -let commonMinVersion = Version("24.0.0") +let commonMinVersion = Version("24.2.0") let commonMaxVersion = Version("25.0.0") let package = Package( diff --git a/Sources/Demo/MapRootController.swift b/Sources/Demo/MapRootController.swift index 1ab8c2a86..38d191188 100644 --- a/Sources/Demo/MapRootController.swift +++ b/Sources/Demo/MapRootController.swift @@ -31,7 +31,12 @@ class MapRootController: UIViewController { engine.setOfflineMode(.enabled) { let descriptor = SearchOfflineManager.createDefaultTilesetDescriptor() - let dcLocation = NSValue(cgPoint: CGPoint(x: 38.89992081005698, y: -77.03399849939174)) + + let dcLocation = NSValue(mkCoordinate: CLLocationCoordinate2D( + latitude: 38.89992081005698, + longitude: -77.03399849939174 + )) + guard let options = MapboxCommon.TileRegionLoadOptions.build( geometry: Geometry(point: dcLocation), descriptors: [descriptor], diff --git a/Sources/MapboxSearch/PublicAPI/Offline/SearchOfflineManager.swift b/Sources/MapboxSearch/PublicAPI/Offline/SearchOfflineManager.swift index 81353e648..cf8a898cc 100644 --- a/Sources/MapboxSearch/PublicAPI/Offline/SearchOfflineManager.swift +++ b/Sources/MapboxSearch/PublicAPI/Offline/SearchOfflineManager.swift @@ -2,7 +2,7 @@ import Foundation /// OfflineManager handles `TileStore`s and responsible for creating Search `TilsetDescriptor`s public class SearchOfflineManager { - static let defaultDatasetName = "test-dataset" + static let defaultDatasetName = "mbx-main" var engine: CoreSearchEngineProtocol diff --git a/Tests/Demo.xctestplan b/Tests/Demo.xctestplan index 4adbfc008..7dcacae8b 100644 --- a/Tests/Demo.xctestplan +++ b/Tests/Demo.xctestplan @@ -35,8 +35,7 @@ "testTargets" : [ { "skippedTests" : [ - "MockServerIntegrationTestCase", - "OfflineIntegrationTests" + "MockServerIntegrationTestCase" ], "target" : { "containerPath" : "container:MapboxSearch.xcodeproj", diff --git a/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift index 1f836bf6c..200916951 100644 --- a/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift @@ -6,14 +6,16 @@ import MapboxCommon @testable import MapboxSearch import XCTest -class OfflineIntegrationTests: MockServerIntegrationTestCase<GeocodingMockResponse> { +/// Note: ``OfflineIntegrationTests`` does not use Mocked data. +class OfflineIntegrationTests: MockServerIntegrationTestCase<SBSMockResponse> { let delegate = SearchEngineDelegateStub() let searchEngine = SearchEngine() - let dataset = "test-dataset" - let dcLocation = CGPoint(x: 38.89992081005698, y: -77.03399849939174) + let dcLocation = CLLocationCoordinate2D(latitude: 38.89992081005698, longitude: -77.03399849939174) let regionId = "dc" + // MARK: - Helpers and set up + override func setUpWithError() throws { try super.setUpWithError() @@ -36,13 +38,15 @@ class OfflineIntegrationTests: MockServerIntegrationTestCase<GeocodingMockRespon func loadData(completion: @escaping (Result<MapboxCommon.TileRegion, MapboxSearch.TileRegionError>) -> Void) -> SearchCancelable { + /// This will use the default dataset defined at ``SearchOfflineManager.defaultDatasetName`` let descriptor = SearchOfflineManager.createDefaultTilesetDescriptor() - let dcLocationValue = NSValue(cgPoint: dcLocation) + let dcLocationValue = NSValue(mkCoordinate: dcLocation) let options = MapboxCommon.TileRegionLoadOptions.build( geometry: Geometry(point: dcLocationValue), descriptors: [descriptor], acceptExpired: true )! + let cancelable = searchEngine.offlineManager.tileStore.loadTileRegion(id: regionId, options: options) { _ in } completion: { result in completion(result) @@ -54,6 +58,8 @@ class OfflineIntegrationTests: MockServerIntegrationTestCase<GeocodingMockRespon searchEngine.offlineManager.tileStore.removeTileRegion(id: regionId) } + // MARK: - Tests + func testLoadData() throws { clearData() @@ -81,14 +87,21 @@ class OfflineIntegrationTests: MockServerIntegrationTestCase<GeocodingMockRespon } loadDataExpectation.fulfill() } - wait(for: [loadDataExpectation], timeout: 200) - wait(for: [indexChangedExpectation], timeout: 200) - - let updateExpectation = delegate.updateExpectation - searchEngine.search(query: "dc") - wait(for: [updateExpectation], timeout: 10) - - XCTAssert(searchEngine.suggestions.isEmpty == false) + wait( + for: [loadDataExpectation, indexChangedExpectation], + timeout: 200, + enforceOrder: true + ) + + let offlineUpdateExpectation = delegate.offlineUpdateExpectation + searchEngine.search(query: "coffee") + wait(for: [offlineUpdateExpectation], timeout: 10) + + XCTAssertNil(delegate.error) + XCTAssertNil(delegate.error?.localizedDescription) + XCTAssertNotNil(searchEngine.responseInfo) + XCTAssertFalse(delegate.resolvedResults.isEmpty) + XCTAssertFalse(searchEngine.suggestions.isEmpty) } func testNoData() { diff --git a/Tests/MapboxSearchTests/Common/Stubs&Models/SearchEngineDelegateStub.swift b/Tests/MapboxSearchTests/Common/Stubs&Models/SearchEngineDelegateStub.swift index 9eb39ac57..9efc5632f 100644 --- a/Tests/MapboxSearchTests/Common/Stubs&Models/SearchEngineDelegateStub.swift +++ b/Tests/MapboxSearchTests/Common/Stubs&Models/SearchEngineDelegateStub.swift @@ -10,6 +10,7 @@ class SearchEngineDelegateStub: SearchEngineDelegate { let successNotificationName = Notification.Name("SearchEngineDelegateStub.success") let updateNotificationName = Notification.Name("SearchEngineDelegateStub.update") let batchUpdateNotificationName = Notification.Name("SearchEngineDelegateStub.batchUpdate") + let offlineUpdateNotificationName = Notification.Name("SearchEngineDelegateStub.offlineUpdate") var errorExpectation: XCTNSNotificationExpectation { XCTNSNotificationExpectation(name: errorNotificationName, object: self) @@ -27,33 +28,12 @@ class SearchEngineDelegateStub: SearchEngineDelegate { XCTNSNotificationExpectation(name: batchUpdateNotificationName, object: self) } - func subscribe(listener: Any, selector: Selector) { - NotificationCenter.default.addObserver( - listener, - selector: selector, - name: successNotificationName, - object: self - ) - NotificationCenter.default.addObserver( - listener, - selector: selector, - name: updateNotificationName, - object: self - ) - NotificationCenter.default.addObserver( - listener, - selector: selector, - name: errorNotificationName, - object: self - ) - NotificationCenter.default.addObserver( - listener, - selector: selector, - name: batchUpdateNotificationName, - object: self - ) + var offlineUpdateExpectation: XCTNSNotificationExpectation { + XCTNSNotificationExpectation(name: offlineUpdateNotificationName, object: self) } + // MARK: SearchEngineDelegate + func resultsResolved(results: [SearchResult], searchEngine: SearchEngine) { resolvedResults = results NotificationCenter.default.post(name: batchUpdateNotificationName, object: self) @@ -72,4 +52,9 @@ class SearchEngineDelegateStub: SearchEngineDelegate { error = searchError NotificationCenter.default.post(name: errorNotificationName, object: self) } + + func offlineResultsUpdated(_ results: [SearchResult], suggestions: [SearchSuggestion], searchEngine: SearchEngine) { + resolvedResults = results + NotificationCenter.default.post(name: offlineUpdateNotificationName, object: self) + } }