From ba5b12ce54d3d03d63d8f43b6fb1d76ffe7de432 Mon Sep 17 00:00:00 2001 From: Balazs Perlaki-Horvath Date: Sun, 13 Jul 2025 18:02:32 +0200 Subject: [PATCH] Fix macOS CI tests --- Tests/LibraryRefreshViewModelTest.swift | 6 +++++- ViewModel/LibraryViewModel.swift | 4 ++-- Views/BuildingBlocks/ZimFileCell.swift | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Tests/LibraryRefreshViewModelTest.swift b/Tests/LibraryRefreshViewModelTest.swift index ef3c388f..9592cdd1 100644 --- a/Tests/LibraryRefreshViewModelTest.swift +++ b/Tests/LibraryRefreshViewModelTest.swift @@ -21,12 +21,14 @@ import Combine @testable import Kiwix private class HTTPTestingURLProtocol: URLProtocol { + @MainActor static var handler: ((URLProtocol) -> Void)? override class func canInit(with request: URLRequest) -> Bool { true } override class func canonicalRequest(for request: URLRequest) -> URLRequest { request } override func stopLoading() { } + @MainActor override func startLoading() { if let handler = HTTPTestingURLProtocol.handler { handler(self) @@ -37,9 +39,10 @@ private class HTTPTestingURLProtocol: URLProtocol { } final class LibraryRefreshViewModelTest: XCTestCase { - private var urlSession: URLSession? + private var urlSession: URLSession! private var cancellables = Set() + @MainActor override func setUpWithError() throws { let config = URLSessionConfiguration.ephemeral config.protocolClasses = [HTTPTestingURLProtocol.self] @@ -57,6 +60,7 @@ final class LibraryRefreshViewModelTest: XCTestCase { } } + @MainActor override func tearDownWithError() throws { HTTPTestingURLProtocol.handler = nil } diff --git a/ViewModel/LibraryViewModel.swift b/ViewModel/LibraryViewModel.swift index 20e251b7..d91b8ab4 100644 --- a/ViewModel/LibraryViewModel.swift +++ b/ViewModel/LibraryViewModel.swift @@ -103,12 +103,12 @@ final class LibraryViewModel: ObservableObject { @MainActor init( - urlSession: URLSession? = nil, + urlSession: URLSession = URLSession.shared, processFactory: @MainActor () -> LibraryProcess = { .shared }, defaults: Defaulting = UDefaults(), categories: CategoriesProtocol = CategoriesToLanguages(withDefaults: UDefaults()) ) { - self.urlSession = urlSession ?? URLSession.shared + self.urlSession = urlSession self.process = processFactory() self.defaults = defaults self.categories = categories diff --git a/Views/BuildingBlocks/ZimFileCell.swift b/Views/BuildingBlocks/ZimFileCell.swift index ab37a5a6..64e7515e 100644 --- a/Views/BuildingBlocks/ZimFileCell.swift +++ b/Views/BuildingBlocks/ZimFileCell.swift @@ -17,7 +17,7 @@ import CoreData import SwiftUI struct ZimFileCell: View { - @ObservedObject var zimFile: ZimFile + @MainActor @ObservedObject var zimFile: ZimFile @State private var isHovering: Bool = false let isLoading: Bool let isSelected: Bool