Download this file
| 1 | import Foundation |
| 2 | import RastrilloApple |
| 3 | import XCTest |
| 4 | @testable import SheetsKit |
| 5 | |
| 6 | final class HomeLoadingTests: XCTestCase { |
| 7 | @MainActor func testLoadingSuccessAndFailureAreDistinct() async throws { |
| 8 | guard let origin = ProcessInfo.processInfo.environment["HOME_LOADING_TEST_ORIGIN"] else { |
| 9 | throw XCTSkip("Run the delayed home-list fixture") |
| 10 | } |
| 11 | let model = SheetModel(client: NativeHTTP(origin: URL(string: origin)!)) |
| 12 | XCTAssertEqual(model.listState, .loading) |
| 13 | for expected in [1, 0, -1, 1] { |
| 14 | let request = Task { await model.loadList() } |
| 15 | try await Task.sleep(for: .milliseconds(25)) |
| 16 | XCTAssertEqual(model.listState, .loading, "Never classify an in-flight request as empty") |
| 17 | await request.value |
| 18 | XCTAssertEqual(model.listState, expected == -1 ? .failed : .loaded) |
| 19 | if expected >= 0 { XCTAssertEqual(model.sheets.count, expected) } |
| 20 | } |
| 21 | } |
| 22 | } |
| 23 | |