From bfd97877d31c9890168ad25dbb98073ff1258155 Mon Sep 17 00:00:00 2001 From: Selim Mustafaev Date: Mon, 17 Feb 2025 10:44:51 +0300 Subject: [PATCH] More test for history screen --- AutoCatTests/HistoryTests.swift | 44 +++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/AutoCatTests/HistoryTests.swift b/AutoCatTests/HistoryTests.swift index eb1ffca..1a525fd 100644 --- a/AutoCatTests/HistoryTests.swift +++ b/AutoCatTests/HistoryTests.swift @@ -174,4 +174,48 @@ struct HistoryTests { #expect(viewModel.vehiclesFiltered.count == 1) #expect(viewModel.vehicles.first?.notes.first?.text == "123") } + + @Test("History (error deleting)") + func historyErrorDeleting() async { + + given(storageServiceMock) + .loadVehicles() + .willReturn([.normal]) + + given(storageServiceMock) + .dbFileURL + .willReturn(nil) + + given(storageServiceMock) + .deleteVehicle(number: .any) + .willThrow(TestError.generic) + + await viewModel.onAppear() + await viewModel.deleteVehicle(.normal) + + #expect(viewModel.vehicles.count == 1) + #expect(viewModel.vehiclesFiltered.count == 1) + #expect(viewModel.hud == .error(TestError.generic)) + } + + @Test("History (error updating)") + func historyErrorUpdating() async { + + given(storageServiceMock) + .loadVehicles() + .willReturn([.normal]) + + given(storageServiceMock) + .dbFileURL + .willReturn(nil) + + given(vehicleServiceMock) + .updateHistory(number: .any) + .willThrow(TestError.generic) + + await viewModel.onAppear() + await viewModel.updateVehicle(.normal) + + #expect(viewModel.hud == .error(TestError.generic)) + } }