krz/hutch

an ios client for sourcehut

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

v3.3.1: HutchTests/ProjectTests.swift · raw

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