-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LP-486 Choose principal place of business page #186
base: main
Are you sure you want to change the base?
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import request from "supertest"; | ||
import enTranslationText from "../../../../../../locales/en/translations.json"; | ||
import cyTranslationText from "../../../../../../locales/cy/translations.json"; | ||
import app from "../../app"; | ||
import { | ||
CHOOSE_PRINCIPAL_PLACE_OF_BUSINESS_ADDRESS_URL | ||
} from "presentation/controller/addressLookUp/url"; | ||
import { GENERAL_PARTNERS_URL } from "../../../../controller/registration/url"; | ||
import { getUrl, setLocalesEnabled, testTranslations } from "../../../utils"; | ||
import { appDevDependencies } from "config/dev-dependencies"; | ||
import * as config from "config"; | ||
import AddressPageType from "presentation/controller/addressLookUp/PageType"; | ||
|
||
describe("Choose Principal Place Of Business Address Page", () => { | ||
const URL = getUrl(CHOOSE_PRINCIPAL_PLACE_OF_BUSINESS_ADDRESS_URL); | ||
const REDIRECT_URL = getUrl(GENERAL_PARTNERS_URL); | ||
|
||
beforeEach(() => { | ||
setLocalesEnabled(false); | ||
appDevDependencies.addressLookUpGateway.setError(false); | ||
appDevDependencies.cacheRepository.feedCache({ | ||
[`${config.APPLICATION_CACHE_KEY_PREFIX_REGISTRATION}registered_office_address`]: | ||
{ | ||
postal_code: "ST6 3LJ", | ||
premises: "", | ||
address_line_1: "", | ||
address_line_2: "", | ||
locality: "", | ||
country: "" | ||
} | ||
}); | ||
}); | ||
|
||
describe("GET Choose Principal Place Of Business Address Page", () => { | ||
it("should load the choose principal place of business address page with Welsh text", async () => { | ||
setLocalesEnabled(true); | ||
|
||
const res = await request(app).get(URL + "?lang=cy"); | ||
|
||
expect(res.status).toBe(200); | ||
testTranslations( | ||
res.text, | ||
cyTranslationText.choosePrincipalPlaceOfBusinessPage | ||
); | ||
}); | ||
|
||
it("should load the choose principal place of business address page with English text", async () => { | ||
setLocalesEnabled(true); | ||
|
||
const res = await request(app).get(URL + "?lang=en"); | ||
|
||
expect(res.status).toBe(200); | ||
testTranslations( | ||
res.text, | ||
enTranslationText.choosePrincipalPlaceOfBusinessPage | ||
); | ||
}); | ||
|
||
it("should populate the address list", async () => { | ||
const res = await request(app).get(URL); | ||
|
||
expect(res.status).toBe(200); | ||
expect(res.text).toContain("2 Duncalf street, Stoke-on-trent, ST6 3LJ"); | ||
expect(res.text).toContain( | ||
"The lodge Duncalf street, Castle hill, Stoke-on-trent, ST6 3LJ" | ||
); | ||
expect(res.text).toContain("4 Duncalf street, Stoke-on-trent, ST6 3LJ"); | ||
expect(res.text).toContain("6 Duncalf street, Stoke-on-trent, ST6 3LJ"); | ||
}); | ||
|
||
it("should return error page when gateway getListOfValidPostcodeAddresses throws an error", async () => { | ||
appDevDependencies.addressLookUpGateway.setError(true); | ||
|
||
const res = await request(app).get(URL); | ||
|
||
expect(res.status).toBe(500); | ||
expect(res.text).toContain(enTranslationText.errorPage.title); | ||
}); | ||
}); | ||
|
||
describe("POST Choose Principal Place Of Business Page", () => { | ||
it("should redirect to the next page and add select address to cache", async () => { | ||
const res = await request(app) | ||
.post(URL) | ||
.send({ | ||
pageType: AddressPageType.choosePrincipalPlaceOfBusinessAddress, | ||
selected_address: `{ | ||
"postal_code": "ST6 3LJ", | ||
"premises": "4", | ||
"address_line_1": "DUNCALF STREET", | ||
"address_line_2": "", | ||
"locality": "STOKE-ON-TRENT", | ||
"country": "GB-ENG" | ||
}` | ||
}); | ||
|
||
expect(res.status).toBe(302); | ||
expect(res.text).toContain(`Redirecting to ${REDIRECT_URL}`); | ||
|
||
// Will need to be uncommented when the confirm page is introduced | ||
/* const cache = appDevDependencies.cacheRepository.cache; | ||
expect(cache?.[`${config.APPLICATION_CACHE_KEY}`]).toHaveProperty( | ||
`${config.APPLICATION_CACHE_KEY_PREFIX_REGISTRATION}principal_place_of_business_address`, | ||
{ | ||
postal_code: "ST6 3LJ", | ||
premises: "4", | ||
address_line_1: "DUNCALF STREET", | ||
address_line_2: "", | ||
locality: "STOKE-ON-TRENT", | ||
country: "GB-ENG" | ||
} | ||
); */ | ||
}); | ||
|
||
it("should redirect to the error page if address can't be deserialised", async () => { | ||
const res = await request(app).post(URL).send({ | ||
pageType: AddressPageType.choosePrincipalPlaceOfBusinessAddress, | ||
selected_address: `some address` | ||
}); | ||
|
||
expect(res.status).toBe(500); | ||
expect(res.text).toContain(enTranslationText.errorPage.title); | ||
|
||
const cache = appDevDependencies.cacheRepository.cache; | ||
expect(cache?.[`${config.APPLICATION_CACHE_KEY}`]).not.toHaveProperty( | ||
`${config.APPLICATION_CACHE_KEY_PREFIX_REGISTRATION}${AddressPageType.choosePrincipalPlaceOfBusinessAddress}` | ||
); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{% extends "layout.njk" %} | ||
|
||
{% import 'includes/macros.njk' as macros %} | ||
|
||
{% set pageTitle = i18n.choosePrincipalPlaceOfBusinessPage.title %} | ||
|
||
{% set addressItems = [] %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be extracted into a common component used by the various choose pages |
||
{% for address in props.data.addressList %} | ||
{% set newItem = { | ||
value: address | dump, | ||
text: macros.formatAddress(address), | ||
attributes: { | ||
required: true, | ||
"radio-event-id": "address-radio-selected" | ||
} | ||
} %} | ||
{% set addressItems = addressItems.concat([newItem]) %} | ||
{% endfor %} | ||
|
||
{% 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" %} | ||
|
||
{% include "includes/proposed-name.njk" %} | ||
|
||
{{ govukRadios({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be extracted into a common component used by the various choose pages |
||
classes: "govuk-radios", | ||
name: "selected_address", | ||
value: props.data.cache['registration_choose-principal-place-of-business-address'] | dump, | ||
fieldset: { | ||
legend: { | ||
text: i18n.choosePrincipalPlaceOfBusinessPage.title, | ||
isPageHeading: true, | ||
classes: "govuk-fieldset__legend--xl" | ||
} | ||
}, | ||
items: addressItems | ||
}) }} | ||
|
||
<p> | ||
<a href="{{ props.currentUrl | replace(props.pageType, props.data.enterPrincipalPlaceOfBusinessPageType) }}" class="govuk-body-m govuk-link" data-event-id="address-not-on-list">{{ i18n.choosePrincipalPlaceOfBusinessPage.addressLink }}</a> | ||
<p> | ||
|
||
{{ govukButton({ | ||
text: i18n.buttons.continue, | ||
attributes: { | ||
"id": "submit", | ||
"onclick": "_paq.push(['trackEvent', 'Limited Partnerships', '" + props.pageType + "', document.querySelector('input[name=selected_address]:checked').getAttribute('radio-event-id')])" | ||
} | ||
}) }} | ||
</form> | ||
</div> | ||
</div> | ||
{% endblock %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will update this, it is breaking tests atm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looked this is used by the controller for the address lookup it might need renaming to something more generic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add an if statement into the address controller here https://github.com/companieshouse/limited-partnerships-web/blob/main/src/presentation/controller/addressLookUp/Controller.ts#L250, to say, if pagetype == your page, use a different cache key for the address?