internal/control/theme_test.go
36 lines · 1160 bytes
1 symbol in this file
1package control
2
3import (
4 "bytes"
5 "io"
6 "strings"
7 "testing"
8
9 "gitbay.org/gitbay/internal/protocol"
10 "gitbay.org/gitbay/internal/store"
11)
12
13// web theme show reports system for a new account, set refuses anything
14// but the three schemes, and a set value is what show reports next.
15func TestWebTheme(t *testing.T) {
16 st, _, uid := newQueueTestRepo(t)
17 var buf bytes.Buffer
18 c := &Ctx{User: store.User{ID: uid, Username: "alice"}, Store: st, Stdout: &buf, Stderr: io.Discard, JSON: true}
19
20 if code := runWebThemeShow(c, nil); code != protocol.ExitOK || !strings.Contains(buf.String(), `"theme":"system"`) {
21 t.Fatalf("show: %d %s", code, buf.String())
22 }
23 if code := runWebThemeSet(c, []string{"blue"}); code != protocol.ExitUsage {
24 t.Fatalf("bad value exited %d", code)
25 }
26 if code := runWebThemeSet(c, nil); code != protocol.ExitUsage {
27 t.Fatalf("no value exited %d", code)
28 }
29 buf.Reset()
30 if code := runWebThemeSet(c, []string{"dark"}); code != protocol.ExitOK || !strings.Contains(buf.String(), `"theme":"dark"`) {
31 t.Fatalf("set: %d %s", code, buf.String())
32 }
33 if got, _ := st.Theme(uid); got != "dark" {
34 t.Fatalf("stored theme: %q", got)
35 }
36}