Skip to content

Commit

Permalink
Add tests for redirect view name prefix with flash attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
xhaggi committed Nov 19, 2024
1 parent d535857 commit 1c65529
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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 {

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 1c65529

Please sign in to comment.