krz/hutch

an ios client for sourcehut

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

main: HutchTests/ProjectTests.swift · raw

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