diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/ShowConditions.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/ShowConditions.java index b83b1d069d..42aedb0147 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/ShowConditions.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/ShowConditions.java @@ -25,4 +25,8 @@ public static String fieldContains(String fieldId, Enum value) { return "%sCONTAINS\"%s\"".formatted(fieldId, value.name()); } + public static String and(String... conditions) { + return String.join(" AND ", conditions); + } + } diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/genapp/XuiGenAppRequest.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/genapp/XuiGenAppRequest.java index 489fdced3c..f3da373f22 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/genapp/XuiGenAppRequest.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/genapp/XuiGenAppRequest.java @@ -33,9 +33,15 @@ public class XuiGenAppRequest implements GenAppRequest { @CCD(label = "Does the defendant need help paying the fee for this application?") private VerticalYesNo needHwf; + @CCD(label = "Have they already applied for help with their application fee?") private VerticalYesNo appliedForHwf; - @CCD(max = 100) + @CCD( + label = "Enter their Help with Fees reference number", + hint = "The defendant will have received this number when they applied for Help with Fees. This reference " + + "must not have been used for a previous application. For example, HWF-A1B-23C", + max = 60 + ) private String hwfReference; private VerticalYesNo otherPartiesAgreed; @@ -65,4 +71,7 @@ public class XuiGenAppRequest implements GenAppRequest { @CCD(searchable = false) private String maxFee; + @CCD(searchable = false) + private VerticalYesNo showHwfScreens; + } diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/genapp/MakeAnApplication.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/genapp/MakeAnApplication.java index f1c328295a..85bda0de10 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/genapp/MakeAnApplication.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/genapp/MakeAnApplication.java @@ -19,10 +19,12 @@ import uk.gov.hmcts.reform.pcs.ccd.entity.GenAppEntity; import uk.gov.hmcts.reform.pcs.ccd.entity.PcsCaseEntity; import uk.gov.hmcts.reform.pcs.ccd.entity.party.PartyEntity; +import uk.gov.hmcts.reform.pcs.ccd.page.makeanapplication.AppliedForHelpWithFees; import uk.gov.hmcts.reform.pcs.ccd.page.makeanapplication.ChooseAnApplication; import uk.gov.hmcts.reform.pcs.ccd.page.makeanapplication.DocumentUploadWanted; import uk.gov.hmcts.reform.pcs.ccd.page.makeanapplication.HearingInNext14Days; import uk.gov.hmcts.reform.pcs.ccd.page.makeanapplication.HelpWithFeesNeeded; +import uk.gov.hmcts.reform.pcs.ccd.page.makeanapplication.MustApplyForHelpWithFees; import uk.gov.hmcts.reform.pcs.ccd.page.makeanapplication.OtherPartiesAgreed; import uk.gov.hmcts.reform.pcs.ccd.page.makeanapplication.SelectParty; import uk.gov.hmcts.reform.pcs.ccd.page.makeanapplication.StartAdjourn; @@ -81,6 +83,8 @@ public void configureDecentralised(DecentralisedConfigBuilder eventPayload) { applyApplicationFeeAmounts(caseData); + caseData.getXuiGenAppRequest().setShowHwfScreens(VerticalYesNo.YES); + return caseData; } diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/page/makeanapplication/AppliedForHelpWithFees.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/page/makeanapplication/AppliedForHelpWithFees.java new file mode 100644 index 0000000000..1231b04742 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/page/makeanapplication/AppliedForHelpWithFees.java @@ -0,0 +1,34 @@ +package uk.gov.hmcts.reform.pcs.ccd.page.makeanapplication; + +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import uk.gov.hmcts.reform.pcs.ccd.ShowConditions; +import uk.gov.hmcts.reform.pcs.ccd.common.CcdPageConfiguration; +import uk.gov.hmcts.reform.pcs.ccd.common.PageBuilder; +import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; +import uk.gov.hmcts.reform.pcs.ccd.domain.VerticalYesNo; +import uk.gov.hmcts.reform.pcs.ccd.domain.genapp.XuiGenAppRequest; + +import static uk.gov.hmcts.reform.pcs.ccd.ShowConditions.fieldEquals; + +@Slf4j +@AllArgsConstructor +public class AppliedForHelpWithFees implements CcdPageConfiguration { + + @Override + public void addTo(PageBuilder pageBuilder) { + pageBuilder + .page("appliedForHelpWithFees") + .pageLabel("Confirm if they have they already applied for help with their application fee") + .showCondition(ShowConditions.and( + fieldEquals("xui_genapp_ShowHwfScreens", VerticalYesNo.YES), + fieldEquals("xui_genapp_NeedHwf", VerticalYesNo.YES) + )) + .label("appliedForHelpWithFees-lineSeparator", "---") + .complex(PCSCase::getXuiGenAppRequest) + .mandatory(XuiGenAppRequest::getAppliedForHwf) + .mandatory(XuiGenAppRequest::getHwfReference, fieldEquals("xui_genapp_AppliedForHwf", VerticalYesNo.YES)) + .done(); + } + +} diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/page/makeanapplication/ChooseAnApplication.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/page/makeanapplication/ChooseAnApplication.java index 2201adc2f5..29dca46aea 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/page/makeanapplication/ChooseAnApplication.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/page/makeanapplication/ChooseAnApplication.java @@ -45,6 +45,7 @@ public void addTo(PageBuilder pageBuilder) { .complex(PCSCase::getXuiGenAppRequest) .readonly(XuiGenAppRequest::getStandardFee, NEVER_SHOW, true) .readonly(XuiGenAppRequest::getMaxFee, NEVER_SHOW, true) + .readonly(XuiGenAppRequest::getShowHwfScreens, NEVER_SHOW, true) .mandatory(XuiGenAppRequest::getApplicationType) .done(); } diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/page/makeanapplication/HearingInNext14Days.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/page/makeanapplication/HearingInNext14Days.java index 96c157a171..91c446bab9 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/page/makeanapplication/HearingInNext14Days.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/page/makeanapplication/HearingInNext14Days.java @@ -2,9 +2,12 @@ import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import uk.gov.hmcts.ccd.sdk.api.CaseDetails; +import uk.gov.hmcts.ccd.sdk.api.callback.AboutToStartOrSubmitResponse; import uk.gov.hmcts.reform.pcs.ccd.common.CcdPageConfiguration; import uk.gov.hmcts.reform.pcs.ccd.common.PageBuilder; import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; +import uk.gov.hmcts.reform.pcs.ccd.domain.State; import uk.gov.hmcts.reform.pcs.ccd.domain.genapp.GenAppType; import uk.gov.hmcts.reform.pcs.ccd.domain.genapp.XuiGenAppRequest; @@ -17,7 +20,7 @@ public class HearingInNext14Days implements CcdPageConfiguration { @Override public void addTo(PageBuilder pageBuilder) { pageBuilder - .page("hearingInNext14Days") + .page("hearingInNext14Days", this::midEvent) .pageLabel("Is the defendant’s court hearing in the next 14 days?") .showCondition(fieldEquals("xui_genapp_ApplicationType", GenAppType.ADJOURN)) .label("hearingInNext14Days-lineSeparator", "---") @@ -26,4 +29,17 @@ public void addTo(PageBuilder pageBuilder) { .done(); } + private AboutToStartOrSubmitResponse midEvent(CaseDetails details, + CaseDetails detailsBefore) { + + PCSCase caseData = details.getData(); + XuiGenAppRequest xuiGenAppRequest = caseData.getXuiGenAppRequest(); + + xuiGenAppRequest.setShowHwfScreens(xuiGenAppRequest.getWithin14Days()); + + return AboutToStartOrSubmitResponse.builder() + .data(caseData) + .build(); + } + } diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/page/makeanapplication/HelpWithFeesNeeded.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/page/makeanapplication/HelpWithFeesNeeded.java index 5878e1ac1c..2732d3fc9c 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/page/makeanapplication/HelpWithFeesNeeded.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/page/makeanapplication/HelpWithFeesNeeded.java @@ -4,19 +4,34 @@ import lombok.extern.slf4j.Slf4j; import uk.gov.hmcts.reform.pcs.ccd.common.CcdPageConfiguration; import uk.gov.hmcts.reform.pcs.ccd.common.PageBuilder; +import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; +import uk.gov.hmcts.reform.pcs.ccd.domain.VerticalYesNo; +import uk.gov.hmcts.reform.pcs.ccd.domain.genapp.XuiGenAppRequest; + +import static uk.gov.hmcts.reform.pcs.ccd.ShowConditions.fieldEquals; @Slf4j @AllArgsConstructor public class HelpWithFeesNeeded implements CcdPageConfiguration { - private static final String PLACEHOLDER = """ -
-
-

- Placeholder -

-
-
+ private static final String INFO_MARKDOWN = """ +

It usually costs ${xui_genapp_StandardFee} to apply. The fee will + increase to ${xui_genapp_MaxFee} if:

+
    +
  • the defendant has already told the other party that they are making + this application, and
  • +
  • the other party did not agree to it + (this means that they objected to it)
  • +
+

You’ll see the final application fee before you pay.

+ +

The defendant may be able to get help paying the fee + if they (one or more of the following):

+
    +
  • are on certain benefits
  • +
  • have little or no savings
  • +
  • have low income
  • +
"""; @Override @@ -24,8 +39,12 @@ public void addTo(PageBuilder pageBuilder) { pageBuilder .page("helpWithFeesNeeded") .pageLabel("Confirm if the defendant needs help paying fees") + .showCondition(fieldEquals("xui_genapp_ShowHwfScreens", VerticalYesNo.YES)) .label("helpWithFeesNeeded-lineSeparator", "---") - .label("helpWithFeesNeeded-placeholder", PLACEHOLDER); + .label("helpWithFeesNeeded-info", INFO_MARKDOWN) + .complex(PCSCase::getXuiGenAppRequest) + .mandatory(XuiGenAppRequest::getNeedHwf) + .done(); } } diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/page/makeanapplication/MustApplyForHelpWithFees.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/page/makeanapplication/MustApplyForHelpWithFees.java new file mode 100644 index 0000000000..5dcabdf425 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/page/makeanapplication/MustApplyForHelpWithFees.java @@ -0,0 +1,67 @@ +package uk.gov.hmcts.reform.pcs.ccd.page.makeanapplication; + +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import uk.gov.hmcts.ccd.sdk.api.CaseDetails; +import uk.gov.hmcts.ccd.sdk.api.callback.AboutToStartOrSubmitResponse; +import uk.gov.hmcts.reform.pcs.ccd.ShowConditions; +import uk.gov.hmcts.reform.pcs.ccd.common.CcdPageConfiguration; +import uk.gov.hmcts.reform.pcs.ccd.common.PageBuilder; +import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; +import uk.gov.hmcts.reform.pcs.ccd.domain.State; +import uk.gov.hmcts.reform.pcs.ccd.domain.VerticalYesNo; + +import static uk.gov.hmcts.reform.pcs.ccd.ShowConditions.fieldEquals; + +@Slf4j +@AllArgsConstructor +public class MustApplyForHelpWithFees implements CcdPageConfiguration { + + private static final String INFO_MARKDOWN = """ +

+ The defendant needs to apply for Help with Fees (GOV.UK, opens in new tab) + before you can continue with this application. If you are applying for Help with Fees on the defendant’s + behalf, you should do that now before you continue with this application. +

+

+ Enter the court form number 'N244' when asked. This will be one of the first questions + when you (or they) apply for Help with Fees. +

+

+ After you (or they) have applied you (or they) will receive a Help With Fees reference number. + Enter the reference number when you return to this application. +

+

+ If they receive any benefit that qualifies them for Help with Fees, you (or they) must include + evidence of it when you (or they) apply online for Help with Fees. +

+

+ If you already have their Help with Fees reference number, you can return to the previous screen + and enter it there. +

+ """; + + @Override + public void addTo(PageBuilder pageBuilder) { + pageBuilder + .page("mustApplyForHelpWithFees", this::midEvent) + .pageLabel("The defendant needs to apply for help with their application fee") + .showCondition(ShowConditions.and( + fieldEquals("xui_genapp_ShowHwfScreens", VerticalYesNo.YES), + fieldEquals("xui_genapp_NeedHwf", VerticalYesNo.YES), + fieldEquals("xui_genapp_AppliedForHwf", VerticalYesNo.NO) + )) + .label("mustApplyForHelpWithFees-lineSeparator", "---") + .label("mustApplyForHelpWithFees-info", INFO_MARKDOWN); + } + + private AboutToStartOrSubmitResponse midEvent(CaseDetails details, + CaseDetails detailsBefore) { + + return AboutToStartOrSubmitResponse.builder() + .errorMessageOverride("You cannot continue until you have their reference number for Help with Fees") + .build(); + } + +} diff --git a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/ShowConditionsTest.java b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/ShowConditionsTest.java index e8f82dbd1e..f3633a6b9b 100644 --- a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/ShowConditionsTest.java +++ b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/ShowConditionsTest.java @@ -1,8 +1,14 @@ package uk.gov.hmcts.reform.pcs.ccd; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import uk.gov.hmcts.reform.pcs.ccd.domain.State; +import java.util.List; +import java.util.stream.Stream; + import static org.assertj.core.api.Assertions.assertThat; class ShowConditionsTest { @@ -39,6 +45,24 @@ void shouldCreateShowConditionForFieldContains() { assertThat(showCondition).isEqualTo("testFieldId1CONTAINS\"BLUE\""); } + @ParameterizedTest + @MethodSource("joinWithAndScenarios") + void shouldJoinShowConditionWithAnd(List showConditionsToJoin, String expectedJoinedShowConditions) { + String showCondition = ShowConditions.and(showConditionsToJoin.toArray(new String[0])); + + assertThat(showCondition).isEqualTo(expectedJoinedShowConditions); + } + + private static Stream joinWithAndScenarios() { + return Stream.of( + // Show conditions to join, expected joined show condition + Arguments.argumentSet("no params", List.of(), ""), + Arguments.argumentSet("one param", List.of("a"), "a"), + Arguments.argumentSet("two params", List.of("a", "b"), "a AND b"), + Arguments.argumentSet("three params", List.of("a", "b", "c"), "a AND b AND c") + ); + } + private enum TestEnum { RED, GREEN, diff --git a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/event/genapp/MakeAnApplicationTest.java b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/event/genapp/MakeAnApplicationTest.java index e7ffeadfac..3cbc11fd39 100644 --- a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/event/genapp/MakeAnApplicationTest.java +++ b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/event/genapp/MakeAnApplicationTest.java @@ -105,6 +105,7 @@ void shouldSetRepresentedPartiesFieldWhenUserRepresentsOne() { .thenReturn(Optional.of(expectedPartyNameList)); PCSCase caseData = PCSCase.builder() + .xuiGenAppRequest(XuiGenAppRequest.builder().build()) .build(); // When @@ -133,6 +134,7 @@ void shouldSetMultipleRepresentedPartiesFlag(int numRepresentedParties, Vertical .thenReturn(Optional.of(expectedPartyNameList)); PCSCase caseData = PCSCase.builder() + .xuiGenAppRequest(XuiGenAppRequest.builder().build()) .build(); // When @@ -160,6 +162,7 @@ void shouldNotSetRepresentedPartiesFieldWhenUserDoesNotRepresentAny() { .thenReturn(Optional.empty()); PCSCase caseData = PCSCase.builder() + .xuiGenAppRequest(XuiGenAppRequest.builder().build()) .build(); // When @@ -193,6 +196,20 @@ void shouldSetTheApplicationFees() { feeSetterCaptor.getValue().accept(caseData, formattedMaxFee); assertThat(caseData.getXuiGenAppRequest().getMaxFee()).isEqualTo(formattedMaxFee); } + + @Test + void shouldSetShowHwfScreensFlagToYes() { + // Given + PCSCase caseData = PCSCase.builder() + .xuiGenAppRequest(XuiGenAppRequest.builder().build()) + .build(); + + // When + callStartHandler(caseData); + + // Then + assertThat(caseData.getXuiGenAppRequest().getShowHwfScreens()).isEqualTo(VerticalYesNo.YES); + } } @Nested diff --git a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/page/makeanapplication/HearingInNext14DaysTest.java b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/page/makeanapplication/HearingInNext14DaysTest.java new file mode 100644 index 0000000000..307f9de954 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/page/makeanapplication/HearingInNext14DaysTest.java @@ -0,0 +1,40 @@ +package uk.gov.hmcts.reform.pcs.ccd.page.makeanapplication; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; +import uk.gov.hmcts.ccd.sdk.api.callback.AboutToStartOrSubmitResponse; +import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; +import uk.gov.hmcts.reform.pcs.ccd.domain.State; +import uk.gov.hmcts.reform.pcs.ccd.domain.VerticalYesNo; +import uk.gov.hmcts.reform.pcs.ccd.domain.genapp.XuiGenAppRequest; +import uk.gov.hmcts.reform.pcs.ccd.page.BasePageTest; + +import static org.assertj.core.api.Assertions.assertThat; + +class HearingInNext14DaysTest extends BasePageTest { + + @BeforeEach + void setUp() { + setPageUnderTest(new HearingInNext14Days()); + } + + @ParameterizedTest + @EnumSource(value = VerticalYesNo.class) + void shouldSetShowHwfScreens(VerticalYesNo hearingWithinNext14Days) { + // Given + PCSCase caseData = PCSCase.builder() + .xuiGenAppRequest(XuiGenAppRequest.builder() + .within14Days(hearingWithinNext14Days) + .build()) + .build(); + + // When + AboutToStartOrSubmitResponse response = callMidEventHandler(caseData); + + // Then + PCSCase updatedCaseData = response.getData(); + assertThat(updatedCaseData.getXuiGenAppRequest().getShowHwfScreens()).isEqualTo(hearingWithinNext14Days); + } + +} diff --git a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/page/makeanapplication/MustApplyForHelpWithFeesTest.java b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/page/makeanapplication/MustApplyForHelpWithFeesTest.java new file mode 100644 index 0000000000..31df897d3e --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/page/makeanapplication/MustApplyForHelpWithFeesTest.java @@ -0,0 +1,33 @@ +package uk.gov.hmcts.reform.pcs.ccd.page.makeanapplication; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import uk.gov.hmcts.ccd.sdk.api.callback.AboutToStartOrSubmitResponse; +import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; +import uk.gov.hmcts.reform.pcs.ccd.domain.State; +import uk.gov.hmcts.reform.pcs.ccd.page.BasePageTest; + +import static org.assertj.core.api.Assertions.assertThat; + +class MustApplyForHelpWithFeesTest extends BasePageTest { + + @BeforeEach + void setUp() { + setPageUnderTest(new MustApplyForHelpWithFees()); + } + + @Test + void shouldAlwaysReturnErrorFromMidEvent() { + // Given + PCSCase caseData = PCSCase.builder() + .build(); + + // When + AboutToStartOrSubmitResponse response = callMidEventHandler(caseData); + + // Then + assertThat(response.getErrorMessageOverride()) + .isEqualTo("You cannot continue until you have their reference number for Help with Fees"); + } + +}