eintopf.info@v0.13.16/web/place_test.go (about) 1 // Copyright (C) 2022 The Eintopf authors 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Affero General Public License as 5 // published by the Free Software Foundation, either version 3 of the 6 // License, or (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Affero General Public License for more details. 12 // 13 // You should have received a copy of the GNU Affero General Public License 14 // along with this program. If not, see <https://www.gnu.org/licenses/>. 15 16 package web 17 18 import ( 19 "testing" 20 "time" 21 22 "github.com/PuerkitoBio/goquery" 23 "github.com/google/go-cmp/cmp" 24 25 "eintopf.info/service/event" 26 "eintopf.info/service/place" 27 ) 28 29 func TestPlacePage(t *testing.T) { 30 tests := []routeTest{ 31 { 32 name: "NotFound", 33 tz: time.UTC, 34 uri: "/ort/12345", 35 places: []*place.NewPlace{ 36 { 37 Published: true, 38 Name: "foo", 39 }, 40 }, 41 status: 404, 42 htmlTestFunc: func(t *testing.T, doc *goquery.Document) { 43 if diff := cmp.Diff("404 Ort wurde nicht gefunden", doc.Find(".error").Text()); diff != "" { 44 t.Errorf(".error mismatch (-want +got):\n%s", diff) 45 } 46 }, 47 }, 48 { 49 name: "Works", 50 tz: time.UTC, 51 uri: "/ort/0", 52 places: []*place.NewPlace{ 53 { 54 Published: true, 55 Name: "foo", 56 Lat: 1, 57 Lng: 2, 58 }, 59 }, 60 status: 200, 61 htmlTestFunc: func(t *testing.T, doc *goquery.Document) { 62 if diff := cmp.Diff(2, len(doc.Find("h1").Nodes)); diff != "" { 63 t.Errorf("h1 mismatch (-want +got):\n%s", diff) 64 } 65 if diff := cmp.Diff("foofoo", doc.Find("h1").Text()); diff != "" { 66 t.Errorf("h1 text mismatch (-want +got):\n%s", diff) 67 } 68 69 assertMap(t, doc) 70 }, 71 }, 72 { 73 name: "NotPublished", 74 tz: time.UTC, 75 uri: "/ort/0", 76 places: []*place.NewPlace{ 77 { 78 Published: false, 79 Name: "foo", 80 }, 81 }, 82 status: 200, 83 }, 84 { 85 name: "MetaNoIndexNotPublished", 86 tz: time.UTC, 87 uri: "/ort/0", 88 places: []*place.NewPlace{ 89 { 90 Published: false, 91 Name: "foo", 92 }, 93 }, 94 status: 200, 95 htmlTestFunc: func(tt *testing.T, doc *goquery.Document) { 96 assertRobotsIndex(t, doc, "noindex, nofollow") 97 }, 98 }, 99 { 100 name: "MetaIndexPublished", 101 tz: time.UTC, 102 uri: "/ort/0", 103 places: []*place.NewPlace{ 104 { 105 Published: true, 106 Name: "foo", 107 }, 108 }, 109 status: 200, 110 htmlTestFunc: func(tt *testing.T, doc *goquery.Document) { 111 assertRobotsIndex(t, doc, "index, follow") 112 }, 113 }, 114 { 115 name: "MetaDefault", 116 tz: time.UTC, 117 uri: "/ort/0", 118 themes: []string{"eintopf", "testdata/themes/meta"}, 119 places: []*place.NewPlace{ 120 { 121 Published: true, 122 Name: "Foo", 123 }, 124 }, 125 status: 200, 126 htmlTestFunc: func(tt *testing.T, doc *goquery.Document) { 127 assertRobotsIndex(t, doc, "index, follow") 128 assertMeta(t, doc, MetaTags{ 129 Title: "Foo | Custom Sitename", 130 Description: "Custom Meta Description", 131 Image: "/assets/images/logo.png", 132 }) 133 }, 134 }, 135 { 136 name: "MetaContent", 137 tz: time.UTC, 138 uri: "/ort/0", 139 places: []*place.NewPlace{ 140 { 141 Published: true, 142 Name: "Foo", 143 Description: "Foo bar", 144 Image: "Foobar.png", 145 }, 146 }, 147 status: 200, 148 htmlTestFunc: func(tt *testing.T, doc *goquery.Document) { 149 assertRobotsIndex(t, doc, "index, follow") 150 assertMeta(t, doc, MetaTags{ 151 Title: "Foo | Eintopf Stuttgart", 152 Description: "Foo bar", 153 Image: "/api/v1/media/Foobar.png", 154 }) 155 }, 156 }, 157 { 158 name: "WithoutMap NoLatLng", 159 tz: time.UTC, 160 uri: "/ort/0", 161 places: []*place.NewPlace{ 162 { 163 Published: true, 164 Name: "bar", 165 }, 166 }, 167 status: 200, 168 htmlTestFunc: func(t *testing.T, doc *goquery.Document) { 169 assertNoMap(t, doc) 170 }, 171 }, 172 { 173 name: "PastEvents", 174 uri: "/ort/0", 175 places: []*place.NewPlace{ 176 { 177 Published: true, 178 Name: "place1", 179 }, 180 { 181 Published: true, 182 Name: "place2", 183 }, 184 }, 185 events: []*event.NewEvent{ 186 // Included 187 { 188 Published: true, 189 Name: "past", 190 Location: "id:0", 191 Start: time.Now().Add(-1 * time.Hour * 24), 192 }, 193 { 194 Published: true, 195 Name: "multiday", 196 Location: "id:0", 197 Start: time.Now().Add(-5 * time.Hour * 24), 198 End: tptr(time.Now().Add(-2 * time.Hour * 24)), 199 }, 200 // Not included 201 { 202 Published: true, 203 Name: "another location", 204 Location: "id:1", 205 Start: time.Now().Add(-1 * time.Hour * 24), 206 }, 207 { 208 Published: true, 209 Name: "future", 210 Location: "id:0", 211 Start: time.Now().Add(time.Hour * 24), 212 }, 213 { 214 Published: false, 215 Name: "not published", 216 Location: "id:0", 217 Start: time.Now().Add(-1 * time.Hour * 24), 218 }, 219 }, 220 status: 200, 221 htmlTestFunc: func(t *testing.T, doc *goquery.Document) { 222 assertPastEvents(t, doc, []string{"past", "multiday"}) 223 }, 224 }, 225 { 226 name: "FutureEvents", 227 uri: "/ort/0", 228 places: []*place.NewPlace{ 229 { 230 Published: true, 231 Name: "place1", 232 }, 233 { 234 Published: true, 235 Name: "place2", 236 }, 237 }, 238 events: []*event.NewEvent{ 239 // Included 240 { 241 Published: true, 242 Name: "future", 243 Location: "id:0", 244 Start: time.Now().Add(time.Hour * 24), 245 }, 246 { 247 Published: true, 248 Name: "multiday", 249 Location: "id:0", 250 Start: time.Now().Add(time.Hour * 24), 251 End: tptr(time.Now().Add(time.Hour * 24 * 5)), 252 }, 253 // Not included 254 { 255 Published: true, 256 Name: "another location", 257 Location: "id:1", 258 Start: time.Now().Add(time.Hour * 24), 259 }, 260 { 261 Published: true, 262 Name: "past", 263 Location: "id:0", 264 Start: time.Now().Add(-2 * time.Hour * 24), 265 }, 266 { 267 Published: false, 268 Name: "not published", 269 Location: "id:0", 270 Start: time.Now().Add(time.Hour * 24), 271 }, 272 }, 273 status: 200, 274 htmlTestFunc: func(t *testing.T, doc *goquery.Document) { 275 assertFutureEvents(t, doc, []string{"future", "multiday"}) 276 }, 277 }, 278 } 279 280 testRoutes(t, tests) 281 }