This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

core / appview / pages / spindle_input_test.go
2.5 kB 88 lines
1package pages 2 3import ( 4 "bytes" 5 "io" 6 "log/slog" 7 "strings" 8 "testing" 9 10 "tangled.org/core/appview/config" 11 "tangled.org/core/appview/oauth" 12 "tangled.org/core/appview/pages/repoinfo" 13 "tangled.org/core/idresolver" 14) 15 16// the spindle picker is free text with a datalist of recently used spindles, and 17// is shared by repo-new, repo-fork and repo-settings/pipelines. Rendering catches 18// what parsing can't: a mistyped fragment name or dict key only fails on execute. 19func TestSpindleInputRenders(t *testing.T) { 20 cfg := &config.Config{} 21 p := NewPages(cfg, idresolver.DefaultResolver("https://plc.test"), nil, nil, slog.New(slog.NewTextHandler(io.Discard, nil))) 22 23 cases := []struct { 24 name string 25 stack []string 26 define string 27 params any 28 want []string 29 }{ 30 { 31 name: "repo/new", 32 stack: []string{"repo/new"}, 33 define: "spindle", 34 params: NewRepoParams{Spindles: []string{"spindle.example.com"}}, 35 want: []string{`list="spindle-options"`, `<option value="spindle.example.com">`, `value=""`}, 36 }, 37 { 38 name: "repo/fork", 39 stack: []string{"repo/fork"}, 40 define: "content", 41 params: ForkRepoParams{ 42 BaseParams: BaseParams{ 43 LoggedInUser: &oauth.MultiAccountUser{Did: "did:plc:test"}, 44 }, 45 Spindles: []string{"spindle.example.com"}, 46 RepoInfo: repoinfo.RepoInfo{OwnerDid: "did:plc:test", Name: "test-repo"}, 47 }, 48 want: []string{`list="spindle-options"`, `<option value="spindle.example.com">`}, 49 }, 50 { 51 name: "repo/settings/pipelines", 52 stack: []string{"repo/settings/pipelines"}, 53 define: "spindleSettings", 54 params: RepoPipelineSettingsParams{ 55 Spindles: []string{"spindle.example.com"}, 56 CurrentSpindle: "spindle.tangled.sh", 57 RepoInfo: repoinfo.RepoInfo{ 58 OwnerDid: "did:plc:test", 59 Name: "test-repo", 60 Roles: repoinfo.RolesInRepo{Roles: []string{"repo:owner"}}, 61 }, 62 }, 63 // the current spindle is prefilled, and clearing the field removes it 64 want: []string{`value="spindle.tangled.sh"`, `<option value="spindle.example.com">`}, 65 }, 66 } 67 68 for _, c := range cases { 69 t.Run(c.name, func(t *testing.T) { 70 tpl, err := p.rawParse(c.stack...) 71 if err != nil { 72 t.Fatalf("parse %v: %v", c.stack, err) 73 } 74 75 var buf bytes.Buffer 76 if err := tpl.ExecuteTemplate(&buf, c.define, c.params); err != nil { 77 t.Fatalf("execute %q: %v", c.define, err) 78 } 79 80 got := buf.String() 81 for _, want := range c.want { 82 if !strings.Contains(got, want) { 83 t.Errorf("output missing %q:\n%s", want, got) 84 } 85 } 86 }) 87 } 88}