krz/hutch
an ios client for sourcehut
clone: git clone https://gitbay.org/krz/hutch.git
main: HutchTests/DeepLinkTests.swift · raw
1import Foundation
2import Testing
3@testable import Hutch
4
5@MainActor
6struct DeepLinkTests {
7
8 @Test
9 func parsesHomeLink() {
10 let link = DeepLink(url: HutchDeepLinkURL.home)
11 #expect(link == .home)
12 }
13
14 @Test
15 func parsesNilPathAsHome() {
16 let link = DeepLink(url: HutchDeepLinkURL.emptyHost)
17 #expect(link == .home)
18 }
19
20 @Test
21 func parsesRepositoryLink() {
22 let link = DeepLink(url: HutchDeepLinkURL.repositoryGit)
23 #expect(link == .repository(service: .git, owner: "~user", repo: "repo"))
24 }
25
26 @Test
27 func parsesHgRepositoryLink() {
28 let link = DeepLink(url: HutchDeepLinkURL.repositoryHg)
29 #expect(link == .repository(service: .hg, owner: "~user", repo: "repo"))
30 }
31
32 @Test
33 func parsesServiceOwnerRootAsUserProfile() {
34 let link = DeepLink(url: HutchDeepLinkURL.gitOwnerRoot)
35 #expect(link == .userProfile(owner: "~owner"))
36 }
37
38 @Test
39 func parsesTicketLink() {
40 let link = DeepLink(url: HutchDeepLinkURL.ticket)
41 #expect(link == .ticket(owner: "~owner", tracker: "tracker", ticketId: 42))
42 }
43
44 @Test
45 func parsesBuildJobLink() {
46 let link = DeepLink(url: HutchDeepLinkURL.buildJob)
47 #expect(link == .build(jobId: 12345))
48 }
49
50 @Test
51 func parsesBuildJobLinkWithOwnerPath() {
52 let link = DeepLink(url: HutchDeepLinkURL.buildJobWithOwner)
53 #expect(link == .build(jobId: 12345))
54 }
55
56 @Test
57 func parsesMailingListLink() {
58 let link = DeepLink(url: HutchDeepLinkURL.mailingList)
59 #expect(link == .mailingList(owner: "~owner", list: "list"))
60 }
61
62 @Test
63 func parsesBuildsTabLink() {
64 let link = DeepLink(url: HutchDeepLinkURL.builds)
65 #expect(link == .buildsTab)
66 }
67
68 @Test
69 func parsesRepositoriesTabLink() {
70 let link = DeepLink(url: HutchDeepLinkURL.repositories)
71 #expect(link == .repositoriesTab)
72 }
73
74 @Test
75 func parsesTrackersTabLink() {
76 let link = DeepLink(url: HutchDeepLinkURL.trackers)
77 #expect(link == .trackersTab)
78 }
79
80 @Test
81 func parsesSystemStatusLink() {
82 let link = DeepLink(url: HutchDeepLinkURL.status)
83 #expect(link == .systemStatus)
84 }
85
86 @Test
87 func parsesLookupLink() {
88 let link = DeepLink(url: HutchDeepLinkURL.lookup)
89 #expect(link == .lookup)
90 }
91
92 @Test
93 func parsesRouteBackedNavigationLinks() {
94 #expect(DeepLink(url: HutchRoute.workQueue(scope: .assigned).url) == .workQueue(scope: .assigned))
95 #expect(DeepLink(url: HutchRoute.failedBuilds.url) == .failedBuilds)
96 #expect(DeepLink(url: HutchRoute.search(query: "patch queue", type: nil).url) == .search(query: "patch queue", type: nil))
97 #expect(DeepLink(url: HutchRoute.search(query: "~alice", type: .user).url) == .search(query: "~alice", type: .user))
98 #expect(DeepLink(url: HutchRoute.projectDashboard(id: "project-1", title: "Hutch").url) == .projectDashboard(id: "project-1", title: "Hutch"))
99 }
100
101 @Test
102 func parsesUserProfileLink() {
103 let link = DeepLink(url: HutchDeepLinkURL.userProfile)
104 #expect(link == .userProfile(owner: "~owner"))
105 }
106
107 @Test
108 func rejectsNonHutchScheme() {
109 let link = DeepLink(url: URL(string: "https://example.com/home")!)
110 #expect(link == nil)
111 }
112
113 @Test
114 func rejectsUnknownPath() {
115 let link = DeepLink(url: HutchDeepLinkURL.unknown)
116 #expect(link == nil)
117 }
118
119 @Test
120 func rejectsTicketLinkWithNonNumericId() {
121 let link = DeepLink(url: HutchDeepLinkURL.invalidTicketId)
122 #expect(link == nil)
123 }
124
125 @Test
126 func rejectsBuildLinkWithNonNumericId() {
127 let link = DeepLink(url: HutchDeepLinkURL.invalidBuildId)
128 #expect(link == nil)
129 }
130}