Skip to content

Commit

Permalink
Test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfej94 committed Mar 18, 2022
1 parent 1e8ca57 commit 02c5632
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
2 changes: 1 addition & 1 deletion AtlasKit.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |spec|

spec.name = "AtlasKit"
spec.version = "0.2.0"
spec.version = "0.2.1"
spec.license = "MIT"
spec.summary = "A swift library for quickly integrating a location search in your app."
spec.homepage = "https://github.com/appoly/AtlasKit"
Expand Down
11 changes: 6 additions & 5 deletions Sources/AtlasKit/AtlasKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class AtlasKit {
/// - completion: Code to be ran when a result is received (Places, Error)
public func performSearchWithDelay(_ term: String, delay: TimeInterval, completion: @escaping (Result<[AtlasKitPlace], AtlasKitError>) -> Void) {
searchTimer?.invalidate()
searchTimer = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: false, block: { [weak self] _ in
searchTimer = Timer.scheduledTimer(withTimeInterval: delay, repeats: false, block: { [weak self] _ in
self?.performSearch(term, completion: completion)
})
}
Expand All @@ -51,10 +51,11 @@ public class AtlasKit {
public func performSearchWithDelay(_ term: String, delay: TimeInterval) async throws -> [AtlasKitPlace] {
searchTimer?.invalidate()
return try await withUnsafeThrowingContinuation { continuation in
searchTimer = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: false, block: { [weak self] _ in

self?.performSearch(term) { continuation.resume(with: $0) }
})
DispatchQueue.main.async { [weak self] in
self?.searchTimer = Timer.scheduledTimer(withTimeInterval: delay, repeats: false, block: { [weak self] _ in
self?.performSearch(term) { continuation.resume(with: $0) }
})
}
}
}

Expand Down
35 changes: 29 additions & 6 deletions UIKitExample/AtlasKitTests/AtlasKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ class AtlasKitTests: XCTestCase {
var error: Error?
var places: [AtlasKitPlace]!

atlas?.performSearch("Test", completion: {
error = $1
places = $0 ?? []
atlas?.performSearch("Test", completion: { result in
switch result {
case .success(let values):
places = values
case .failure(let err):
error = err
}
expectation.fulfill()
})

Expand All @@ -52,15 +56,27 @@ class AtlasKitTests: XCTestCase {
XCTAssertTrue(places.count > 0)
}
}


func testAsyncSearch() async throws {
guard let atlas = atlas else { XCTFail(); return }
let places = try await atlas.performSearch("Test")
XCTAssertTrue(places.count > 0)
}


func testSearchWithDelay() throws {
let expectation = self.expectation(description: "search_complete")
var error: Error?
var places: [AtlasKitPlace]!

atlas?.performSearchWithDelay("Test", delay: 2, completion: {
error = $1
places = $0 ?? []
atlas?.performSearchWithDelay("Test", delay: 2, completion: { result in
switch result {
case .success(let values):
places = values
case .failure(let err):
error = err
}
expectation.fulfill()
})

Expand All @@ -72,5 +88,12 @@ class AtlasKitTests: XCTestCase {
XCTAssertTrue(places.count > 0)
}
}


func testAsyncSearchWithDelay() async throws {
guard let atlas = atlas else { XCTFail(); return }
let places = try await atlas.performSearchWithDelay("Test", delay: 2.0)
XCTAssertTrue(places.count > 0)
}

}

0 comments on commit 02c5632

Please sign in to comment.