diff --git a/htmx-spring-boot/src/test/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxHandlerMethodTest.java b/htmx-spring-boot/src/test/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxHandlerMethodTest.java index 81708f1..c2785e6 100644 --- a/htmx-spring-boot/src/test/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxHandlerMethodTest.java +++ b/htmx-spring-boot/src/test/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxHandlerMethodTest.java @@ -74,6 +74,15 @@ public void testLocationRedirectViewNamePrefixContextRelative() throws Exception .andExpect(header().string("HX-Location", "/contextpath/path")); } + @Test + public void testLocationRedirectViewNamePrefixFlashAttributes() throws Exception { + + mockMvc.perform(get("/location-redirect-view-name-prefix-flash-attributes").headers(htmxRequest())) + .andExpect(status().isOk()) + .andExpect(header().string("HX-Location", "/path")) + .andExpect(flash().attribute("flash", "test")); + } + @Test public void testLocationRedirectWithContextData() throws Exception { @@ -148,6 +157,15 @@ public void testRedirectViewNamePrefixContextRelative() throws Exception { .andExpect(header().string("HX-Redirect", "/contextpath/test")); } + @Test + public void testRedirectViewNamePrefixFlashAttributes() throws Exception { + + mockMvc.perform(get("/contextpath/redirect-view-name-prefix-flash-attributes").contextPath("/contextpath").headers(htmxRequest())) + .andExpect(status().isOk()) + .andExpect(header().string("HX-Redirect", "/contextpath/test")) + .andExpect(flash().attribute("flash", "test"));; + } + @Test public void testRedirectWithContextPath() throws Exception { @@ -219,6 +237,14 @@ public String locationRedirectViewNamePrefix() { return "htmx:location:/path"; } + @HxRequest + @GetMapping("/location-redirect-view-name-prefix-flash-attributes") + public String locationRedirectWithViewNamePrefixFlashAttributes(RedirectAttributes redirectAttributes) { + + redirectAttributes.addFlashAttribute("flash", "test"); + return "htmx:location:/path"; + } + @HxRequest @GetMapping("/location-redirect-with-context-data") public HtmxLocationRedirectView locationRedirectWithContextData() { @@ -308,6 +334,14 @@ public HtmxRedirectView redirectExposingModelAttributes(RedirectAttributes attri return new HtmxRedirectView("/test"); } + @HxRequest + @GetMapping("/redirect-view-name-prefix-flash-attributes") + public String redirectWithViewNamePrefixFlashAttributes(RedirectAttributes redirectAttributes) { + + redirectAttributes.addFlashAttribute("flash", "test"); + return "htmx:redirect:/test"; + } + @HxRequest @GetMapping("/redirect-view-name-prefix") public String redirectViewNamePrefix() {