Skip to content

Commit

Permalink
[SSDK-617] Fix offline tests (#199)
Browse files Browse the repository at this point in the history
### Description
Fixes [SSDK-617](https://mapbox.atlassian.net/browse/SSDK-617)

- [Offline] Change default tileset name to `mbx-main`
- [Tests] Fix Offline tests and re-enable.
    - This fix depends on the earlier PR #206 to add OfflineIndexObserver
- [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.

### Checklist
- [x] Update `CHANGELOG`
  • Loading branch information
aokj4ck authored Apr 9, 2024
1 parent aa07728 commit 2ada7a4
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 44 deletions.
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)
}
}

0 comments on commit 2ada7a4

Please sign in to comment.