summaryrefslogtreecommitdiff
path: root/HutchTests/ProjectTests.swift
blob: 23faa0d381e3a00cd9cd1e6e88f7a73994d56a1a (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import Foundation
import Testing
@testable import Hutch

struct ProjectTests {
    private enum Fixture {
        static let exampleWebsite = "https://example.com"
    }

    @Test
    func resourceSummaryIncludesCounts() {
        let project = Project(
            metadata: .init(
                id: "project-1",
                name: "Hutch",
                description: nil,
                website: nil,
                visibility: .publicVisibility,
                tags: [],
                updated: Date(timeIntervalSince1970: 0)
            ),
            resources: .init(
                mailingLists: [
                    Project.MailingList(
                        id: "list-1",
                        name: "hutch-devel",
                        description: nil,
                        visibility: .publicVisibility,
                        owner: Entity(canonicalName: "~owner")
                    )
                ],
                sources: [
                    Project.SourceRepo(
                        id: "repo-1",
                        name: "hutch",
                        description: nil,
                        visibility: .publicVisibility,
                        owner: Entity(canonicalName: "~owner"),
                        repoType: .git
                    ),
                    Project.SourceRepo(
                        id: "repo-2",
                        name: "hutch-web",
                        description: nil,
                        visibility: .publicVisibility,
                        owner: Entity(canonicalName: "~owner"),
                        repoType: .git
                    )
                ],
                trackers: [
                    Project.Tracker(
                        id: "tracker-1",
                        name: "bugs",
                        description: nil,
                        visibility: .publicVisibility,
                        owner: Entity(canonicalName: "~owner")
                    )
                ],
                isFullyLoaded: true
            )
        )

        #expect(project.resourceSummary == "2 repos • 1 tracker • 1 list")
    }

    @Test
    func resourceSummaryFallsBackToWebsite() {
        let project = Project(
            metadata: .init(
                id: "project-1",
                name: "Docs",
                description: nil,
                website: Fixture.exampleWebsite,
                visibility: .publicVisibility,
                tags: [],
                updated: Date(timeIntervalSince1970: 0)
            ),
            resources: .init(mailingLists: [], sources: [], trackers: [], isFullyLoaded: true)
        )

        #expect(project.resourceSummary == "Website linked")
    }

    @Test
    func displayHelpersNormalizeBlankValues() {
        let project = Project(
            metadata: .init(
                id: "project-1",
                name: "  ",
                description: "\n",
                website: Fixture.exampleWebsite,
                visibility: .unlisted,
                tags: [" docs ", "", "Docs", "ios"],
                updated: Date(timeIntervalSince1970: 0)
            ),
            resources: .init(mailingLists: [], sources: [], trackers: [], isFullyLoaded: true)
        )

        #expect(project.displayName == "Untitled Project")
        #expect(project.displayDescription == nil)
        #expect(project.displayTags == ["docs", "ios"])
        #expect(project.metadataLine.contains("Unlisted"))
    }
}