75 lines
2.3 KiB
Swift
75 lines
2.3 KiB
Swift
//
|
|
// LocationPickerTests.swift
|
|
// AutoCatTests
|
|
//
|
|
// Created by Selim Mustafaev on 10.08.2024.
|
|
// Copyright © 2024 Selim Mustafaev. All rights reserved.
|
|
//
|
|
|
|
import Testing
|
|
import CoreLocation
|
|
import Mockable
|
|
import Intents
|
|
import Contacts
|
|
|
|
@testable import AutoCat
|
|
@testable import AutoCatCore
|
|
|
|
@MainActor
|
|
struct LocationPickerTests {
|
|
|
|
let latitude: CLLocationDegrees = 10
|
|
let longitude: CLLocationDegrees = 10
|
|
let address = "Test Address"
|
|
|
|
let geocoderMock = MockGeocoderProtocol()
|
|
|
|
func makeViewModel(event: VehicleEventDto) -> LocationPickerViewModel {
|
|
|
|
let locationService = LocationService(
|
|
geocoder: geocoderMock,
|
|
locationManager: MockSwiftLocationProtocol(),
|
|
settingsService: MockSettingsServiceProtocol()
|
|
)
|
|
|
|
return LocationPickerViewModel(locationService: locationService,
|
|
event: event)
|
|
}
|
|
|
|
@Test("Set initial location (user)")
|
|
func setInitialLocationUser() async throws {
|
|
|
|
let viewModel = makeViewModel(event: .init(lat: 0, lon: 0, addedBy: nil))
|
|
|
|
#expect(viewModel.position == .userLocation(fallback: .automatic))
|
|
}
|
|
|
|
@Test("Set initial location (custom)")
|
|
func setInitialLocationCustom() async throws {
|
|
|
|
let viewModel = makeViewModel(event: .init(lat: latitude, lon: longitude, addedBy: nil))
|
|
|
|
#expect(viewModel.position.region?.center.latitude == latitude)
|
|
#expect(viewModel.position.region?.center.longitude == longitude)
|
|
}
|
|
|
|
@Test("Update event")
|
|
func updateEvent() async throws {
|
|
|
|
let viewModel = makeViewModel(event: .init(lat: 0, lon: 0, addedBy: nil))
|
|
|
|
let location = CLLocation(latitude: latitude, longitude: longitude)
|
|
let placemark = CLPlacemark(location: location, name: address, postalAddress: nil)
|
|
|
|
given(geocoderMock)
|
|
.reverseGeocodeLocation(.any)
|
|
.willReturn([placemark])
|
|
|
|
await viewModel.updateEvent(center: .init(latitude: latitude, longitude: longitude))
|
|
|
|
#expect(viewModel.event.latitude == latitude)
|
|
#expect(viewModel.event.longitude == longitude)
|
|
#expect(viewModel.event.address == address)
|
|
}
|
|
}
|