64 lines
2.0 KiB
Swift
64 lines
2.0 KiB
Swift
//
|
|
// LocationPickerTests.swift
|
|
// AutoCatTests
|
|
//
|
|
// Created by Selim Mustafaev on 10.08.2024.
|
|
// Copyright © 2024 Selim Mustafaev. All rights reserved.
|
|
//
|
|
|
|
import Testing
|
|
import CoreLocation
|
|
|
|
@testable import AutoCat
|
|
@testable import AutoCatCore
|
|
|
|
@MainActor
|
|
struct LocationPickerTests {
|
|
|
|
let latitude: CLLocationDegrees = 10
|
|
let longitude: CLLocationDegrees = 10
|
|
let address = "Test Address"
|
|
|
|
let geocoder = GeocoderMock()
|
|
|
|
init() {
|
|
|
|
ServiceContainer.shared.register(GeocoderProtocol.self, instance: geocoder)
|
|
ServiceContainer.shared.register(SwiftLocationProtocol.self, instance: SwiftLocationMock())
|
|
ServiceContainer.shared.register(LocationServiceProtocol.self, instance: LocationService())
|
|
}
|
|
|
|
@Test("Set initial location (user)")
|
|
func setInitialLocationUser() async throws {
|
|
|
|
let viewModel = LocationPickerViewModel(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 = LocationPickerViewModel(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 = LocationPickerViewModel(event: .init(lat: 0, lon: 0, addedBy: nil))
|
|
|
|
geocoder.addLocation(latitude: latitude,
|
|
longitude: longitude,
|
|
address: address)
|
|
|
|
await viewModel.updateEvent(center: .init(latitude: latitude, longitude: longitude))
|
|
|
|
#expect(viewModel.event.latitude == latitude)
|
|
#expect(viewModel.event.longitude == longitude)
|
|
#expect(viewModel.event.address == address)
|
|
}
|
|
}
|