krz/hutch

an ios client for sourcehut

clone: git clone https://gitbay.org/krz/hutch.git

v3.7.0: HutchTests/DeepLinkTests.swift · raw

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