internal/control/issuescreen_test.go

main
gitbay/internal/control/issuescreen_test.go history · blame · raw

77 lines · 2443 bytes

6 symbols in this file
 1package control
 2
 3import (
 4	"slices"
 5	"testing"
 6
 7	"gitbay.org/gitbay/internal/protocol"
 8	"gitbay.org/gitbay/internal/store"
 9)
10
11func TestIssueShowPlainPinned(t *testing.T) {
12	st, repo, uid := newQueueTestRepo(t)
13	owner := store.User{ID: uid, Username: "alice"}
14	id, err := st.CreateIssue(repo.ID, uid, "Android app", "An app.", "md")
15	if err != nil {
16		t.Fatal(err)
17	}
18	if err := st.AddIssueComment(id, uid, "Started.", "md"); err != nil {
19		t.Fatal(err)
20	}
21	c, out, errOut := mrTestCtx(st, owner)
22	if code := Dispatch(c, []string{"issue", "show", repo.Path(), "1"}); code != protocol.ExitOK {
23		t.Fatalf("exit %d: %s", code, errOut)
24	}
25	pinPlain(t, "issue-show", out.String())
26}
27
28func issueFixture() IssueShow {
29	return IssueShow{issueOut: issueOut{Number: 12, Title: "Android app", State: "open", Author: "cmc",
30		Labels: []string{"mobile"}, Assignees: []string{"alice"}, Body: "An app.", BodyFormat: "md",
31		CreatedAt: "2026-08-21T10:00:00Z"},
32		Comments: []commentOut{
33			{ID: 1, Author: "cmc", Body: "Started.", BodyFormat: "md", CreatedAt: "2026-09-01T10:00:00Z", Kind: "comment"},
34			{ID: 2, Author: "cmc", Body: "labelled mobile", CreatedAt: "2026-09-01T10:00:00Z", Kind: "system"},
35		}}
36}
37
38func actionVerbs(s screen) []string {
39	var v []string
40	for _, a := range s.actions {
41		v = append(v, a.argv[1])
42	}
43	return v
44}
45
46func TestIssueShowScreenWriter(t *testing.T) {
47	c := screenCtx(100, false)
48	c.User = store.User{Username: "alice"}
49	s := issueShowScreen(c, screenRepo, issueFixture(), true)
50	if n := sectionCounts(s); n["Discussion"] != 1 || n["Events"] != 1 {
51		t.Errorf("sections = %v", n)
52	}
53	if got, want := actionVerbs(s), []string{"comment", "assign", "label", "close"}; !slices.Equal(got, want) {
54		t.Errorf("actions = %q, want %q", got, want)
55	}
56	checkActions(t, s)
57}
58
59func TestIssueShowScreenAuthorCanClose(t *testing.T) {
60	c := screenCtx(100, false)
61	c.User = store.User{Username: "cmc"}
62	s := issueShowScreen(c, screenRepo, issueFixture(), false)
63	if got, want := actionVerbs(s), []string{"comment", "close"}; !slices.Equal(got, want) {
64		t.Errorf("actions = %q, want %q", got, want)
65	}
66}
67
68func TestIssueShowScreenReader(t *testing.T) {
69	c := screenCtx(100, false)
70	c.User = store.User{Username: "bob"}
71	d := issueFixture()
72	d.State = "closed"
73	s := issueShowScreen(c, screenRepo, d, false)
74	if got, want := actionVerbs(s), []string{"comment"}; !slices.Equal(got, want) {
75		t.Errorf("actions = %q, want %q", got, want)
76	}
77}