Skip to content

Commit

Permalink
Add a test for going from a regular POST into a subflow
Browse files Browse the repository at this point in the history
  • Loading branch information
spokenbird authored and cy-by committed Nov 1, 2023
1 parent cfc3297 commit 63ad9b6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import formflow.library.address_validation.AddressValidationService;
Expand All @@ -21,6 +22,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;

Expand Down Expand Up @@ -180,9 +182,6 @@ public void shouldSetIterationIsCompleteWhenLastScreenInSubflowIsAPost() throws
assertThat((Boolean) iterationAfterSecondSubflowScreeen.get("iterationIsComplete")).isTrue();
}

private record Result(UUID testSubflowLogicUUID, List<Map<String, Object>> iterationsAfterFirstPost, String uuidString) {
}

@Test
public void shouldHandleSubflowsWithAGetAndThenAPost() throws Exception {
setFlowInfoInSession(session, "yetAnotherTestFlow", submission.getId());
Expand All @@ -208,6 +207,30 @@ public void shouldHandleSubflowsWithAGetAndThenAPost() throws Exception {
List<Map<String, Object>> iterationsAfterSecondPost = (List<Map<String, Object>>) submissionAfterSecondPost.getInputData().get("subflowWithAGetAndThenAPost");
assertThat((Boolean) iterationsAfterSecondPost.get(0).get("iterationIsComplete")).isTrue();
}

@Test
public void shouldHandleGoingFromANonSubflowPostScreenIntoASubflow() throws Exception {
setFlowInfoInSession(session, "testSubflowLogic", submission.getId());

ResultActions result = mockMvc.perform(post("/flow/testSubflowLogic/testEntryScreen")
.session(session)
.params(new LinkedMultiValueMap<>(Map.of(
"doYouWantToEnterTheTestSubflow", List.of("true"))))
);
String nextScreenUrl = "/flow/testSubflowLogic/testEntryScreen/navigation";
result.andExpect(redirectedUrl(nextScreenUrl));

while (Objects.requireNonNull(nextScreenUrl).contains("/navigation")) {
// follow redirects
nextScreenUrl = mockMvc.perform(get(nextScreenUrl).session(session))
.andExpect(status().is3xxRedirection()).andReturn()
.getResponse()
.getRedirectedUrl();
}
assertThat(nextScreenUrl).isEqualTo("/flow/testSubflowLogic/subflowAddItem");
FormScreen nextScreen = new FormScreen(mockMvc.perform(get(nextScreenUrl)));
assertThat(nextScreen.getTitle()).isEqualTo("Subflow Page");
}
}

@Nested
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ protected ResultActions postExpectingSuccess(String pageName, Map<String, List<S
// Appends the id to the post URL
protected ResultActions postToUrlExpectingSuccess(String postUrl, String redirectUrl,
Map<String, List<String>> params, String uuid) throws Exception {
return postToUrlExpectingSuccess(postUrl + "/" + uuid, redirectUrl, params);
String uuidString = uuid == null ? "" : '/' + uuid;
return postToUrlExpectingSuccess(postUrl + uuidString, redirectUrl, params);
}

protected ResultActions postToUrlExpectingSuccess(String postUrl, String redirectUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<main id="content" role="main" class="form-card spacing-above-35">
<th:block
th:replace="~{fragments/cardHeader :: cardHeader(header='Subflow Page', subtext='This is a page within a subflow')}"/>
<!-- Test that the currentSubflowItem is passed in by the controller: -->
<div th:text="${currentSubflowItem.firstNameSubflow}"></div>
<!-- Test that the currentSubflowItem is passed in by the controller: -->
<div th:text="${currentSubflowItem}"></div>
<div>
<th:block
th:replace="~{fragments/inputs/text ::
Expand Down

0 comments on commit 63ad9b6

Please sign in to comment.