krz/hutch
an ios client for sourcehut
clone: git clone https://gitbay.org/krz/hutch.git
v2.16.0: HutchTests/AppStateTests.swift · raw
1import Testing
2@testable import Hutch
3
4struct AppStateTests {
5
6 @Test
7 @MainActor
8 func presentRepositoryDeepLinkErrorSetsUserFacingMessage() {
9 let appState = AppState()
10
11 appState.presentRepositoryDeepLinkError()
12
13 #expect(appState.deepLinkError == "The repository could not be found or is inaccessible.")
14 }
15
16 @Test
17 @MainActor
18 func presentTicketDeepLinkErrorSetsUserFacingMessage() {
19 let appState = AppState()
20
21 appState.presentTicketDeepLinkError()
22
23 #expect(appState.deepLinkError == "The ticket could not be found or is inaccessible.")
24 }
25
26 @Test
27 @MainActor
28 func openSystemStatusSelectsMoreTabAndQueuesNavigation() {
29 let appState = AppState()
30
31 appState.openSystemStatus()
32
33 #expect(appState.selectedTab == .more)
34 #expect(appState.pendingTabNavigation == .systemStatus)
35 }
36
37 @Test
38 @MainActor
39 func navigationHelpersQueueExpectedTargets() {
40 let appState = AppState()
41 let repository = RepositorySummary(
42 id: 1,
43 rid: "repo",
44 service: .git,
45 name: "hutch",
46 description: nil,
47 visibility: .public,
48 updated: .distantPast,
49 owner: Entity(canonicalName: "~owner"),
50 head: nil
51 )
52 let tracker = TrackerSummary(
53 id: 2,
54 rid: "tracker",
55 name: "todo",
56 description: nil,
57 visibility: .public,
58 updated: .distantPast,
59 owner: Entity(canonicalName: "~owner")
60 )
61
62 appState.navigateToRepository(repository)
63 #expect(appState.selectedTab == .repositories)
64 #expect(appState.pendingTabNavigation == .repository(repository))
65
66 appState.navigateToTracker(tracker)
67 #expect(appState.selectedTab == .tickets)
68 #expect(appState.pendingTabNavigation == .tracker(tracker))
69
70 appState.navigateToBuild(jobId: 42)
71 #expect(appState.selectedTab == .builds)
72 #expect(appState.pendingDeepLink == .build(jobId: 42))
73
74 appState.navigateToTicket(ownerUsername: "owner", trackerName: "todo", ticketId: 9)
75 #expect(appState.selectedTab == .tickets)
76 #expect(appState.pendingDeepLink == .ticket(owner: "owner", tracker: "todo", ticketId: 9))
77 }
78}