Fix tabbar
This commit is contained in:
parent
c8d7279fd1
commit
f3a09e3500
@ -24,20 +24,28 @@ class MainTabController: UITabBarController, UITabBarControllerDelegate {
|
|||||||
traitOverrides.horizontalSizeClass = .compact
|
traitOverrides.horizontalSizeClass = .compact
|
||||||
}
|
}
|
||||||
|
|
||||||
setupHistoryTab()
|
addHistoryTab()
|
||||||
|
addDummyTab()
|
||||||
Task { await addSettings() }
|
Task { await addSettings() }
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupHistoryTab() {
|
func addHistoryTab() {
|
||||||
|
|
||||||
let coordinator = HistoryCoordinator()
|
let coordinator = HistoryCoordinator()
|
||||||
let (controller, viewModel) = coordinator.start()
|
let (controller, viewModel) = coordinator.start()
|
||||||
controller.tabBarItem = UITabBarItem(title: NSLocalizedString("History", comment: ""),
|
controller.tabBarItem = UITabBarItem(title: NSLocalizedString("History", comment: ""),
|
||||||
image: UIImage(systemName: "clock.arrow.circlepath"), tag: 0)
|
image: UIImage(systemName: "clock.arrow.circlepath"), tag: 0)
|
||||||
viewControllers?[0] = controller
|
viewControllers?.insert(controller, at: 0)
|
||||||
historyViewModel = viewModel
|
historyViewModel = viewModel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func addDummyTab() {
|
||||||
|
|
||||||
|
let controller = DummyNewController()
|
||||||
|
controller.tabBarItem = UITabBarItem(title: "", image: UIImage(systemName: "plus"), tag: 0)
|
||||||
|
viewControllers?.insert(controller, at: 2)
|
||||||
|
}
|
||||||
|
|
||||||
func addSettings() async {
|
func addSettings() async {
|
||||||
|
|
||||||
let coordinator = SettingsCoordinator(tabController: self)
|
let coordinator = SettingsCoordinator(tabController: self)
|
||||||
|
|||||||
@ -21,10 +21,11 @@ final class HistoryCoordinator {
|
|||||||
let viewModel = HistoryViewModel(
|
let viewModel = HistoryViewModel(
|
||||||
apiService: resolver.resolve(ApiServiceProtocol.self),
|
apiService: resolver.resolve(ApiServiceProtocol.self),
|
||||||
storageService: resolver.resolve(StorageServiceProtocol.self),
|
storageService: resolver.resolve(StorageServiceProtocol.self),
|
||||||
vehicleService: resolver.resolve(VehicleServiceProtocol.self),
|
vehicleService: resolver.resolve(VehicleServiceProtocol.self)
|
||||||
coordinator: self
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
viewModel.coordinator = self
|
||||||
|
|
||||||
let view = HistoryScreen(viewModel: viewModel)
|
let view = HistoryScreen(viewModel: viewModel)
|
||||||
let controller = UIHostingController(rootView: view)
|
let controller = UIHostingController(rootView: view)
|
||||||
|
|
||||||
|
|||||||
@ -34,6 +34,9 @@ struct HistoryScreen: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.onAppear {
|
||||||
|
Task { await viewModel.onAppear() }
|
||||||
|
}
|
||||||
.hud($viewModel.hud)
|
.hud($viewModel.hud)
|
||||||
.listStyle(.plain)
|
.listStyle(.plain)
|
||||||
.navigationTitle(String.localizedStringWithFormat(NSLocalizedString("vehicles found", comment: ""),
|
.navigationTitle(String.localizedStringWithFormat(NSLocalizedString("vehicles found", comment: ""),
|
||||||
|
|||||||
@ -16,7 +16,7 @@ final class HistoryViewModel: ACHudContainer {
|
|||||||
let apiService: ApiServiceProtocol
|
let apiService: ApiServiceProtocol
|
||||||
let storageService: StorageServiceProtocol
|
let storageService: StorageServiceProtocol
|
||||||
let vehicleService: VehicleServiceProtocol
|
let vehicleService: VehicleServiceProtocol
|
||||||
let coordinator: HistoryCoordinator?
|
var coordinator: HistoryCoordinator?
|
||||||
|
|
||||||
var hud: ACHud?
|
var hud: ACHud?
|
||||||
|
|
||||||
@ -46,16 +46,20 @@ final class HistoryViewModel: ACHudContainer {
|
|||||||
|
|
||||||
init(apiService: ApiServiceProtocol,
|
init(apiService: ApiServiceProtocol,
|
||||||
storageService: StorageServiceProtocol,
|
storageService: StorageServiceProtocol,
|
||||||
vehicleService: VehicleServiceProtocol,
|
vehicleService: VehicleServiceProtocol) {
|
||||||
coordinator: HistoryCoordinator) {
|
|
||||||
|
|
||||||
self.apiService = apiService
|
self.apiService = apiService
|
||||||
self.storageService = storageService
|
self.storageService = storageService
|
||||||
self.vehicleService = vehicleService
|
self.vehicleService = vehicleService
|
||||||
self.coordinator = coordinator
|
}
|
||||||
|
|
||||||
|
func onAppear() async {
|
||||||
|
|
||||||
Task { await loadVehicles() }
|
async let loadTask: () = loadVehicles()
|
||||||
Task { dbFileURL = await storageService.dbFileURL }
|
async let dbUrlTask = storageService.dbFileURL
|
||||||
|
|
||||||
|
await loadTask
|
||||||
|
dbFileURL = await dbUrlTask
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadVehicles() async {
|
func loadVehicles() async {
|
||||||
|
|||||||
@ -6,6 +6,9 @@
|
|||||||
// Copyright © 2025 Selim Mustafaev. All rights reserved.
|
// Copyright © 2025 Selim Mustafaev. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
import Mockable
|
||||||
|
|
||||||
|
@Mockable
|
||||||
public protocol VehicleServiceProtocol: Sendable {
|
public protocol VehicleServiceProtocol: Sendable {
|
||||||
|
|
||||||
func check(number: String) async throws -> VehicleWithErrors
|
func check(number: String) async throws -> VehicleWithErrors
|
||||||
|
|||||||
58
AutoCatTests/HistoryTests.swift
Normal file
58
AutoCatTests/HistoryTests.swift
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
//
|
||||||
|
// HistoryTests.swift
|
||||||
|
// AutoCatTests
|
||||||
|
//
|
||||||
|
// Created by Selim Mustafaev on 09.02.2025.
|
||||||
|
// Copyright © 2025 Selim Mustafaev. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Testing
|
||||||
|
import Mockable
|
||||||
|
import AutoCatCore
|
||||||
|
@testable import AutoCat
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
struct HistoryTests {
|
||||||
|
|
||||||
|
var storageServiceMock: MockStorageServiceProtocol
|
||||||
|
var apiServiceMock: MockApiServiceProtocol
|
||||||
|
var vehicleServiceMock: MockVehicleServiceProtocol
|
||||||
|
|
||||||
|
var viewModel: HistoryViewModel
|
||||||
|
|
||||||
|
init() async {
|
||||||
|
|
||||||
|
storageServiceMock = MockStorageServiceProtocol()
|
||||||
|
apiServiceMock = MockApiServiceProtocol()
|
||||||
|
vehicleServiceMock = MockVehicleServiceProtocol()
|
||||||
|
|
||||||
|
viewModel = HistoryViewModel(
|
||||||
|
apiService: apiServiceMock,
|
||||||
|
storageService: storageServiceMock,
|
||||||
|
vehicleService: vehicleServiceMock
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func test() async throws {
|
||||||
|
|
||||||
|
let dbURL = URL(fileURLWithPath: "testDbUrl")
|
||||||
|
|
||||||
|
given(storageServiceMock)
|
||||||
|
.loadVehicles()
|
||||||
|
.willReturn([.normal])
|
||||||
|
|
||||||
|
given(storageServiceMock)
|
||||||
|
.dbFileURL
|
||||||
|
.willReturn(dbURL)
|
||||||
|
|
||||||
|
await viewModel.onAppear()
|
||||||
|
|
||||||
|
#expect(viewModel.vehicles == [.normal])
|
||||||
|
#expect(viewModel.vehiclesFiltered == [.normal])
|
||||||
|
#expect(viewModel.vehicleSections.count == 1)
|
||||||
|
#expect(viewModel.dbFileURL == dbURL)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user