Fix tabbar
This commit is contained in:
parent
c8d7279fd1
commit
f3a09e3500
@ -24,20 +24,28 @@ class MainTabController: UITabBarController, UITabBarControllerDelegate {
|
||||
traitOverrides.horizontalSizeClass = .compact
|
||||
}
|
||||
|
||||
setupHistoryTab()
|
||||
addHistoryTab()
|
||||
addDummyTab()
|
||||
Task { await addSettings() }
|
||||
}
|
||||
|
||||
func setupHistoryTab() {
|
||||
func addHistoryTab() {
|
||||
|
||||
let coordinator = HistoryCoordinator()
|
||||
let (controller, viewModel) = coordinator.start()
|
||||
controller.tabBarItem = UITabBarItem(title: NSLocalizedString("History", comment: ""),
|
||||
image: UIImage(systemName: "clock.arrow.circlepath"), tag: 0)
|
||||
viewControllers?[0] = controller
|
||||
viewControllers?.insert(controller, at: 0)
|
||||
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 {
|
||||
|
||||
let coordinator = SettingsCoordinator(tabController: self)
|
||||
|
||||
@ -21,10 +21,11 @@ final class HistoryCoordinator {
|
||||
let viewModel = HistoryViewModel(
|
||||
apiService: resolver.resolve(ApiServiceProtocol.self),
|
||||
storageService: resolver.resolve(StorageServiceProtocol.self),
|
||||
vehicleService: resolver.resolve(VehicleServiceProtocol.self),
|
||||
coordinator: self
|
||||
vehicleService: resolver.resolve(VehicleServiceProtocol.self)
|
||||
)
|
||||
|
||||
viewModel.coordinator = self
|
||||
|
||||
let view = HistoryScreen(viewModel: viewModel)
|
||||
let controller = UIHostingController(rootView: view)
|
||||
|
||||
|
||||
@ -34,6 +34,9 @@ struct HistoryScreen: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
Task { await viewModel.onAppear() }
|
||||
}
|
||||
.hud($viewModel.hud)
|
||||
.listStyle(.plain)
|
||||
.navigationTitle(String.localizedStringWithFormat(NSLocalizedString("vehicles found", comment: ""),
|
||||
|
||||
@ -16,7 +16,7 @@ final class HistoryViewModel: ACHudContainer {
|
||||
let apiService: ApiServiceProtocol
|
||||
let storageService: StorageServiceProtocol
|
||||
let vehicleService: VehicleServiceProtocol
|
||||
let coordinator: HistoryCoordinator?
|
||||
var coordinator: HistoryCoordinator?
|
||||
|
||||
var hud: ACHud?
|
||||
|
||||
@ -46,16 +46,20 @@ final class HistoryViewModel: ACHudContainer {
|
||||
|
||||
init(apiService: ApiServiceProtocol,
|
||||
storageService: StorageServiceProtocol,
|
||||
vehicleService: VehicleServiceProtocol,
|
||||
coordinator: HistoryCoordinator) {
|
||||
vehicleService: VehicleServiceProtocol) {
|
||||
|
||||
self.apiService = apiService
|
||||
self.storageService = storageService
|
||||
self.vehicleService = vehicleService
|
||||
self.coordinator = coordinator
|
||||
}
|
||||
|
||||
Task { await loadVehicles() }
|
||||
Task { dbFileURL = await storageService.dbFileURL }
|
||||
func onAppear() async {
|
||||
|
||||
async let loadTask: () = loadVehicles()
|
||||
async let dbUrlTask = storageService.dbFileURL
|
||||
|
||||
await loadTask
|
||||
dbFileURL = await dbUrlTask
|
||||
}
|
||||
|
||||
func loadVehicles() async {
|
||||
|
||||
@ -6,6 +6,9 @@
|
||||
// Copyright © 2025 Selim Mustafaev. All rights reserved.
|
||||
//
|
||||
|
||||
import Mockable
|
||||
|
||||
@Mockable
|
||||
public protocol VehicleServiceProtocol: Sendable {
|
||||
|
||||
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