e2e/theme_test.go
45 lines · 1710 bytes
1 symbol in this file
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 t.Parallel()
13 inst := startInstanceWith(t, "[web]\nmode = \"accounts\"\n")
14 key := inst.newKey(t, "alice")
15 inst.admin(t, "admin", "user", "create", "alice", "--key", key+".pub")
16
17 if out, _, code := inst.ssh(t, key, "", "web", "theme", "show", "--json"); code != 0 || !strings.Contains(out, `"theme":"system"`) {
18 t.Fatalf("theme show: %d %s", code, out)
19 }
20 if _, _, code := inst.ssh(t, key, "", "web", "theme", "set", "blue"); code != 2 {
21 t.Fatalf("bad value accepted: %d", code)
22 }
23 if out, _, code := inst.ssh(t, key, "", "web", "theme", "set", "dark", "--json"); code != 0 || !strings.Contains(out, `"theme":"dark"`) {
24 t.Fatalf("theme set: %d %s", code, out)
25 }
26
27 alice := inst.login(t, key)
28 set := inst.base() + "/settings"
29 _, body := browserGet(t, alice, set)
30 if !strings.Contains(body, `<html lang="en" data-theme="dark">`) {
31 t.Fatalf("page is not stamped dark:\n%s", body[:200])
32 }
33 if !strings.Contains(body, `<option value="dark" selected>`) {
34 t.Fatalf("account page does not show dark selected")
35 }
36 if status, _ := browserPost(t, alice, set, url.Values{"field": {"theme"}, "theme": {"system"}}); status != 200 {
37 t.Fatalf("settings post: %d", status)
38 }
39 if out, _, _ := inst.ssh(t, key, "", "web", "theme", "show", "--json"); !strings.Contains(out, `"theme":"system"`) {
40 t.Fatalf("web form did not reset the theme: %s", out)
41 }
42 if _, body := browserGet(t, alice, set); strings.Contains(body, "data-theme") {
43 t.Fatalf("system stamps the page")
44 }
45}