e2e/theme_test.go
44 lines · 1696 bytes
1package e2e
2
3import (
4 "net/url"
5 "strings"
6 "testing"
7)
8
9// web theme set fixes the colour scheme the layout stamps on <html>; the
10// account page shows the same setting and changes it (#232).
11func TestWebTheme(t *testing.T) {
12 inst := startInstanceWith(t, "[web]\nmode = \"accounts\"\n")
13 key := inst.newKey(t, "alice")
14 inst.admin(t, "admin", "user", "create", "alice", "--key", key+".pub")
15
16 if out, _, code := inst.ssh(t, key, "", "web", "theme", "show", "--json"); code != 0 || !strings.Contains(out, `"theme":"system"`) {
17 t.Fatalf("theme show: %d %s", code, out)
18 }
19 if _, _, code := inst.ssh(t, key, "", "web", "theme", "set", "blue"); code != 2 {
20 t.Fatalf("bad value accepted: %d", code)
21 }
22 if out, _, code := inst.ssh(t, key, "", "web", "theme", "set", "dark", "--json"); code != 0 || !strings.Contains(out, `"theme":"dark"`) {
23 t.Fatalf("theme set: %d %s", code, out)
24 }
25
26 alice := inst.login(t, key)
27 set := inst.base() + "/settings"
28 _, body := browserGet(t, alice, set)
29 if !strings.Contains(body, `<html lang="en" data-theme="dark">`) {
30 t.Fatalf("page is not stamped dark:\n%s", body[:200])
31 }
32 if !strings.Contains(body, `<option value="dark" selected>`) {
33 t.Fatalf("account page does not show dark selected")
34 }
35 if status, _ := browserPost(t, alice, set, url.Values{"field": {"theme"}, "theme": {"system"}}); status != 200 {
36 t.Fatalf("settings post: %d", status)
37 }
38 if out, _, _ := inst.ssh(t, key, "", "web", "theme", "show", "--json"); !strings.Contains(out, `"theme":"system"`) {
39 t.Fatalf("web form did not reset the theme: %s", out)
40 }
41 if _, body := browserGet(t, alice, set); strings.Contains(body, "data-theme") {
42 t.Fatalf("system stamps the page")
43 }
44}