e2e/profileweb_test.go
110 lines · 4335 bytes
1package e2e
2
3import (
4 "net/url"
5 "strings"
6 "testing"
7)
8
9// TestProfileSettingsWeb covers profile set from the account settings page
10// (#161): description, website, links and about round-trip through the
11// form, and emptying a field actually clears it rather than being skipped.
12func TestProfileSettingsWeb(t *testing.T) {
13 inst := startInstanceWith(t, "[web]\nmode = \"accounts\"\n")
14 aliceKey := inst.newKey(t, "alice")
15 inst.admin(t, "admin", "user", "create", "alice",
16 "--key", aliceKey+".pub", "--email", "alice@example.test", "--verified")
17 alice := inst.login(t, aliceKey)
18 settingsURL := inst.base() + "/settings"
19
20 // The form is on the page, every input labelled.
21 _, body := browserGet(t, alice, settingsURL)
22 for _, want := range []string{
23 `<label for="p-description">`, `<label for="p-website">`,
24 `<label for="p-links">`, `<label for="p-about">`, `<label for="format">`,
25 } {
26 if !strings.Contains(body, want) {
27 t.Fatalf("profile form missing %q:\n%s", want, body)
28 }
29 }
30
31 // Setting every field lands where the CLI reads it.
32 status, _ := browserPost(t, alice, settingsURL, url.Values{
33 "field": {"profile"},
34 "description": {"builds small tools"},
35 "website": {"https://alice.example"},
36 "links": {"Mastodon|https://fosstodon.example/@alice\nhttps://alice.example/now"},
37 "about": {"hello there"},
38 "format": {"md"},
39 })
40 if status != 200 && status != 303 {
41 t.Fatalf("profile post: %d", status)
42 }
43 out, _, _ := inst.ssh(t, aliceKey, "", "profile", "show", "--json")
44 for _, want := range []string{
45 `"description":"builds small tools"`, `"website":"https://alice.example"`,
46 `"label":"Mastodon"`, `"url":"https://fosstodon.example/@alice"`,
47 `"url":"https://alice.example/now"`, `"about":"hello there"`,
48 } {
49 if !strings.Contains(out, want) {
50 t.Fatalf("profile set missing %q: %s", want, out)
51 }
52 }
53
54 // The page shows what was just saved.
55 _, body = browserGet(t, alice, settingsURL)
56 for _, want := range []string{
57 "builds small tools", "https://alice.example", "Mastodon|https://fosstodon.example/@alice",
58 "https://alice.example/now", "hello there",
59 } {
60 if !strings.Contains(body, want) {
61 t.Fatalf("settings page did not round-trip %q:\n%s", want, body)
62 }
63 }
64
65 // The whole form resubmits every time, the way a settings page does:
66 // each step below carries the fields already in place and changes one.
67 links := "Mastodon|https://fosstodon.example/@alice\nhttps://alice.example/now"
68
69 // The org choice is honoured on the profile page.
70 if status, _ := browserPost(t, alice, settingsURL, url.Values{
71 "field": {"profile"}, "description": {"builds small tools"},
72 "website": {"https://alice.example"}, "links": {links},
73 "about": {"a /note/ in org"}, "format": {"org"},
74 }); status != 200 && status != 303 {
75 t.Fatalf("profile post (org): %d", status)
76 }
77 if _, page := browserGet(t, alice, inst.base()+"/alice"); !strings.Contains(page, "<em>note</em>") {
78 t.Fatalf("about did not render as org:\n%s", page)
79 }
80
81 // Emptying the website clears it, not leaves it alone.
82 if status, _ := browserPost(t, alice, settingsURL, url.Values{
83 "field": {"profile"}, "description": {"builds small tools"},
84 "website": {""}, "links": {links}, "about": {"a /note/ in org"}, "format": {"org"},
85 }); status != 200 && status != 303 {
86 t.Fatalf("profile post (clear website): %d", status)
87 }
88 out, _, _ = inst.ssh(t, aliceKey, "", "profile", "show", "--json")
89 if strings.Contains(out, "alice.example") && strings.Contains(out, `"website"`) {
90 t.Fatalf("website not cleared: %s", out)
91 }
92 if !strings.Contains(out, "builds small tools") {
93 t.Fatalf("clearing website clobbered the description: %s", out)
94 }
95 if !strings.Contains(out, `"label":"Mastodon"`) {
96 t.Fatalf("clearing website clobbered the links: %s", out)
97 }
98
99 // Emptying the links field clears the whole list.
100 if status, _ := browserPost(t, alice, settingsURL, url.Values{
101 "field": {"profile"}, "description": {"builds small tools"},
102 "links": {""}, "about": {"a /note/ in org"}, "format": {"org"},
103 }); status != 200 && status != 303 {
104 t.Fatalf("profile post (clear links): %d", status)
105 }
106 out, _, _ = inst.ssh(t, aliceKey, "", "profile", "show", "--json")
107 if strings.Contains(out, "Mastodon") || strings.Contains(out, `"links"`) {
108 t.Fatalf("links not cleared: %s", out)
109 }
110}