package web import ( "net/http" "net/http/httptest" "strings" "testing" "gardomatic.kleiax.de/lib/client" ) func TestPlantPageNamesAreUsedThroughoutTheApplication(t *testing.T) { app := newTestApplication(t) user := client.User{ID: 1, Activated: true} garden := client.Garden{ID: 3, Name: "Hinterhof", Role: "owner"} tests := []struct { name string template string data *templateData want []string }{ { name: "garden plants", template: "plant.tmpl", data: &templateData{commonTemplateData: commonTemplateData{Filters: map[string]string{}}}, want: []string{"Im Garten", "<h2>Im Garten</h2>"}, }, { name: "species", template: "species.tmpl", data: &templateData{commonTemplateData: commonTemplateData{Filters: map[string]string{}}}, want: []string{"<title>Pflanzen", "<h2>Pflanzen</h2>"}, }, { name: "settings", template: "settings.tmpl", data: &templateData{}, want: []string{"for='view-plants'>Im Garten</label>", "for='view-species'>Pflanzen</label>"}, }, { name: "search", template: "search.tmpl", data: &templateData{searchTemplateData: searchTemplateData{Search: searchResults{Query: "Tomate"}}}, want: []string{"<h3>Im Garten</h3>", "<h3>Pflanzen und Pflanzzeiten</h3>"}, }, { name: "dashboard", template: "dashboard.tmpl", data: &templateData{}, want: []string{"href='/g/3/plants'><span class='summary-number'>0</span><h3>Im Garten</h3>"}, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { tt.data.IsAuthenticated = true tt.data.IsActivated = true tt.data.CurrentUser = &user tt.data.Garden = &garden response := httptest.NewRecorder() app.render(response, http.StatusOK, tt.template, tt.data) body := response.Body.String() for _, want := range append([]string{"href='/g/3/plants'>Im Garten</a>", "href='/g/3/species'>Pflanzen</a>"}, tt.want...) { if !strings.Contains(body, want) { t.Errorf("%s is missing %q", tt.template, want) } } }) } }