Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SSDK-617] Fix offline tests #199

Merged
merged 20 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
de9912b
Enable offline tests - SSDK-617
aokj4ck Mar 25, 2024
06e0d32
Update to NSValue(mkCoordinate: CLLocationCoordinate2D) for offline d…
aokj4ck Mar 26, 2024
8c7e327
Update offline dataset to mbx-main - SSDK-617
aokj4ck Mar 26, 2024
202cf10
Remove unused reference to dataset in Offline tests - SSDK-617
aokj4ck Mar 26, 2024
520aa18
Add test search engine delegate stub for offline tests
aokj4ck Mar 26, 2024
93a0144
Fold Search engine offline stub into main stub, do not need two - SSD…
aokj4ck Mar 26, 2024
1563004
Add bounding box to offline search test - SSDK-617
aokj4ck Mar 27, 2024
051e79e
Fix typo in notification name - SSDK-617
aokj4ck Mar 27, 2024
5ba4b6d
Try out alternate token to triage issues - SSDK-617
aokj4ck Mar 28, 2024
f28987f
Require MapboxCommon 24.2.0+ for offline search - SSDK-617
aokj4ck Apr 3, 2024
9252eb1
Merge branch 'main' of github.com:mapbox/mapbox-search-ios into SSDK-…
aokj4ck Apr 3, 2024
f4231fc
Add OfflineIndexObserver for insight to Offline state
aokj4ck Apr 8, 2024
6120139
Assign explicit simulated location for Demo app
aokj4ck Apr 8, 2024
5a2a5a8
Merge branch 'add-OfflineIndexObserver' into SSDK-617-fix-offline-tes…
aokj4ck Apr 9, 2024
d76c398
Add Washington, DC GPX location as new default location
aokj4ck Apr 9, 2024
52da414
Change offline test query to "coffee", add assertions, remove boundin…
aokj4ck Apr 9, 2024
df953fc
Merge branch 'main' of github.com:mapbox/mapbox-search-ios into SSDK-…
aokj4ck Apr 9, 2024
1975e0e
Pare down unnecessary changes from offline test fixes - SSDK-617
aokj4ck Apr 9, 2024
80fd834
Add markers to separate tests functions
aokj4ck Apr 9, 2024
e6f3e98
Update changelog - SSDK-617
aokj4ck Apr 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 6 additions & 1 deletion Sources/Demo/MapRootController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions Tests/Demo.xctestplan
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
"testTargets" : [
{
"skippedTests" : [
"MockServerIntegrationTestCase",
"OfflineIntegrationTests"
"MockServerIntegrationTestCase"
],
"target" : {
"containerPath" : "container:MapboxSearch.xcodeproj",
Expand Down
37 changes: 25 additions & 12 deletions Tests/MapboxSearchIntegrationTests/OfflineIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)
Expand All @@ -54,6 +58,8 @@ class OfflineIntegrationTests: MockServerIntegrationTestCase<GeocodingMockRespon
searchEngine.offlineManager.tileStore.removeTileRegion(id: regionId)
}

// MARK: - Tests

func testLoadData() throws {
clearData()

Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
}
}