krz/hutch

an ios client for sourcehut

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

v3.4.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 parsesUserProfileLink() {
 93        let link = DeepLink(url: HutchDeepLinkURL.userProfile)
 94        #expect(link == .userProfile(owner: "~owner"))
 95    }
 96
 97    @Test
 98    func rejectsNonHutchScheme() {
 99        let link = DeepLink(url: URL(string: "https://example.com/home")!)
100        #expect(link == nil)
101    }
102
103    @Test
104    func rejectsUnknownPath() {
105        let link = DeepLink(url: HutchDeepLinkURL.unknown)
106        #expect(link == nil)
107    }
108
109    @Test
110    func rejectsTicketLinkWithNonNumericId() {
111        let link = DeepLink(url: HutchDeepLinkURL.invalidTicketId)
112        #expect(link == nil)
113    }
114
115    @Test
116    func rejectsBuildLinkWithNonNumericId() {
117        let link = DeepLink(url: HutchDeepLinkURL.invalidBuildId)
118        #expect(link == nil)
119    }
120}