From de9912bfa3f88a452e007d5a5bcbedefd62bac9a Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Mon, 25 Mar 2024 12:45:08 -0400 Subject: [PATCH 01/17] Enable offline tests - SSDK-617 --- Tests/Demo.xctestplan | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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", From 06e0d32fe8b5d0be9ded54099fec5845691a8fe2 Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Tue, 26 Mar 2024 12:12:42 -0400 Subject: [PATCH 02/17] Update to NSValue(mkCoordinate: CLLocationCoordinate2D) for offline downloads instead of CGPoint - SSDK-617 --- Sources/Demo/MapRootController.swift | 7 ++++++- .../OfflineIntegrationTests.swift | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) 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/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift index 1ab179677..8b3b65c8b 100644 --- a/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift @@ -11,7 +11,7 @@ class OfflineIntegrationTests: MockServerIntegrationTestCase) -> Void) -> SearchCancelable { 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], From 8c7e32797960b7c907071bbcadaf1f6238591742 Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Tue, 26 Mar 2024 13:56:48 -0400 Subject: [PATCH 03/17] Update offline dataset to mbx-main - SSDK-617 --- .../PublicAPI/Offline/SearchOfflineManager.swift | 2 +- .../OfflineIntegrationTests.swift | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) 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/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift index 8b3b65c8b..25061b0f5 100644 --- a/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift @@ -6,11 +6,12 @@ import MapboxCommon @testable import MapboxSearch import XCTest -class OfflineIntegrationTests: MockServerIntegrationTestCase { +/// Note: ``OfflineIntegrationTests`` does not use Mocked data. +class OfflineIntegrationTests: MockServerIntegrationTestCase { let delegate = SearchEngineDelegateStub() let searchEngine = SearchEngine() - let dataset = "test-dataset" + let dataset = "mbx-main" let dcLocation = CLLocationCoordinate2D(latitude: 38.89992081005698, longitude: -77.03399849939174) let regionId = "dc" From 202cf101ccdb74614bea779b176eeaed2b227cd4 Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Tue, 26 Mar 2024 14:04:16 -0400 Subject: [PATCH 04/17] Remove unused reference to dataset in Offline tests - SSDK-617 - Add assertions to aid development --- .../OfflineIntegrationTests.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift index 25061b0f5..499f1d616 100644 --- a/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift @@ -11,7 +11,6 @@ class OfflineIntegrationTests: MockServerIntegrationTestCase { let delegate = SearchEngineDelegateStub() let searchEngine = SearchEngine() - let dataset = "mbx-main" let dcLocation = CLLocationCoordinate2D(latitude: 38.89992081005698, longitude: -77.03399849939174) let regionId = "dc" @@ -37,6 +36,7 @@ class OfflineIntegrationTests: MockServerIntegrationTestCase { func loadData(completion: @escaping (Result) -> Void) -> SearchCancelable { + /// This will use the default dataset defined at ``SearchOfflineManager.defaultDatasetName`` let descriptor = SearchOfflineManager.createDefaultTilesetDescriptor() let dcLocationValue = NSValue(mkCoordinate: dcLocation) let options = MapboxCommon.TileRegionLoadOptions.build( @@ -44,6 +44,7 @@ class OfflineIntegrationTests: MockServerIntegrationTestCase { descriptors: [descriptor], acceptExpired: true )! + let cancelable = searchEngine.offlineManager.tileStore.loadTileRegion(id: regionId, options: options) { _ in } completion: { result in completion(result) @@ -76,6 +77,8 @@ class OfflineIntegrationTests: MockServerIntegrationTestCase { searchEngine.search(query: "dc") wait(for: [updateExpectation], timeout: 10) + XCTAssertNil(delegate.error) + XCTAssertNil(delegate.error?.localizedDescription) XCTAssert(searchEngine.suggestions.isEmpty == false) } From 520aa1842799b8ec036e296f26256b399d28f61a Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Tue, 26 Mar 2024 16:06:54 -0400 Subject: [PATCH 05/17] Add test search engine delegate stub for offline tests - Remove unused SearchEngineDelegateStub.subscribe(listener:, selector:) --- MapboxSearch.xcodeproj/project.pbxproj | 6 ++++ .../OfflineIntegrationTests.swift | 6 ++-- .../SearchEngineDelegateStub.swift | 30 +++---------------- .../SearchEngineOfflineDelegateStub.swift | 15 ++++++++++ 4 files changed, 28 insertions(+), 29 deletions(-) create mode 100644 Tests/MapboxSearchTests/Common/Stubs&Models/SearchEngineOfflineDelegateStub.swift diff --git a/MapboxSearch.xcodeproj/project.pbxproj b/MapboxSearch.xcodeproj/project.pbxproj index e526c36f4..f936ce9c1 100644 --- a/MapboxSearch.xcodeproj/project.pbxproj +++ b/MapboxSearch.xcodeproj/project.pbxproj @@ -34,6 +34,8 @@ 048823482B6B0A9D00C770AA /* category-hotel-search-along-route-jp.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B7C2B6B043C00FDE7D5 /* category-hotel-search-along-route-jp.json */; }; 048823492B6B0A9D00C770AA /* category-hotel-search-along-route-jp.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B7C2B6B043C00FDE7D5 /* category-hotel-search-along-route-jp.json */; }; 0488234A2B6B0A9E00C770AA /* category-hotel-search-along-route-jp.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B7C2B6B043C00FDE7D5 /* category-hotel-search-along-route-jp.json */; }; + 049284EF2BB359670001EB47 /* SearchEngineOfflineDelegateStub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 049284EE2BB359670001EB47 /* SearchEngineOfflineDelegateStub.swift */; }; + 049284F02BB3597C0001EB47 /* SearchEngineOfflineDelegateStub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 049284EE2BB359670001EB47 /* SearchEngineOfflineDelegateStub.swift */; }; 04970F8D2B7A97C900213763 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 04970F8C2B7A97C900213763 /* PrivacyInfo.xcprivacy */; }; 04AB0B4B2B6AADB700FDE7D5 /* mapbox.places.san.francisco.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B4A2B6AADB700FDE7D5 /* mapbox.places.san.francisco.json */; }; 04AB0B4C2B6AADB700FDE7D5 /* mapbox.places.san.francisco.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B4A2B6AADB700FDE7D5 /* mapbox.places.san.francisco.json */; }; @@ -542,6 +544,7 @@ 046818E02B87FF5C0082B188 /* search-box-suggestions-minsk.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "search-box-suggestions-minsk.json"; sourceTree = ""; }; 047790482B890A8500A99528 /* search-box-recursion.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "search-box-recursion.json"; sourceTree = ""; }; 0477904C2B890F4E00A99528 /* search-box-retrieve-minsk.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "search-box-retrieve-minsk.json"; sourceTree = ""; }; + 049284EE2BB359670001EB47 /* SearchEngineOfflineDelegateStub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchEngineOfflineDelegateStub.swift; sourceTree = ""; }; 04970F8C2B7A97C900213763 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = ""; }; 04AB0B4A2B6AADB700FDE7D5 /* mapbox.places.san.francisco.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = mapbox.places.san.francisco.json; sourceTree = ""; }; 04AB0B792B6AF37800FDE7D5 /* CategoryIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryIntegrationTests.swift; sourceTree = ""; }; @@ -1582,6 +1585,7 @@ FEEDD38D2508E24900DC0A98 /* CoreSearchResultStub.swift */, FEEDD3912508E24900DC0A98 /* CoreSearchResponseStub.swift */, FEEDD38A2508E24900DC0A98 /* SearchEngineDelegateStub.swift */, + 049284EE2BB359670001EB47 /* SearchEngineOfflineDelegateStub.swift */, F9A59249252C75BB0074F692 /* TestDataProviderRecord.swift */, FEEDD3942508E24900DC0A98 /* CoreSearchEngineStub.swift */, F9A5925A252C799E0074F692 /* CoreUserRecordsLayerStub.swift */, @@ -2717,6 +2721,7 @@ 141789EE287C125E0000AE79 /* AddressAutofill.Suggestion+Tests.swift in Sources */, FE46559A25669B4E007ECC6A /* ServerSearchResultTests.swift in Sources */, FECB50C02553FF210026302E /* HighlightsCalculatorTests.swift in Sources */, + 049284EF2BB359670001EB47 /* SearchEngineOfflineDelegateStub.swift in Sources */, 14FA65842953618800056E5B /* PlaceAutocomplete.Options+Tests.swift in Sources */, FE22DE4C2576983F00DFEACD /* Route+Tests.swift in Sources */, F9F882B92588CCEE00062A82 /* CoreSearchResultMetadataStub.swift in Sources */, @@ -2829,6 +2834,7 @@ F9C557B72670CC5600BE8B94 /* CoreSearchResultStub.swift in Sources */, 04AB0B7B2B6AF43E00FDE7D5 /* CategoryIntegrationTests.swift in Sources */, F9C557BF2670CD4300BE8B94 /* CoreRequestOptions+Samples.swift in Sources */, + 049284F02BB3597C0001EB47 /* SearchEngineOfflineDelegateStub.swift in Sources */, F9C557BB2670CCC000BE8B94 /* SearchResultType+Extensions.swift in Sources */, F9C557BA2670CCAB00BE8B94 /* TestDataProviderRecord.swift in Sources */, 042477C32B7290F900D870D5 /* SearchEngineGeocodingIntegrationTests.swift in Sources */, diff --git a/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift index 499f1d616..75f01e5b7 100644 --- a/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift @@ -8,7 +8,7 @@ import XCTest /// Note: ``OfflineIntegrationTests`` does not use Mocked data. class OfflineIntegrationTests: MockServerIntegrationTestCase { - let delegate = SearchEngineDelegateStub() + let delegate = SearchEngineOfflineDelegateStub() let searchEngine = SearchEngine() let dcLocation = CLLocationCoordinate2D(latitude: 38.89992081005698, longitude: -77.03399849939174) @@ -73,9 +73,9 @@ class OfflineIntegrationTests: MockServerIntegrationTestCase { } wait(for: [loadDataExpectation], timeout: 200) - let updateExpectation = delegate.updateExpectation + let offlineUpdateExpectation = delegate.offlineUpdateExpectation searchEngine.search(query: "dc") - wait(for: [updateExpectation], timeout: 10) + wait(for: [offlineUpdateExpectation], timeout: 10) XCTAssertNil(delegate.error) XCTAssertNil(delegate.error?.localizedDescription) diff --git a/Tests/MapboxSearchTests/Common/Stubs&Models/SearchEngineDelegateStub.swift b/Tests/MapboxSearchTests/Common/Stubs&Models/SearchEngineDelegateStub.swift index 9eb39ac57..e12e0efb3 100644 --- a/Tests/MapboxSearchTests/Common/Stubs&Models/SearchEngineDelegateStub.swift +++ b/Tests/MapboxSearchTests/Common/Stubs&Models/SearchEngineDelegateStub.swift @@ -1,6 +1,7 @@ @testable import MapboxSearch import XCTest +/// Offline behavior is handled by specialized Stub subclass class SearchEngineDelegateStub: SearchEngineDelegate { var resolvedResult: SearchResult? var resolvedResults: [SearchResult] = [] @@ -27,32 +28,9 @@ 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 - ) - } + // MARK: SearchEngineDelegate + + // Excludes offline tests, see subclass for offline func resultsResolved(results: [SearchResult], searchEngine: SearchEngine) { resolvedResults = results diff --git a/Tests/MapboxSearchTests/Common/Stubs&Models/SearchEngineOfflineDelegateStub.swift b/Tests/MapboxSearchTests/Common/Stubs&Models/SearchEngineOfflineDelegateStub.swift new file mode 100644 index 000000000..e3ece91d3 --- /dev/null +++ b/Tests/MapboxSearchTests/Common/Stubs&Models/SearchEngineOfflineDelegateStub.swift @@ -0,0 +1,15 @@ +@testable import MapboxSearch +import XCTest + +class SearchEngineOfflineDelegateStub: SearchEngineDelegateStub { + let offlineUpdateNotificationName = Notification.Name("SearchEngineOfflineDelegateStub.offlineUpdate") + + var offlineUpdateExpectation: XCTNSNotificationExpectation { + XCTNSNotificationExpectation(name: offlineUpdateNotificationName, object: self) + } + + func offlineResultsUpdated(_ results: [SearchResult], suggestions: [SearchSuggestion], searchEngine: SearchEngine) { + resolvedResults = results + NotificationCenter.default.post(name: offlineUpdateNotificationName, object: self) + } +} From 93a014479bec2a5877f3f5b94493613faca33ee7 Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Tue, 26 Mar 2024 17:36:37 -0400 Subject: [PATCH 06/17] Fold Search engine offline stub into main stub, do not need two - SSDK-617 --- MapboxSearch.xcodeproj/project.pbxproj | 6 ------ .../OfflineIntegrationTests.swift | 2 +- .../Stubs&Models/SearchEngineDelegateStub.swift | 13 ++++++++++--- .../SearchEngineOfflineDelegateStub.swift | 15 --------------- 4 files changed, 11 insertions(+), 25 deletions(-) delete mode 100644 Tests/MapboxSearchTests/Common/Stubs&Models/SearchEngineOfflineDelegateStub.swift diff --git a/MapboxSearch.xcodeproj/project.pbxproj b/MapboxSearch.xcodeproj/project.pbxproj index f936ce9c1..e526c36f4 100644 --- a/MapboxSearch.xcodeproj/project.pbxproj +++ b/MapboxSearch.xcodeproj/project.pbxproj @@ -34,8 +34,6 @@ 048823482B6B0A9D00C770AA /* category-hotel-search-along-route-jp.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B7C2B6B043C00FDE7D5 /* category-hotel-search-along-route-jp.json */; }; 048823492B6B0A9D00C770AA /* category-hotel-search-along-route-jp.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B7C2B6B043C00FDE7D5 /* category-hotel-search-along-route-jp.json */; }; 0488234A2B6B0A9E00C770AA /* category-hotel-search-along-route-jp.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B7C2B6B043C00FDE7D5 /* category-hotel-search-along-route-jp.json */; }; - 049284EF2BB359670001EB47 /* SearchEngineOfflineDelegateStub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 049284EE2BB359670001EB47 /* SearchEngineOfflineDelegateStub.swift */; }; - 049284F02BB3597C0001EB47 /* SearchEngineOfflineDelegateStub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 049284EE2BB359670001EB47 /* SearchEngineOfflineDelegateStub.swift */; }; 04970F8D2B7A97C900213763 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 04970F8C2B7A97C900213763 /* PrivacyInfo.xcprivacy */; }; 04AB0B4B2B6AADB700FDE7D5 /* mapbox.places.san.francisco.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B4A2B6AADB700FDE7D5 /* mapbox.places.san.francisco.json */; }; 04AB0B4C2B6AADB700FDE7D5 /* mapbox.places.san.francisco.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B4A2B6AADB700FDE7D5 /* mapbox.places.san.francisco.json */; }; @@ -544,7 +542,6 @@ 046818E02B87FF5C0082B188 /* search-box-suggestions-minsk.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "search-box-suggestions-minsk.json"; sourceTree = ""; }; 047790482B890A8500A99528 /* search-box-recursion.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "search-box-recursion.json"; sourceTree = ""; }; 0477904C2B890F4E00A99528 /* search-box-retrieve-minsk.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "search-box-retrieve-minsk.json"; sourceTree = ""; }; - 049284EE2BB359670001EB47 /* SearchEngineOfflineDelegateStub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchEngineOfflineDelegateStub.swift; sourceTree = ""; }; 04970F8C2B7A97C900213763 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = ""; }; 04AB0B4A2B6AADB700FDE7D5 /* mapbox.places.san.francisco.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = mapbox.places.san.francisco.json; sourceTree = ""; }; 04AB0B792B6AF37800FDE7D5 /* CategoryIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryIntegrationTests.swift; sourceTree = ""; }; @@ -1585,7 +1582,6 @@ FEEDD38D2508E24900DC0A98 /* CoreSearchResultStub.swift */, FEEDD3912508E24900DC0A98 /* CoreSearchResponseStub.swift */, FEEDD38A2508E24900DC0A98 /* SearchEngineDelegateStub.swift */, - 049284EE2BB359670001EB47 /* SearchEngineOfflineDelegateStub.swift */, F9A59249252C75BB0074F692 /* TestDataProviderRecord.swift */, FEEDD3942508E24900DC0A98 /* CoreSearchEngineStub.swift */, F9A5925A252C799E0074F692 /* CoreUserRecordsLayerStub.swift */, @@ -2721,7 +2717,6 @@ 141789EE287C125E0000AE79 /* AddressAutofill.Suggestion+Tests.swift in Sources */, FE46559A25669B4E007ECC6A /* ServerSearchResultTests.swift in Sources */, FECB50C02553FF210026302E /* HighlightsCalculatorTests.swift in Sources */, - 049284EF2BB359670001EB47 /* SearchEngineOfflineDelegateStub.swift in Sources */, 14FA65842953618800056E5B /* PlaceAutocomplete.Options+Tests.swift in Sources */, FE22DE4C2576983F00DFEACD /* Route+Tests.swift in Sources */, F9F882B92588CCEE00062A82 /* CoreSearchResultMetadataStub.swift in Sources */, @@ -2834,7 +2829,6 @@ F9C557B72670CC5600BE8B94 /* CoreSearchResultStub.swift in Sources */, 04AB0B7B2B6AF43E00FDE7D5 /* CategoryIntegrationTests.swift in Sources */, F9C557BF2670CD4300BE8B94 /* CoreRequestOptions+Samples.swift in Sources */, - 049284F02BB3597C0001EB47 /* SearchEngineOfflineDelegateStub.swift in Sources */, F9C557BB2670CCC000BE8B94 /* SearchResultType+Extensions.swift in Sources */, F9C557BA2670CCAB00BE8B94 /* TestDataProviderRecord.swift in Sources */, 042477C32B7290F900D870D5 /* SearchEngineGeocodingIntegrationTests.swift in Sources */, diff --git a/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift index 75f01e5b7..7cff53c62 100644 --- a/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift @@ -8,7 +8,7 @@ import XCTest /// Note: ``OfflineIntegrationTests`` does not use Mocked data. class OfflineIntegrationTests: MockServerIntegrationTestCase { - let delegate = SearchEngineOfflineDelegateStub() + let delegate = SearchEngineDelegateStub() let searchEngine = SearchEngine() let dcLocation = CLLocationCoordinate2D(latitude: 38.89992081005698, longitude: -77.03399849939174) diff --git a/Tests/MapboxSearchTests/Common/Stubs&Models/SearchEngineDelegateStub.swift b/Tests/MapboxSearchTests/Common/Stubs&Models/SearchEngineDelegateStub.swift index e12e0efb3..b1d54427a 100644 --- a/Tests/MapboxSearchTests/Common/Stubs&Models/SearchEngineDelegateStub.swift +++ b/Tests/MapboxSearchTests/Common/Stubs&Models/SearchEngineDelegateStub.swift @@ -1,7 +1,6 @@ @testable import MapboxSearch import XCTest -/// Offline behavior is handled by specialized Stub subclass class SearchEngineDelegateStub: SearchEngineDelegate { var resolvedResult: SearchResult? var resolvedResults: [SearchResult] = [] @@ -11,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("SearchEngineOfflineDelegateStub.offlineUpdate") var errorExpectation: XCTNSNotificationExpectation { XCTNSNotificationExpectation(name: errorNotificationName, object: self) @@ -28,9 +28,11 @@ class SearchEngineDelegateStub: SearchEngineDelegate { XCTNSNotificationExpectation(name: batchUpdateNotificationName, object: self) } - // MARK: SearchEngineDelegate + var offlineUpdateExpectation: XCTNSNotificationExpectation { + XCTNSNotificationExpectation(name: offlineUpdateNotificationName, object: self) + } - // Excludes offline tests, see subclass for offline + // MARK: SearchEngineDelegate func resultsResolved(results: [SearchResult], searchEngine: SearchEngine) { resolvedResults = results @@ -50,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) + } } diff --git a/Tests/MapboxSearchTests/Common/Stubs&Models/SearchEngineOfflineDelegateStub.swift b/Tests/MapboxSearchTests/Common/Stubs&Models/SearchEngineOfflineDelegateStub.swift deleted file mode 100644 index e3ece91d3..000000000 --- a/Tests/MapboxSearchTests/Common/Stubs&Models/SearchEngineOfflineDelegateStub.swift +++ /dev/null @@ -1,15 +0,0 @@ -@testable import MapboxSearch -import XCTest - -class SearchEngineOfflineDelegateStub: SearchEngineDelegateStub { - let offlineUpdateNotificationName = Notification.Name("SearchEngineOfflineDelegateStub.offlineUpdate") - - var offlineUpdateExpectation: XCTNSNotificationExpectation { - XCTNSNotificationExpectation(name: offlineUpdateNotificationName, object: self) - } - - func offlineResultsUpdated(_ results: [SearchResult], suggestions: [SearchSuggestion], searchEngine: SearchEngine) { - resolvedResults = results - NotificationCenter.default.post(name: offlineUpdateNotificationName, object: self) - } -} From 15630043f735e5ba93c7f33744f76401ba1a14e8 Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Wed, 27 Mar 2024 11:49:17 -0400 Subject: [PATCH 07/17] Add bounding box to offline search test - SSDK-617 --- .../OfflineIntegrationTests.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift index 7cff53c62..ba2660fa6 100644 --- a/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift @@ -73,8 +73,15 @@ class OfflineIntegrationTests: MockServerIntegrationTestCase { } wait(for: [loadDataExpectation], timeout: 200) + // Providing a bounding box to offline search is recommended to optimize performance + let regionBounds = BoundingBox( + CLLocationCoordinate2D(latitude: 39.0002626, longitude: -76.908646), + CLLocationCoordinate2D(latitude: 38.7911851, longitude: -77.1235559) + ) + let searchOptions = SearchOptions(boundingBox: regionBounds) + let offlineUpdateExpectation = delegate.offlineUpdateExpectation - searchEngine.search(query: "dc") + searchEngine.search(query: "dc", options: searchOptions) wait(for: [offlineUpdateExpectation], timeout: 10) XCTAssertNil(delegate.error) From 051e79e49ddc46b10c31ea541d0c10fed7521d4f Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Wed, 27 Mar 2024 15:57:42 -0400 Subject: [PATCH 08/17] Fix typo in notification name - SSDK-617 --- .../Common/Stubs&Models/SearchEngineDelegateStub.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/MapboxSearchTests/Common/Stubs&Models/SearchEngineDelegateStub.swift b/Tests/MapboxSearchTests/Common/Stubs&Models/SearchEngineDelegateStub.swift index b1d54427a..9efc5632f 100644 --- a/Tests/MapboxSearchTests/Common/Stubs&Models/SearchEngineDelegateStub.swift +++ b/Tests/MapboxSearchTests/Common/Stubs&Models/SearchEngineDelegateStub.swift @@ -10,7 +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("SearchEngineOfflineDelegateStub.offlineUpdate") + let offlineUpdateNotificationName = Notification.Name("SearchEngineDelegateStub.offlineUpdate") var errorExpectation: XCTNSNotificationExpectation { XCTNSNotificationExpectation(name: errorNotificationName, object: self) From 5ba4b6d3ada2ce7e5ab831fb8c0a3ec18fe58412 Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Wed, 27 Mar 2024 20:28:23 -0400 Subject: [PATCH 09/17] Try out alternate token to triage issues - SSDK-617 --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f9c9aadf1..e7b75a285 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -270,11 +270,11 @@ commands: command: | echo "machine api.mapbox.com" >> ~/.netrc echo "login mapbox" >> ~/.netrc - echo "password $SDK_REGISTRY_TOKEN" >> ~/.netrc + echo "password $SDK_REGISTRY_TOKEN_FULL" >> ~/.netrc chmod 0600 ~/.netrc - run: name: Inject Mapbox token - command: echo $SDK_REGISTRY_TOKEN > ~/.mapbox + command: echo $SDK_REGISTRY_TOKEN_FULL > ~/.mapbox ios-install-carthage-dependencies: steps: From f28987fcc333ce772d8ae788337c003b70e2138d Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Wed, 3 Apr 2024 09:21:59 -0400 Subject: [PATCH 10/17] Require MapboxCommon 24.2.0+ for offline search - SSDK-617 --- Cartfile | 2 +- Cartfile.resolved | 2 +- .../xcshareddata/swiftpm/Package.resolved | 8 ++++---- Package.swift | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) 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/MapboxSearch.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/MapboxSearch.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index c3e68929e..90f494bb5 100644 --- a/MapboxSearch.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/MapboxSearch.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -5,8 +5,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/mattgallagher/CwlCatchException.git", "state" : { - "revision" : "3b123999de19bf04905bc1dfdb76f817b0f2cc00", - "version" : "2.1.2" + "revision" : "3ef6999c73b6938cc0da422f2c912d0158abb0a0", + "version" : "2.2.0" } }, { @@ -14,8 +14,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/mattgallagher/CwlPreconditionTesting.git", "state" : { - "revision" : "a23ded2c91df9156628a6996ab4f347526f17b6b", - "version" : "2.1.2" + "revision" : "2ef56b2caf25f55fa7eef8784c30d5a767550f54", + "version" : "2.2.1" } }, { 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( From f4231fcdb7a5997ea8c7fa30cb63ee3591c32605 Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Mon, 8 Apr 2024 17:30:03 -0400 Subject: [PATCH 11/17] Add OfflineIndexObserver for insight to Offline state - Update tests to expect offline index observer events - Update changelog - Add debug description strings for CoreOfflineIndexChangeEventType --- CHANGELOG.md | 2 ++ MapboxSearch.xcodeproj/project.pbxproj | 16 ++++++++++ .../InternalAPI/CoreAliases.swift | 6 ++++ .../CoreSearchEngineProtocol.swift | 4 +++ .../CoreOfflineIndexChangeEventType.swift | 18 ++++++++++++ .../Offline/OfflineIndexObserver.swift | 29 +++++++++++++++++++ .../OfflineIntegrationTests.swift | 13 +++++++++ .../Stubs&Models/CoreSearchEngineStub.swift | 4 +++ 8 files changed, 92 insertions(+) create mode 100644 Sources/MapboxSearch/InternalAPI/Offline/CoreOfflineIndexChangeEventType.swift create mode 100644 Sources/MapboxSearch/PublicAPI/Offline/OfflineIndexObserver.swift diff --git a/CHANGELOG.md b/CHANGELOG.md index 895fea231..863458b10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ 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. + ## 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/MapboxSearch.xcodeproj/project.pbxproj b/MapboxSearch.xcodeproj/project.pbxproj index 59c762adb..b65450aaf 100644 --- a/MapboxSearch.xcodeproj/project.pbxproj +++ b/MapboxSearch.xcodeproj/project.pbxproj @@ -31,6 +31,8 @@ 0477904D2B890F4E00A99528 /* search-box-retrieve-minsk.json in Resources */ = {isa = PBXBuildFile; fileRef = 0477904C2B890F4E00A99528 /* search-box-retrieve-minsk.json */; }; 0477904E2B890F4E00A99528 /* search-box-retrieve-minsk.json in Resources */ = {isa = PBXBuildFile; fileRef = 0477904C2B890F4E00A99528 /* search-box-retrieve-minsk.json */; }; 0477904F2B890F4E00A99528 /* search-box-retrieve-minsk.json in Resources */ = {isa = PBXBuildFile; fileRef = 0477904C2B890F4E00A99528 /* search-box-retrieve-minsk.json */; }; + 0484BCDF2BC4865C003CF408 /* OfflineIndexObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0484BCDE2BC4865C003CF408 /* OfflineIndexObserver.swift */; }; + 0484BCE22BC49A23003CF408 /* CoreOfflineIndexChangeEventType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0484BCE12BC49A23003CF408 /* CoreOfflineIndexChangeEventType.swift */; }; 048823482B6B0A9D00C770AA /* category-hotel-search-along-route-jp.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B7C2B6B043C00FDE7D5 /* category-hotel-search-along-route-jp.json */; }; 048823492B6B0A9D00C770AA /* category-hotel-search-along-route-jp.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B7C2B6B043C00FDE7D5 /* category-hotel-search-along-route-jp.json */; }; 0488234A2B6B0A9E00C770AA /* category-hotel-search-along-route-jp.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B7C2B6B043C00FDE7D5 /* category-hotel-search-along-route-jp.json */; }; @@ -540,6 +542,8 @@ 046818E02B87FF5C0082B188 /* search-box-suggestions-minsk.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "search-box-suggestions-minsk.json"; sourceTree = ""; }; 047790482B890A8500A99528 /* search-box-recursion.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "search-box-recursion.json"; sourceTree = ""; }; 0477904C2B890F4E00A99528 /* search-box-retrieve-minsk.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "search-box-retrieve-minsk.json"; sourceTree = ""; }; + 0484BCDE2BC4865C003CF408 /* OfflineIndexObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OfflineIndexObserver.swift; sourceTree = ""; }; + 0484BCE12BC49A23003CF408 /* CoreOfflineIndexChangeEventType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreOfflineIndexChangeEventType.swift; sourceTree = ""; }; 04970F8C2B7A97C900213763 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = ""; }; 04AB0B4A2B6AADB700FDE7D5 /* mapbox.places.san.francisco.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = mapbox.places.san.francisco.json; sourceTree = ""; }; 04AB0B792B6AF37800FDE7D5 /* DiscoverIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiscoverIntegrationTests.swift; sourceTree = ""; }; @@ -1052,6 +1056,14 @@ path = sbs; sourceTree = ""; }; + 0484BCE02BC49A18003CF408 /* Offline */ = { + isa = PBXGroup; + children = ( + 0484BCE12BC49A23003CF408 /* CoreOfflineIndexChangeEventType.swift */, + ); + path = Offline; + sourceTree = ""; + }; 04970F8B2B7A97C900213763 /* Resources */ = { isa = PBXGroup; children = ( @@ -1554,6 +1566,7 @@ F9274FF127394AE600708F37 /* TileRegionError.swift */, F9274FEA2732BF0E00708F37 /* SearchTileStore.swift */, F9274FF6273AAE7200708F37 /* TileRegionLoadOptions+Search.swift */, + 0484BCDE2BC4865C003CF408 /* OfflineIndexObserver.swift */, ); path = Offline; sourceTree = ""; @@ -1731,6 +1744,7 @@ FEEDD2C12508DFE400DC0A98 /* InternalAPI */ = { isa = PBXGroup; children = ( + 0484BCE02BC49A18003CF408 /* Offline */, 04C127562B62FFD000884325 /* Engine */, 148DE66E285777050085684D /* Common */, F98BECBB2577B9150081D3BC /* Telemetry */, @@ -2664,6 +2678,7 @@ F9E8146225418E7D00F6378E /* EventsManager.swift in Sources */, FEEDD3002508DFE400DC0A98 /* CLLocationCoordinate2DCodable.swift in Sources */, FEEDD3042508DFE400DC0A98 /* SearchResultType.swift in Sources */, + 0484BCE22BC49A23003CF408 /* CoreOfflineIndexChangeEventType.swift in Sources */, F91FD66C258CCB41008CB8E1 /* CoreResultType+Extensions.swift in Sources */, FEEDD3152508DFE400DC0A98 /* ServerSearchResult.swift in Sources */, 140E47A2298BC90E00677E30 /* Discover.swift in Sources */, @@ -2671,6 +2686,7 @@ 04C127552B62F6BC00884325 /* ApiType.swift in Sources */, FE059C5A251A0AE6001F7701 /* SearchCategorySuggestionImpl.swift in Sources */, FEEDD2F62508DFE400DC0A98 /* CoreSearchResultResponse.swift in Sources */, + 0484BCDF2BC4865C003CF408 /* OfflineIndexObserver.swift in Sources */, FE260A6725C063880037B725 /* ReverseGeocodingOptions.swift in Sources */, FECA461026D3F81800BC7B18 /* MapboxSearchUserAgent.swift in Sources */, FEEDD2F32508DFE400DC0A98 /* CoreBoundingBox.swift in Sources */, diff --git a/Sources/MapboxSearch/InternalAPI/CoreAliases.swift b/Sources/MapboxSearch/InternalAPI/CoreAliases.swift index ad1aa541b..1c69bb309 100644 --- a/Sources/MapboxSearch/InternalAPI/CoreAliases.swift +++ b/Sources/MapboxSearch/InternalAPI/CoreAliases.swift @@ -33,6 +33,12 @@ typealias CoreUserActivityReporterOptions = MapboxCoreSearch.UserActivityReporte typealias CoreReverseGeoOptions = MapboxCoreSearch.ReverseGeoOptions +// Offline +typealias CoreOfflineIndexObserver = MapboxCoreSearch.OfflineIndexObserver +typealias CoreOfflineIndexChangeEvent = MapboxCoreSearch.OfflineIndexChangeEvent +typealias CoreOfflineIndexError = MapboxCoreSearch.OfflineIndexError +typealias CoreOfflineIndexChangeEventType = MapboxCoreSearch.OfflineIndexChangeEventType + let mapboxCoreSearchErrorDomain = "MapboxCoreSearchErrorDomain" extension CoreSearchEngine { diff --git a/Sources/MapboxSearch/InternalAPI/CoreSearchEngineProtocol.swift b/Sources/MapboxSearch/InternalAPI/CoreSearchEngineProtocol.swift index 9a398a4c3..198432e1f 100644 --- a/Sources/MapboxSearch/InternalAPI/CoreSearchEngineProtocol.swift +++ b/Sources/MapboxSearch/InternalAPI/CoreSearchEngineProtocol.swift @@ -81,6 +81,10 @@ protocol CoreSearchEngineProtocol { func setTileStore(_ tileStore: MapboxCommon.TileStore, completion: (() -> Void)?) func setTileStore(_ tileStore: MapboxCommon.TileStore) + + func addOfflineIndexObserver(for observer: CoreOfflineIndexObserver) + + func removeOfflineIndexObserver(for observer: CoreOfflineIndexObserver) } extension CoreSearchEngine: CoreSearchEngineProtocol { diff --git a/Sources/MapboxSearch/InternalAPI/Offline/CoreOfflineIndexChangeEventType.swift b/Sources/MapboxSearch/InternalAPI/Offline/CoreOfflineIndexChangeEventType.swift new file mode 100644 index 000000000..0be3ffce2 --- /dev/null +++ b/Sources/MapboxSearch/InternalAPI/Offline/CoreOfflineIndexChangeEventType.swift @@ -0,0 +1,18 @@ +// Copyright © 2024 Mapbox. All rights reserved. + +import Foundation + +extension CoreOfflineIndexChangeEventType: CustomDebugStringConvertible { + public var debugDescription: String { + switch self { + case .added: + return "Added" + case .removed: + return "Removed" + case .updated: + return "Updated" + @unknown default: + return "Unknown" + } + } +} diff --git a/Sources/MapboxSearch/PublicAPI/Offline/OfflineIndexObserver.swift b/Sources/MapboxSearch/PublicAPI/Offline/OfflineIndexObserver.swift new file mode 100644 index 000000000..a2ea14724 --- /dev/null +++ b/Sources/MapboxSearch/PublicAPI/Offline/OfflineIndexObserver.swift @@ -0,0 +1,29 @@ +// Copyright © 2024 Mapbox. All rights reserved. + +import Foundation + +class OfflineIndexObserver: CoreOfflineIndexObserver { + enum Types { + typealias indexChangedBlock = (CoreOfflineIndexChangeEvent) -> Void + typealias errorBlock = (CoreOfflineIndexError) -> Void + } + + private var onIndexChangedBlock: Types.indexChangedBlock + private var onErrorBlock: Types.errorBlock + + init( + onIndexChangedBlock: @escaping Types.indexChangedBlock = { _ in }, + onErrorBlock: @escaping Types.errorBlock = { _ in } + ) { + self.onIndexChangedBlock = onIndexChangedBlock + self.onErrorBlock = onErrorBlock + } + + func onIndexChanged(for event: CoreOfflineIndexChangeEvent) { + onIndexChangedBlock(event) + } + + func onError(forError error: CoreOfflineIndexError) { + onErrorBlock(error) + } +} diff --git a/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift index 1ab179677..1f836bf6c 100644 --- a/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift @@ -57,6 +57,18 @@ class OfflineIntegrationTests: MockServerIntegrationTestCase Date: Mon, 8 Apr 2024 18:10:46 -0400 Subject: [PATCH 12/17] Assign explicit simulated location for Demo app - Clean up code comments around DefaultLocationProvider.locationManager --- MapboxSearch.xcodeproj/xcshareddata/xcschemes/Demo.xcscheme | 2 +- Sources/MapboxSearch/PublicAPI/DefaultLocationProvider.swift | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/MapboxSearch.xcodeproj/xcshareddata/xcschemes/Demo.xcscheme b/MapboxSearch.xcodeproj/xcshareddata/xcschemes/Demo.xcscheme index 80438c09f..fe0ff092e 100644 --- a/MapboxSearch.xcodeproj/xcshareddata/xcschemes/Demo.xcscheme +++ b/MapboxSearch.xcodeproj/xcshareddata/xcschemes/Demo.xcscheme @@ -126,7 +126,7 @@ diff --git a/Sources/MapboxSearch/PublicAPI/DefaultLocationProvider.swift b/Sources/MapboxSearch/PublicAPI/DefaultLocationProvider.swift index 828a9f200..5abc1a0c1 100644 --- a/Sources/MapboxSearch/PublicAPI/DefaultLocationProvider.swift +++ b/Sources/MapboxSearch/PublicAPI/DefaultLocationProvider.swift @@ -5,8 +5,7 @@ import CoreLocation /// Would not trigger Location Permission dialogs but will retrieve permission changes notification. /// Suitable for `SearchEngine` for providing user location by default without additional efforts. public class DefaultLocationProvider { - // not used anywhere as public - /* public */ let locationManager: CLLocationManager + let locationManager: CLLocationManager #if FAST_LOCATION_CHANGES_TRACKING let locationRequestFrequency: TimeInterval = 1 From d76c39842874c4ed888f8c899a634d13abb10e08 Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Tue, 9 Apr 2024 11:57:08 -0400 Subject: [PATCH 13/17] Add Washington, DC GPX location as new default location --- MapboxSearch.xcodeproj/project.pbxproj | 4 ++++ MapboxSearch.xcodeproj/xcshareddata/xcschemes/Demo.xcscheme | 4 ++-- Sources/Demo/WashingtonDC.gpx | 6 ++++++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 Sources/Demo/WashingtonDC.gpx diff --git a/MapboxSearch.xcodeproj/project.pbxproj b/MapboxSearch.xcodeproj/project.pbxproj index b65450aaf..a9cb11bd9 100644 --- a/MapboxSearch.xcodeproj/project.pbxproj +++ b/MapboxSearch.xcodeproj/project.pbxproj @@ -33,6 +33,7 @@ 0477904F2B890F4E00A99528 /* search-box-retrieve-minsk.json in Resources */ = {isa = PBXBuildFile; fileRef = 0477904C2B890F4E00A99528 /* search-box-retrieve-minsk.json */; }; 0484BCDF2BC4865C003CF408 /* OfflineIndexObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0484BCDE2BC4865C003CF408 /* OfflineIndexObserver.swift */; }; 0484BCE22BC49A23003CF408 /* CoreOfflineIndexChangeEventType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0484BCE12BC49A23003CF408 /* CoreOfflineIndexChangeEventType.swift */; }; + 0484BCE92BC589C9003CF408 /* WashingtonDC.gpx in Resources */ = {isa = PBXBuildFile; fileRef = 0484BCE82BC589C9003CF408 /* WashingtonDC.gpx */; }; 048823482B6B0A9D00C770AA /* category-hotel-search-along-route-jp.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B7C2B6B043C00FDE7D5 /* category-hotel-search-along-route-jp.json */; }; 048823492B6B0A9D00C770AA /* category-hotel-search-along-route-jp.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B7C2B6B043C00FDE7D5 /* category-hotel-search-along-route-jp.json */; }; 0488234A2B6B0A9E00C770AA /* category-hotel-search-along-route-jp.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B7C2B6B043C00FDE7D5 /* category-hotel-search-along-route-jp.json */; }; @@ -544,6 +545,7 @@ 0477904C2B890F4E00A99528 /* search-box-retrieve-minsk.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "search-box-retrieve-minsk.json"; sourceTree = ""; }; 0484BCDE2BC4865C003CF408 /* OfflineIndexObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OfflineIndexObserver.swift; sourceTree = ""; }; 0484BCE12BC49A23003CF408 /* CoreOfflineIndexChangeEventType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreOfflineIndexChangeEventType.swift; sourceTree = ""; }; + 0484BCE82BC589C9003CF408 /* WashingtonDC.gpx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = WashingtonDC.gpx; sourceTree = ""; }; 04970F8C2B7A97C900213763 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = ""; }; 04AB0B4A2B6AADB700FDE7D5 /* mapbox.places.san.francisco.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = mapbox.places.san.francisco.json; sourceTree = ""; }; 04AB0B792B6AF37800FDE7D5 /* DiscoverIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiscoverIntegrationTests.swift; sourceTree = ""; }; @@ -1960,6 +1962,7 @@ children = ( FEEDD3B42508E3CD00DC0A98 /* Assets.xcassets */, FEEDD3BC2508E3CD00DC0A98 /* Info.plist */, + 0484BCE82BC589C9003CF408 /* WashingtonDC.gpx */, FEEDD3BA2508E3CD00DC0A98 /* Munich, Germany.gpx */, FEEDD3BD2508E3CD00DC0A98 /* San Carlos, California.gpx */, ); @@ -2334,6 +2337,7 @@ files = ( FEEDD3C12508E3CD00DC0A98 /* Main.storyboard in Resources */, FEEDD3C02508E3CD00DC0A98 /* LaunchScreen.storyboard in Resources */, + 0484BCE92BC589C9003CF408 /* WashingtonDC.gpx in Resources */, FEEDD3BE2508E3CD00DC0A98 /* Assets.xcassets in Resources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/MapboxSearch.xcodeproj/xcshareddata/xcschemes/Demo.xcscheme b/MapboxSearch.xcodeproj/xcshareddata/xcschemes/Demo.xcscheme index fe0ff092e..0581aabc1 100644 --- a/MapboxSearch.xcodeproj/xcshareddata/xcschemes/Demo.xcscheme +++ b/MapboxSearch.xcodeproj/xcshareddata/xcschemes/Demo.xcscheme @@ -126,8 +126,8 @@ + identifier = "../../Sources/Demo/WashingtonDC.gpx" + referenceType = "0"> + + + Washington, D.C. + + From 52da414095f3989b879a3d2fe4a86db196a79b88 Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Tue, 9 Apr 2024 13:08:41 -0400 Subject: [PATCH 14/17] Change offline test query to "coffee", add assertions, remove boundingbox - SSDK-617 --- .../OfflineIntegrationTests.swift | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift index c409b5e94..22189befb 100644 --- a/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift @@ -83,23 +83,21 @@ class OfflineIntegrationTests: MockServerIntegrationTestCase { } loadDataExpectation.fulfill() } - wait(for: [loadDataExpectation], timeout: 200) - wait(for: [indexChangedExpectation], timeout: 200) - - // Providing a bounding box to offline search is recommended to optimize performance - let regionBounds = BoundingBox( - CLLocationCoordinate2D(latitude: 39.0002626, longitude: -76.908646), - CLLocationCoordinate2D(latitude: 38.7911851, longitude: -77.1235559) + wait( + for: [loadDataExpectation, indexChangedExpectation], + timeout: 200, + enforceOrder: true ) - let searchOptions = SearchOptions(boundingBox: regionBounds) let offlineUpdateExpectation = delegate.offlineUpdateExpectation - searchEngine.search(query: "dc", options: searchOptions) + searchEngine.search(query: "coffee") wait(for: [offlineUpdateExpectation], timeout: 10) XCTAssertNil(delegate.error) XCTAssertNil(delegate.error?.localizedDescription) - XCTAssert(searchEngine.suggestions.isEmpty == false) + XCTAssertNotNil(searchEngine.responseInfo) + XCTAssertFalse(delegate.resolvedResults.isEmpty) + XCTAssertFalse(searchEngine.suggestions.isEmpty) } func testNoData() { From 1975e0e9fee90814fe539a88e75483690c67877a Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Tue, 9 Apr 2024 13:33:55 -0400 Subject: [PATCH 15/17] Pare down unnecessary changes from offline test fixes - SSDK-617 --- .circleci/config.yml | 4 ++-- MapboxSearch.xcodeproj/project.pbxproj | 4 ---- .../xcshareddata/swiftpm/Package.resolved | 8 ++++---- .../xcshareddata/xcschemes/Demo.xcscheme | 4 ++-- Sources/Demo/WashingtonDC.gpx | 6 ------ 5 files changed, 8 insertions(+), 18 deletions(-) delete mode 100644 Sources/Demo/WashingtonDC.gpx diff --git a/.circleci/config.yml b/.circleci/config.yml index e7b75a285..f9c9aadf1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -270,11 +270,11 @@ commands: command: | echo "machine api.mapbox.com" >> ~/.netrc echo "login mapbox" >> ~/.netrc - echo "password $SDK_REGISTRY_TOKEN_FULL" >> ~/.netrc + echo "password $SDK_REGISTRY_TOKEN" >> ~/.netrc chmod 0600 ~/.netrc - run: name: Inject Mapbox token - command: echo $SDK_REGISTRY_TOKEN_FULL > ~/.mapbox + command: echo $SDK_REGISTRY_TOKEN > ~/.mapbox ios-install-carthage-dependencies: steps: diff --git a/MapboxSearch.xcodeproj/project.pbxproj b/MapboxSearch.xcodeproj/project.pbxproj index a9cb11bd9..b65450aaf 100644 --- a/MapboxSearch.xcodeproj/project.pbxproj +++ b/MapboxSearch.xcodeproj/project.pbxproj @@ -33,7 +33,6 @@ 0477904F2B890F4E00A99528 /* search-box-retrieve-minsk.json in Resources */ = {isa = PBXBuildFile; fileRef = 0477904C2B890F4E00A99528 /* search-box-retrieve-minsk.json */; }; 0484BCDF2BC4865C003CF408 /* OfflineIndexObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0484BCDE2BC4865C003CF408 /* OfflineIndexObserver.swift */; }; 0484BCE22BC49A23003CF408 /* CoreOfflineIndexChangeEventType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0484BCE12BC49A23003CF408 /* CoreOfflineIndexChangeEventType.swift */; }; - 0484BCE92BC589C9003CF408 /* WashingtonDC.gpx in Resources */ = {isa = PBXBuildFile; fileRef = 0484BCE82BC589C9003CF408 /* WashingtonDC.gpx */; }; 048823482B6B0A9D00C770AA /* category-hotel-search-along-route-jp.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B7C2B6B043C00FDE7D5 /* category-hotel-search-along-route-jp.json */; }; 048823492B6B0A9D00C770AA /* category-hotel-search-along-route-jp.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B7C2B6B043C00FDE7D5 /* category-hotel-search-along-route-jp.json */; }; 0488234A2B6B0A9E00C770AA /* category-hotel-search-along-route-jp.json in Resources */ = {isa = PBXBuildFile; fileRef = 04AB0B7C2B6B043C00FDE7D5 /* category-hotel-search-along-route-jp.json */; }; @@ -545,7 +544,6 @@ 0477904C2B890F4E00A99528 /* search-box-retrieve-minsk.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "search-box-retrieve-minsk.json"; sourceTree = ""; }; 0484BCDE2BC4865C003CF408 /* OfflineIndexObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OfflineIndexObserver.swift; sourceTree = ""; }; 0484BCE12BC49A23003CF408 /* CoreOfflineIndexChangeEventType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreOfflineIndexChangeEventType.swift; sourceTree = ""; }; - 0484BCE82BC589C9003CF408 /* WashingtonDC.gpx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = WashingtonDC.gpx; sourceTree = ""; }; 04970F8C2B7A97C900213763 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = ""; }; 04AB0B4A2B6AADB700FDE7D5 /* mapbox.places.san.francisco.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = mapbox.places.san.francisco.json; sourceTree = ""; }; 04AB0B792B6AF37800FDE7D5 /* DiscoverIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiscoverIntegrationTests.swift; sourceTree = ""; }; @@ -1962,7 +1960,6 @@ children = ( FEEDD3B42508E3CD00DC0A98 /* Assets.xcassets */, FEEDD3BC2508E3CD00DC0A98 /* Info.plist */, - 0484BCE82BC589C9003CF408 /* WashingtonDC.gpx */, FEEDD3BA2508E3CD00DC0A98 /* Munich, Germany.gpx */, FEEDD3BD2508E3CD00DC0A98 /* San Carlos, California.gpx */, ); @@ -2337,7 +2334,6 @@ files = ( FEEDD3C12508E3CD00DC0A98 /* Main.storyboard in Resources */, FEEDD3C02508E3CD00DC0A98 /* LaunchScreen.storyboard in Resources */, - 0484BCE92BC589C9003CF408 /* WashingtonDC.gpx in Resources */, FEEDD3BE2508E3CD00DC0A98 /* Assets.xcassets in Resources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/MapboxSearch.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/MapboxSearch.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 90f494bb5..c3e68929e 100644 --- a/MapboxSearch.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/MapboxSearch.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -5,8 +5,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/mattgallagher/CwlCatchException.git", "state" : { - "revision" : "3ef6999c73b6938cc0da422f2c912d0158abb0a0", - "version" : "2.2.0" + "revision" : "3b123999de19bf04905bc1dfdb76f817b0f2cc00", + "version" : "2.1.2" } }, { @@ -14,8 +14,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/mattgallagher/CwlPreconditionTesting.git", "state" : { - "revision" : "2ef56b2caf25f55fa7eef8784c30d5a767550f54", - "version" : "2.2.1" + "revision" : "a23ded2c91df9156628a6996ab4f347526f17b6b", + "version" : "2.1.2" } }, { diff --git a/MapboxSearch.xcodeproj/xcshareddata/xcschemes/Demo.xcscheme b/MapboxSearch.xcodeproj/xcshareddata/xcschemes/Demo.xcscheme index 0581aabc1..fe0ff092e 100644 --- a/MapboxSearch.xcodeproj/xcshareddata/xcschemes/Demo.xcscheme +++ b/MapboxSearch.xcodeproj/xcshareddata/xcschemes/Demo.xcscheme @@ -126,8 +126,8 @@ + identifier = "San Francisco, CA, USA" + referenceType = "1"> - - - Washington, D.C. - - From 80fd834eb86683ce8655f75e7df4062f4ce580d3 Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Tue, 9 Apr 2024 13:42:14 -0400 Subject: [PATCH 16/17] Add markers to separate tests functions --- .../OfflineIntegrationTests.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift b/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift index 22189befb..200916951 100644 --- a/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift +++ b/Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift @@ -14,6 +14,8 @@ class OfflineIntegrationTests: MockServerIntegrationTestCase { let dcLocation = CLLocationCoordinate2D(latitude: 38.89992081005698, longitude: -77.03399849939174) let regionId = "dc" + // MARK: - Helpers and set up + override func setUpWithError() throws { try super.setUpWithError() @@ -56,6 +58,8 @@ class OfflineIntegrationTests: MockServerIntegrationTestCase { searchEngine.offlineManager.tileStore.removeTileRegion(id: regionId) } + // MARK: - Tests + func testLoadData() throws { clearData() From e6f3e986b346df22185539a52c8924dc0e587590 Mon Sep 17 00:00:00 2001 From: Jack Alto Date: Tue, 9 Apr 2024 13:46:49 -0400 Subject: [PATCH 17/17] Update changelog - SSDK-617 --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) 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."