internal/control/reposcreen_test.go
54 lines · 2085 bytes
3 symbols in this file
1package control
2
3import (
4 "strings"
5 "testing"
6
7 "gitbay.org/gitbay/internal/protocol"
8 "gitbay.org/gitbay/internal/store"
9)
10
11func TestRepoShowPlainPinned(t *testing.T) {
12 st, repo, uid := newQueueTestRepo(t)
13 c, out, errOut := mrTestCtx(st, store.User{ID: uid, Username: "alice"})
14 if code := Dispatch(c, []string{"repo", "show", repo.Path()}); code != protocol.ExitOK {
15 t.Fatalf("exit %d: %s", code, errOut)
16 }
17 pinPlain(t, "repo-show", out.String())
18}
19
20func TestRepoShowScreen(t *testing.T) {
21 c := screenCtx(100, false)
22 d := repoShowOut{Path: "krz/gitbay", Description: "A CLI-first git forge.", Visibility: "public", DefaultBranch: "main",
23 Topics: []string{"cli", "forge"}}
24 g := repoGlance{clone: "ssh://git@gitbay.org/krz/gitbay.git", release: "v1.41.0, 2h ago", checks: "✓ 2/2 on main", mrsN: 1, issuesN: 3}
25 mrs := []store.MR{{Number: 552, Title: "wire $PAGER", UpdatedAt: "2026-10-01T11:40:00Z"}}
26 issues := []store.Issue{{Number: 12, Title: "Android app", UpdatedAt: "2026-08-21T10:00:00Z"}}
27 s := repoShowScreen(c, d, g, mrs, issues, []CommitOut{{"a136534ff9", "changelog: v1.41.0"}})
28 if n := sectionCounts(s); n["Open merge requests"] != 1 || n["Open issues"] != 3 || n["Recent commits"] != 1 {
29 t.Errorf("sections = %v", n)
30 }
31 out := renderString(c, s)
32 for _, want := range []string{
33 "Head: main ✓ 2/2\n",
34 "A CLI-first git forge.\n",
35 "+2 more gitbay issue list krz/gitbay\n",
36 } {
37 if !strings.Contains(out, want) {
38 t.Errorf("missing %q in:\n%s", want, out)
39 }
40 }
41 checkActions(t, s)
42}
43
44func TestRepoShowScreenMirrorErrorOnly(t *testing.T) {
45 c := screenCtx(100, false)
46 d := repoShowOut{Path: "krz/tap", Visibility: "public", DefaultBranch: "main", Mirrors: []repoMirrorOut{
47 {Direction: "push", URL: "https://github.com/x/tap.git"},
48 {Direction: "push", URL: "https://github.com/x/tap2.git", LastError: "exit status 1"},
49 }}
50 out := renderString(c, repoShowScreen(c, d, repoGlance{}, nil, nil, nil))
51 if strings.Count(out, "Mirror:") != 1 || !strings.Contains(out, "tap2.git: exit status 1") {
52 t.Errorf("mirror lines:\n%s", out)
53 }
54}