|
| 1 | +package uk.gov.hmcts.reform.pcs.ccd; |
| 2 | + |
| 3 | +import org.assertj.core.api.SoftAssertions; |
| 4 | +import org.junit.jupiter.params.ParameterizedTest; |
| 5 | +import org.junit.jupiter.params.provider.Arguments; |
| 6 | +import org.junit.jupiter.params.provider.MethodSource; |
| 7 | +import org.springframework.beans.factory.annotation.Autowired; |
| 8 | +import org.springframework.boot.test.context.SpringBootTest; |
| 9 | +import uk.gov.hmcts.ccd.sdk.CCDDefinitionGenerator; |
| 10 | +import uk.gov.hmcts.ccd.sdk.ResolvedCCDConfig; |
| 11 | +import uk.gov.hmcts.ccd.sdk.api.Event; |
| 12 | +import uk.gov.hmcts.ccd.sdk.api.Field; |
| 13 | +import uk.gov.hmcts.ccd.sdk.api.FieldCollection; |
| 14 | +import uk.gov.hmcts.reform.pcs.ccd.accesscontrol.UserRole; |
| 15 | +import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; |
| 16 | +import uk.gov.hmcts.reform.pcs.ccd.domain.State; |
| 17 | +import uk.gov.hmcts.reform.pcs.ccd.event.EventId; |
| 18 | +import uk.gov.hmcts.reform.pcs.ccd.page.CommonPageContent; |
| 19 | + |
| 20 | +import java.util.List; |
| 21 | +import java.util.Map; |
| 22 | +import java.util.stream.Collectors; |
| 23 | +import java.util.stream.Stream; |
| 24 | + |
| 25 | +import static org.assertj.core.api.Assertions.assertThat; |
| 26 | +import static org.junit.jupiter.params.provider.Arguments.arguments; |
| 27 | + |
| 28 | +@SpringBootTest |
| 29 | +@SuppressWarnings({"rawtypes"}) |
| 30 | +class CaseDefinitionIT { |
| 31 | + |
| 32 | + @Autowired |
| 33 | + private CCDDefinitionGenerator ccdDefinitionGenerator; |
| 34 | + |
| 35 | + @ParameterizedTest |
| 36 | + @MethodSource("saveAndResumeEventScenarios") |
| 37 | + void eventPagesShouldHaveSaveAndResumeHintText(EventId eventId, List<String> excludedPageIds) { |
| 38 | + Map<String, List<Field>> pageFieldsMap = getPageToFieldsMap(eventId); |
| 39 | + |
| 40 | + SoftAssertions softAssertions = new SoftAssertions(); |
| 41 | + |
| 42 | + pageFieldsMap.entrySet() |
| 43 | + .stream() |
| 44 | + .filter(entry -> !excludedPageIds.contains(entry.getKey())) |
| 45 | + .forEach(entry -> { |
| 46 | + String pageId = entry.getKey(); |
| 47 | + List<Field> pageFields = entry.getValue(); |
| 48 | + |
| 49 | + boolean hintTextFound = containsSaveAndResumeHint(pageFields); |
| 50 | + softAssertions.assertThat(hintTextFound) |
| 51 | + .withFailMessage("Page %s should have save and resume hint", pageId) |
| 52 | + .isTrue(); |
| 53 | + }); |
| 54 | + |
| 55 | + softAssertions.assertAll(); |
| 56 | + } |
| 57 | + |
| 58 | + private static Stream<Arguments> saveAndResumeEventScenarios() { |
| 59 | + return Stream.of( |
| 60 | + // Event ID, Excluded Page IDs |
| 61 | + arguments( |
| 62 | + EventId.resumePossessionClaim, |
| 63 | + List.of( |
| 64 | + "resumeClaim", |
| 65 | + "claimantTypeNotEligibleEngland", |
| 66 | + "claimantTypeNotEligibleWales", |
| 67 | + "claimTypeNotEligibleEngland", |
| 68 | + "claimTypeNotEligibleWales" |
| 69 | + ) |
| 70 | + ), |
| 71 | + |
| 72 | + arguments( |
| 73 | + EventId.enforceTheOrder, |
| 74 | + List.of( |
| 75 | + "enforcementApplication", |
| 76 | + "evictionDelayWarning", |
| 77 | + "checkYourAnswersPlaceHolder" |
| 78 | + ) |
| 79 | + |
| 80 | + ) |
| 81 | + ); |
| 82 | + } |
| 83 | + |
| 84 | + private Map<String, List<Field>> getPageToFieldsMap(EventId eventId) { |
| 85 | + ResolvedCCDConfig<PCSCase, State, UserRole> ccdConfig = getCCDConfig(); |
| 86 | + |
| 87 | + Event<PCSCase, UserRole, State> event = ccdConfig.getEvents().get(eventId.name()); |
| 88 | + assertThat(event).isNotNull(); |
| 89 | + |
| 90 | + FieldCollection fieldCollection = event.getFields(); |
| 91 | + |
| 92 | + return fieldCollection.getFields().stream() |
| 93 | + .map(Field.FieldBuilder::build) |
| 94 | + .collect(Collectors.groupingBy(Field::getPage)); |
| 95 | + } |
| 96 | + |
| 97 | + @SuppressWarnings("unchecked") |
| 98 | + private ResolvedCCDConfig<PCSCase, State, UserRole> getCCDConfig() { |
| 99 | + return (ResolvedCCDConfig<PCSCase, State, UserRole>) ccdDefinitionGenerator.loadConfigs().getFirst(); |
| 100 | + } |
| 101 | + |
| 102 | + private boolean containsSaveAndResumeHint(List<Field> pageFields) { |
| 103 | + return pageFields.stream() |
| 104 | + .anyMatch(field -> CommonPageContent.SAVE_AND_RETURN.equals(field.getLabel())); |
| 105 | + } |
| 106 | + |
| 107 | + |
| 108 | +} |
0 commit comments