summaryrefslogtreecommitdiff
path: root/HutchTests/DeepLinkTests.swift
blob: 12f759bb41fc434db30e963693d854f8e779214d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import Foundation
import Testing
@testable import Hutch

struct DeepLinkTests {

    @Test
    func parsesHomeLink() {
        let link = DeepLink(url: URL(string: "hutch://home")!)
        #expect(link == .home)
    }

    @Test
    func parsesNilPathAsHome() {
        let link = DeepLink(url: URL(string: "hutch://")!)
        #expect(link == .home)
    }

    @Test
    func parsesRepositoryLink() {
        let link = DeepLink(url: URL(string: "hutch://git/~user/repo")!)
        #expect(link == .repository(owner: "~user", repo: "repo"))
    }

    @Test
    func parsesTicketLink() {
        let link = DeepLink(url: URL(string: "hutch://todo/~owner/tracker/42")!)
        #expect(link == .ticket(owner: "~owner", tracker: "tracker", ticketId: 42))
    }

    @Test
    func parsesBuildJobLink() {
        let link = DeepLink(url: URL(string: "hutch://builds/12345")!)
        #expect(link == .build(jobId: 12345))
    }

    @Test
    func parsesBuildsTabLink() {
        let link = DeepLink(url: URL(string: "hutch://builds")!)
        #expect(link == .buildsTab)
    }

    @Test
    func parsesRepositoriesTabLink() {
        let link = DeepLink(url: URL(string: "hutch://repositories")!)
        #expect(link == .repositoriesTab)
    }

    @Test
    func parsesTrackersTabLink() {
        let link = DeepLink(url: URL(string: "hutch://trackers")!)
        #expect(link == .trackersTab)
    }

    @Test
    func parsesSystemStatusLink() {
        let link = DeepLink(url: URL(string: "hutch://status")!)
        #expect(link == .systemStatus)
    }

    @Test
    func parsesLookupLink() {
        let link = DeepLink(url: URL(string: "hutch://lookup")!)
        #expect(link == .lookup)
    }

    @Test
    func rejectsNonHutchScheme() {
        let link = DeepLink(url: URL(string: "https://example.com/home")!)
        #expect(link == nil)
    }

    @Test
    func rejectsUnknownPath() {
        let link = DeepLink(url: URL(string: "hutch://unknown")!)
        #expect(link == nil)
    }

    @Test
    func rejectsTicketLinkWithNonNumericId() {
        let link = DeepLink(url: URL(string: "hutch://todo/~owner/tracker/abc")!)
        #expect(link == nil)
    }

    @Test
    func rejectsBuildLinkWithNonNumericId() {
        let link = DeepLink(url: URL(string: "hutch://builds/abc")!)
        #expect(link == nil)
    }
}