Skip to content

Commit

Permalink
Merge pull request #89 from companieshouse/lp-236-general-partner-cho…
Browse files Browse the repository at this point in the history
…ice-page

Lp 236 general partner choice page
  • Loading branch information
mattch1 authored Dec 10, 2024
2 parents f66a4d1 + a5fef06 commit fb4e29c
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 6 deletions.
7 changes: 7 additions & 0 deletions locales/cy/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@
"pageInformation": "WELSH - If the partnership has more than one general partner, you'll add them one at a time."
},

"generalPartnerChoicePage": {
"title": "WELSH - You now need to tell us about the general partners",
"hint": "WELSH - You can add more later.",
"person": "WELSH - A person",
"legalEntity": "WELSH - A legal entity"
},

"pageNotFound" : {
"title" : "WELSH - Page Not Found",
"spelling" : "WELSH - If you typed the web address, check it is spelled correctly.",
Expand Down
7 changes: 7 additions & 0 deletions locales/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@
"pageInformation": "If the partnership has more than one general partner, you'll add them one at a time."
},

"generalPartnerChoicePage": {
"title": "Is the general partner a person or a legal entity?",
"hint": "You can add more later.",
"person": "A person",
"legalEntity": "A legal entity"
},

"pageNotFound" : {
"title" : "Page not found",
"spelling" : "If you typed the web address, check it is spelled correctly.",
Expand Down
1 change: 1 addition & 0 deletions src/presentation/controller/registration/PageType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ enum RegistrationPageType {
name = "name",
email = "email",
generalPartners = "general-partners",
generalPartnerChoice = "general-partner-choice",
next = "next",
}

Expand Down
12 changes: 11 additions & 1 deletion src/presentation/controller/registration/Routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const WHICH_TYPE_TEMPLATE = RegistrationPageType.whichType;
export const NAME_TEMPLATE = RegistrationPageType.name;
export const EMAIL_TEMPLATE = RegistrationPageType.email;
export const GENERAL_PARTNERS_TEMPLATE = RegistrationPageType.generalPartners;
export const GENERAL_PARTNER_CHOICE_TEMPLATE = RegistrationPageType.generalPartnerChoice;

export const NEXT_TEMPLATE = RegistrationPageType.next;

Expand All @@ -20,6 +21,7 @@ export const NAME_URL = `${BASE_URL}/${NAME_TEMPLATE}`;
export const EMAIL_URL = `${BASE_WITH_IDS_URL}/${EMAIL_TEMPLATE}`;

export const GENERAL_PARTNERS_URL = `${BASE_WITH_IDS_URL}/${GENERAL_PARTNERS_TEMPLATE}`;
export const GENERAL_PARTNER_CHOICE_URL = `${BASE_WITH_IDS_URL}/${GENERAL_PARTNER_CHOICE_TEMPLATE}`;

export const NEXT_URL = `${BASE_WITH_IDS_URL}/${NEXT_TEMPLATE}`;

Expand Down Expand Up @@ -47,10 +49,17 @@ const registrationRoutingEmail = {
const registrationRoutingGeneralPartners = {
previousUrl: EMAIL_URL,
currentUrl: GENERAL_PARTNERS_URL,
nextUrl: NEXT_URL,
nextUrl: GENERAL_PARTNER_CHOICE_URL,
pageType: RegistrationPageType.generalPartners,
};

const registrationRoutingGeneralPartnerChoice = {
previousUrl: GENERAL_PARTNERS_URL,
currentUrl: GENERAL_PARTNER_CHOICE_URL,
nextUrl: NEXT_URL,
pageType: RegistrationPageType.generalPartnerChoice,
};

const registrationRoutingNext = {
previousUrl: GENERAL_PARTNERS_URL,
currentUrl: NEXT_URL,
Expand All @@ -63,6 +72,7 @@ const list = [
registrationRoutingName,
registrationRoutingEmail,
registrationRoutingGeneralPartners,
registrationRoutingGeneralPartnerChoice,
registrationRoutingNext,
];

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import request from "supertest";
import { LocalesService } from "@companieshouse/ch-node-utils";
import * as config from "../../../../config/constants";
import enTranslationText from "../../../../../locales/en/translations.json";
import cyTranslationText from "../../../../../locales/cy/translations.json";
import app from "../app";
import {
GENERAL_PARTNER_CHOICE_URL,
NEXT_URL,
} from "../../../controller/registration/Routing";
import RegistrationPageType from "../../../../presentation/controller/registration/PageType";

describe("General Partner Choice Page", () => {
beforeEach(() => {
setLocalesEnabled(false);
});

const setLocalesEnabled = (bool: boolean) => {
jest.spyOn(config, "isLocalesEnabled").mockReturnValue(bool);
LocalesService.getInstance().enabled = bool;
};

it("should load the general partner choice page with Welsh text", async () => {
setLocalesEnabled(true);
const res = await request(app).get(GENERAL_PARTNER_CHOICE_URL + "?lang=cy");

expect(res.status).toBe(200);
expect(res.text).toContain(cyTranslationText.generalPartnerChoicePage.title);
});

it("should load the general partner choice page with English text", async () => {
setLocalesEnabled(true);
const res = await request(app).get(GENERAL_PARTNER_CHOICE_URL + "?lang=en");

expect(res.status).toBe(200);
expect(res.text).toContain(enTranslationText.generalPartnerChoicePage.title);
});

it("should redirect to next page when choice is selected", async () => {
const selectedType = "person";
const res = await request(app).post(GENERAL_PARTNER_CHOICE_URL).send({
pageType: RegistrationPageType.generalPartnerChoice,
parameter: selectedType,
});

const redirectUrl = `${NEXT_URL}?${RegistrationPageType.generalPartnerChoice}=${selectedType}`;
expect(res.status).toBe(302);
expect(res.text).toContain(redirectUrl);
});
});
19 changes: 14 additions & 5 deletions src/routes/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
NEXT_URL,
WHICH_TYPE_URL,
GENERAL_PARTNERS_URL,
GENERAL_PARTNER_CHOICE_URL,
} from "../presentation/controller/registration/Routing";

export const registrationEndpoints = (
Expand All @@ -36,23 +37,31 @@ export const registrationEndpoints = (
authentication,
dependencies.registrationController.createTransactionAndFirstSubmission()
);
router.get(
EMAIL_URL,
authentication,
dependencies.registrationController.getPageRouting()
);
router.post(
EMAIL_URL,
authentication,
dependencies.registrationController.sendPageData()
);
router.get(
GENERAL_PARTNERS_URL,
authentication,
dependencies.registrationController.getPageRouting()
);

router.get(
EMAIL_URL,
GENERAL_PARTNER_CHOICE_URL,
authentication,
dependencies.registrationController.getPageRouting()
);
router.post(
EMAIL_URL,
GENERAL_PARTNER_CHOICE_URL,
authentication,
dependencies.registrationController.sendPageData()
dependencies.registrationController.redirectWithParameter()
);

router.get(
NEXT_URL,
authentication,
Expand Down
52 changes: 52 additions & 0 deletions src/views/general-partner-choice.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{% extends "layout.njk" %}

{% block content %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<form class="form" action={{ props.currentUrl }} method="post">
<input type="hidden" name="pageType" value={{ props.pageType }}>

{% include "includes/csrf_token.njk" %}

{{ govukRadios({
classes: "govuk-radios",
name: "parameter",
value: data['generalPartner'],
fieldset: {
legend: {
text: i18n.generalPartnerChoicePage.title,
isPageHeading: true,
classes: "govuk-fieldset__legend--xl"
}
},
hint: {
text: i18n.generalPartnerChoicePage.hint
},

items: [
{
value: "person",
text: i18n.generalPartnerChoicePage.person,
id: "person",
name: "person",
attributes: {
required: true
}
},
{
value: "legalEntity",
text: i18n.generalPartnerChoicePage.legalEntity,
id: "legal_entity",
name: "legal_entity",
attributes: {
required: true
}
}
]
}) }}

{% include "includes/continue-button.njk" %}
</form>
</div>
</div>
{% endblock %}

0 comments on commit fb4e29c

Please sign in to comment.