mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +00:00
Use the Emoji/Map/Poll view models. (#4458)
* Toggle emojis in the EmojiPickerScreenViewModel. * Send locations in the StaticLocationScreen. * Send polls in the PollFormScreen.
This commit is contained in:
@@ -12,18 +12,20 @@ import XCTest
|
||||
|
||||
@MainActor
|
||||
class StaticLocationScreenViewModelTests: XCTestCase {
|
||||
let timelineProxy = TimelineProxyMock(.init())
|
||||
|
||||
var viewModel: StaticLocationScreenViewModelProtocol!
|
||||
var context: StaticLocationScreenViewModel.Context { viewModel.context }
|
||||
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
|
||||
var context: StaticLocationScreenViewModel.Context {
|
||||
viewModel.context
|
||||
}
|
||||
|
||||
override func setUpWithError() throws {
|
||||
cancellables.removeAll()
|
||||
let viewModel = StaticLocationScreenViewModel(interactionMode: .picker,
|
||||
mapURLBuilder: ServiceLocator.shared.settings.mapTilerConfiguration)
|
||||
mapURLBuilder: ServiceLocator.shared.settings.mapTilerConfiguration,
|
||||
timelineController: MockTimelineController(timelineProxy: timelineProxy),
|
||||
analytics: ServiceLocator.shared.analytics,
|
||||
userIndicatorController: UserIndicatorControllerMock())
|
||||
viewModel.state.bindings.isLocationAuthorized = true
|
||||
self.viewModel = viewModel
|
||||
}
|
||||
@@ -73,22 +75,18 @@ class StaticLocationScreenViewModelTests: XCTestCase {
|
||||
context.mapCenterLocation = .init(latitude: 0, longitude: 0)
|
||||
context.geolocationUncertainty = 10
|
||||
|
||||
let deferred = deferFulfillment(viewModel.actions) { action in
|
||||
switch action {
|
||||
case .sendLocation:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
let deferred = deferFulfillment(viewModel.actions) { $0 == .close }
|
||||
let expectation = XCTestExpectation(description: "sendLocation")
|
||||
timelineProxy.sendLocationBodyGeoURIDescriptionZoomLevelAssetTypeClosure = { _, geoURI, _, _, assetType in
|
||||
XCTAssertEqual(geoURI.uncertainty, 10)
|
||||
XCTAssertEqual(assetType, .sender)
|
||||
expectation.fulfill()
|
||||
return .success(())
|
||||
}
|
||||
|
||||
context.send(viewAction: .selectLocation)
|
||||
guard case .sendLocation(let geoUri, let isUserLocation) = try await deferred.fulfill() else {
|
||||
XCTFail("Sent action should be 'sendLocation'")
|
||||
return
|
||||
}
|
||||
XCTAssertEqual(geoUri.uncertainty, 10)
|
||||
XCTAssertTrue(isUserLocation)
|
||||
await fulfillment(of: [expectation], timeout: 1)
|
||||
try await deferred.fulfill()
|
||||
}
|
||||
|
||||
func testSendPickedLocation() async throws {
|
||||
@@ -96,21 +94,17 @@ class StaticLocationScreenViewModelTests: XCTestCase {
|
||||
context.isLocationAuthorized = nil
|
||||
context.geolocationUncertainty = 10
|
||||
|
||||
let deferred = deferFulfillment(viewModel.actions) { action in
|
||||
switch action {
|
||||
case .sendLocation:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
let deferred = deferFulfillment(viewModel.actions) { $0 == .close }
|
||||
let expectation = XCTestExpectation(description: "sendLocation")
|
||||
timelineProxy.sendLocationBodyGeoURIDescriptionZoomLevelAssetTypeClosure = { _, geoURI, _, _, assetType in
|
||||
XCTAssertEqual(geoURI.uncertainty, nil)
|
||||
XCTAssertEqual(assetType, .pin)
|
||||
expectation.fulfill()
|
||||
return .success(())
|
||||
}
|
||||
|
||||
context.send(viewAction: .selectLocation)
|
||||
guard case .sendLocation(let geoUri, let isUserLocation) = try await deferred.fulfill() else {
|
||||
XCTFail("Sent action should be 'sendLocation'")
|
||||
return
|
||||
}
|
||||
XCTAssertEqual(geoUri.uncertainty, nil)
|
||||
XCTAssertFalse(isUserLocation)
|
||||
await fulfillment(of: [expectation], timeout: 1)
|
||||
try await deferred.fulfill()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user