krz/hutch
an ios client for sourcehut
clone: git clone https://gitbay.org/krz/hutch.git
v3.0.4: HutchTests/ProjectTests.swift · raw
1import Foundation
2import Testing
3@testable import Hutch
4
5struct ProjectTests {
6 @Test
7 func resourceSummaryIncludesCounts() {
8 let project = Project(
9 id: "project-1",
10 name: "Hutch",
11 description: nil,
12 website: nil,
13 visibility: .public,
14 tags: [],
15 updated: Date(timeIntervalSince1970: 0),
16 mailingLists: [
17 Project.MailingList(
18 id: "list-1",
19 name: "hutch-devel",
20 description: nil,
21 visibility: .public,
22 owner: Entity(canonicalName: "~owner")
23 )
24 ],
25 sources: [
26 Project.SourceRepo(
27 id: "repo-1",
28 name: "hutch",
29 description: nil,
30 visibility: .public,
31 owner: Entity(canonicalName: "~owner"),
32 repoType: .git
33 ),
34 Project.SourceRepo(
35 id: "repo-2",
36 name: "hutch-web",
37 description: nil,
38 visibility: .public,
39 owner: Entity(canonicalName: "~owner"),
40 repoType: .git
41 )
42 ],
43 trackers: [
44 Project.Tracker(
45 id: "tracker-1",
46 name: "bugs",
47 description: nil,
48 visibility: .public,
49 owner: Entity(canonicalName: "~owner")
50 )
51 ]
52 )
53
54 #expect(project.resourceSummary == "2 repos • 1 tracker • 1 list")
55 }
56
57 @Test
58 func resourceSummaryFallsBackToWebsite() {
59 let project = Project(
60 id: "project-1",
61 name: "Docs",
62 description: nil,
63 website: "https://example.com",
64 visibility: .public,
65 tags: [],
66 updated: Date(timeIntervalSince1970: 0),
67 mailingLists: [],
68 sources: [],
69 trackers: []
70 )
71
72 #expect(project.resourceSummary == "Website linked")
73 }
74
75 @Test
76 func displayHelpersNormalizeBlankValues() {
77 let project = Project(
78 id: "project-1",
79 name: " ",
80 description: "\n",
81 website: "https://example.com",
82 visibility: .unlisted,
83 tags: [" docs ", "", "Docs", "ios"],
84 updated: Date(timeIntervalSince1970: 0),
85 mailingLists: [],
86 sources: [],
87 trackers: []
88 )
89
90 #expect(project.displayName == "Untitled Project")
91 #expect(project.displayDescription == nil)
92 #expect(project.displayTags == ["docs", "ios"])
93 #expect(project.metadataLine.contains("Unlisted"))
94 }
95}