|
4 | 4 | import org.springframework.beans.factory.annotation.Autowired; |
5 | 5 | import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; |
6 | 6 | import org.springframework.security.test.context.support.WithMockUser; |
| 7 | +import org.springframework.stereotype.Controller; |
| 8 | +import org.springframework.test.context.ContextConfiguration; |
7 | 9 | import org.springframework.test.web.servlet.MockMvc; |
| 10 | +import org.springframework.web.bind.annotation.GetMapping; |
| 11 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 12 | +import org.springframework.web.bind.annotation.ResponseBody; |
8 | 13 |
|
9 | 14 | import static org.hamcrest.Matchers.not; |
10 | 15 | import static org.hamcrest.collection.IsIterableContainingInRelativeOrder.containsInRelativeOrder; |
11 | 16 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
12 | 17 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; |
13 | 18 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
14 | 19 |
|
15 | | -@WebMvcTest(TestController.class) |
| 20 | +@WebMvcTest(HtmxHandlerInterceptorTest.TestController.class) |
| 21 | +@ContextConfiguration(classes = HtmxHandlerInterceptorTest.TestController.class) |
16 | 22 | @WithMockUser |
17 | 23 | class HtmxHandlerInterceptorTest { |
18 | 24 |
|
@@ -231,4 +237,176 @@ public void testHxReselect() throws Exception { |
231 | 237 | .andExpect(header().string("HX-Reselect", "#target")); |
232 | 238 | } |
233 | 239 |
|
| 240 | + @Controller |
| 241 | + @RequestMapping("/") |
| 242 | + static class TestController { |
| 243 | + |
| 244 | + @GetMapping("/without-trigger") |
| 245 | + @ResponseBody |
| 246 | + public String methodWithoutAnnotations() { |
| 247 | + return ""; |
| 248 | + } |
| 249 | + |
| 250 | + @GetMapping("/with-trigger") |
| 251 | + @HxTrigger("eventTriggered") |
| 252 | + @ResponseBody |
| 253 | + public String methodWithHxTrigger() { |
| 254 | + return ""; |
| 255 | + } |
| 256 | + |
| 257 | + @GetMapping("/with-trigger-multiple-events") |
| 258 | + @HxTrigger({ "event1", "event2" }) |
| 259 | + @ResponseBody |
| 260 | + public String methodWithHxTriggerAndMultipleEvents() { |
| 261 | + return ""; |
| 262 | + } |
| 263 | + |
| 264 | + @GetMapping("/with-trigger-after-settle") |
| 265 | + @HxTriggerAfterSettle("eventTriggered") |
| 266 | + @ResponseBody |
| 267 | + public String methodWithHxTriggerAfterSettle() { |
| 268 | + return ""; |
| 269 | + } |
| 270 | + |
| 271 | + @GetMapping("/with-trigger-after-settle-multiple-events") |
| 272 | + @HxTriggerAfterSettle({ "event1", "event2" }) |
| 273 | + @ResponseBody |
| 274 | + public String methodWithHxTriggerAfterSettleAndMultipleEvents() { |
| 275 | + return ""; |
| 276 | + } |
| 277 | + |
| 278 | + @GetMapping("/with-trigger-after-swap") |
| 279 | + @HxTriggerAfterSwap("eventTriggered") |
| 280 | + @ResponseBody |
| 281 | + public String methodWithHxTriggerAfterSwap() { |
| 282 | + return ""; |
| 283 | + } |
| 284 | + |
| 285 | + @GetMapping("/with-trigger-after-swap-multiple-events") |
| 286 | + @HxTriggerAfterSwap({ "event1", "event2" }) |
| 287 | + @ResponseBody |
| 288 | + public String methodWithHxTriggerAfterSwapAndMultipleEvents() { |
| 289 | + return ""; |
| 290 | + } |
| 291 | + |
| 292 | + @GetMapping("/with-triggers") |
| 293 | + @HxTrigger({ "event1", "event2" }) |
| 294 | + @HxTriggerAfterSettle({ "event1", "event2" }) |
| 295 | + @HxTriggerAfterSwap({ "event1", "event2" }) |
| 296 | + @ResponseBody |
| 297 | + public String methodWithHxTriggers() { |
| 298 | + return ""; |
| 299 | + } |
| 300 | + |
| 301 | + @GetMapping("/updates-sidebar") |
| 302 | + @HxUpdatesSidebar |
| 303 | + @ResponseBody |
| 304 | + public String updatesSidebar() { |
| 305 | + return ""; |
| 306 | + } |
| 307 | + |
| 308 | + @GetMapping("/hx-trigger-alias-for") |
| 309 | + @HxTriggerWithAliasFor(event = "updateTrigger") |
| 310 | + @ResponseBody |
| 311 | + public String hxTriggerWithAliasForOverride() { |
| 312 | + return ""; |
| 313 | + } |
| 314 | + |
| 315 | + @GetMapping("/hx-refresh") |
| 316 | + @HxRefresh |
| 317 | + @ResponseBody |
| 318 | + public String hxRefresh() { |
| 319 | + return ""; |
| 320 | + } |
| 321 | + |
| 322 | + @GetMapping("/hx-vary") |
| 323 | + @ResponseBody |
| 324 | + public String hxVary() { |
| 325 | + return ""; |
| 326 | + } |
| 327 | + |
| 328 | + @GetMapping("/hx-location-without-context-data") |
| 329 | + @HxLocation("/path") |
| 330 | + @ResponseBody |
| 331 | + public String hxLocationWithoutContextData() { |
| 332 | + return ""; |
| 333 | + } |
| 334 | + |
| 335 | + @GetMapping("/hx-location-with-context-data") |
| 336 | + @HxLocation(path = "/path", source = "source", event = "event", handler = "handler", target = "target", swap = "swap", select = "select") |
| 337 | + @ResponseBody |
| 338 | + public String hxLocationWithContextData() { |
| 339 | + return ""; |
| 340 | + } |
| 341 | + |
| 342 | + @GetMapping("/hx-push-url-path") |
| 343 | + @HxPushUrl("/path") |
| 344 | + @ResponseBody |
| 345 | + public String hxPushUrlPath() { |
| 346 | + return ""; |
| 347 | + } |
| 348 | + |
| 349 | + @GetMapping("/hx-push-url") |
| 350 | + @HxPushUrl |
| 351 | + @ResponseBody |
| 352 | + public String hxPushUrl() { |
| 353 | + return ""; |
| 354 | + } |
| 355 | + |
| 356 | + @GetMapping("/hx-push-url-false") |
| 357 | + @HxPushUrl(HtmxValue.FALSE) |
| 358 | + @ResponseBody |
| 359 | + public String hxPushUrlFalse() { |
| 360 | + return ""; |
| 361 | + } |
| 362 | + |
| 363 | + @GetMapping("/hx-redirect") |
| 364 | + @HxRedirect("/path") |
| 365 | + @ResponseBody |
| 366 | + public String hxRedirect() { |
| 367 | + return ""; |
| 368 | + } |
| 369 | + |
| 370 | + @GetMapping("/hx-replace-url-path") |
| 371 | + @HxReplaceUrl("/path") |
| 372 | + @ResponseBody |
| 373 | + public String hxReplaceUrlPath() { |
| 374 | + return ""; |
| 375 | + } |
| 376 | + @GetMapping("/hx-replace-url") |
| 377 | + @HxReplaceUrl |
| 378 | + @ResponseBody |
| 379 | + public String hxReplaceUrl() { |
| 380 | + return ""; |
| 381 | + } |
| 382 | + @GetMapping("/hx-replace-url-false") |
| 383 | + @HxReplaceUrl(HtmxValue.FALSE) |
| 384 | + @ResponseBody |
| 385 | + public String hxReplaceUrlFalse() { |
| 386 | + return ""; |
| 387 | + } |
| 388 | + |
| 389 | + @GetMapping("/hx-reswap") |
| 390 | + @HxReswap(value = HxSwapType.INNER_HTML, swap = 300) |
| 391 | + @ResponseBody |
| 392 | + public String hxReswap() { |
| 393 | + return ""; |
| 394 | + } |
| 395 | + |
| 396 | + @GetMapping("/hx-retarget") |
| 397 | + @HxRetarget("#target") |
| 398 | + @ResponseBody |
| 399 | + public String hxRetarget() { |
| 400 | + return ""; |
| 401 | + } |
| 402 | + |
| 403 | + @GetMapping("/hx-reselect") |
| 404 | + @HxReselect("#target") |
| 405 | + @ResponseBody |
| 406 | + public String hxReselect() { |
| 407 | + return ""; |
| 408 | + } |
| 409 | + |
| 410 | + } |
| 411 | + |
234 | 412 | } |
0 commit comments