Skip to content

Commit

Permalink
MLPAB-2065 Pages to select which language the LPA will be in (#1348)
Browse files Browse the repository at this point in the history
  • Loading branch information
hawx authored Jul 12, 2024
1 parent e0533b5 commit ec196d6
Show file tree
Hide file tree
Showing 27 changed files with 496 additions and 67 deletions.
4 changes: 2 additions & 2 deletions cypress/e2e/attorney/language-preferences.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ describe('Your preferred language', () => {
cy.checkA11yApp();

cy.get('.govuk-error-summary').within(() => {
cy.contains('Select which language you’d like us to use when we contact you');
cy.contains('Select which language you would like us to use when we contact you');
});

cy.contains('.govuk-fieldset .govuk-error-message', 'Select which language you’d like us to use when we contact you');
cy.contains('.govuk-fieldset .govuk-error-message', 'Select which language you would like us to use when we contact you');
})
})
4 changes: 2 additions & 2 deletions cypress/e2e/certificate-provider/language-preferences.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ describe('Your preferred language', () => {
cy.checkA11yApp();

cy.get('.govuk-error-summary').within(() => {
cy.contains('Select which language you’d like us to use when we contact you');
cy.contains('Select which language you would like us to use when we contact you');
});

cy.contains('.govuk-fieldset .govuk-error-message', 'Select which language you’d like us to use when we contact you');
cy.contains('.govuk-fieldset .govuk-error-message', 'Select which language you would like us to use when we contact you');
})
})
28 changes: 19 additions & 9 deletions cypress/e2e/donor/confirm-your-identity-and-sign.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ describe('Confirm your identity and sign', () => {
cy.contains('h3', "Replacement attorney");
cy.contains('a', 'Continue').click();

cy.url().should('contain', '/your-lpa-language');
cy.contains('label', 'Continue and register my LPA in English').click();
cy.contains('button', 'Save and continue').click();

cy.url().should('contain', '/your-legal-rights-and-responsibilities');
cy.checkA11yApp();
cy.contains('a', 'Continue to signing page').click();
Expand Down Expand Up @@ -104,6 +108,8 @@ describe('Confirm your identity and sign', () => {

cy.contains('button', 'Continue').click();
cy.contains('a', 'Continue').click();
cy.contains('label', 'Continue and register my LPA in English').click();
cy.contains('button', 'Save and continue').click();
cy.contains('a', 'Continue to signing page').click();
cy.contains('label', 'I want to sign this LPA as a deed').click();
cy.contains('label', 'I want to apply to register this LPA').click();
Expand Down Expand Up @@ -144,6 +150,10 @@ describe('Confirm your identity and sign', () => {
cy.contains('h3', "Replacement attorney");
cy.contains('a', 'Continue').click();

cy.url().should('contain', '/your-lpa-language');
cy.contains('label', 'Continue and register my LPA in English').click();
cy.contains('button', 'Save and continue').click();

cy.url().should('contain', '/your-legal-rights-and-responsibilities');
cy.checkA11yApp();
cy.contains('a', 'Continue to signing page').click();
Expand Down Expand Up @@ -287,9 +297,9 @@ describe('Confirm your identity and sign', () => {
it('can update LPA details', () => {
cy.visit('/fixtures?redirect=/task-list&progress=payForTheLpa');
cy.contains('li', "Confirm your identity and sign")
.should('contain', 'Not started')
.find('a')
.click();
.should('contain', 'Not started')
.find('a')
.click();

cy.url().should('contain', '/how-to-confirm-your-identity-and-sign');
cy.checkA11yApp();
Expand Down Expand Up @@ -326,9 +336,9 @@ describe('Confirm your identity and sign', () => {
it('can withdraw LPA', () => {
cy.visit('/fixtures?redirect=/task-list&progress=payForTheLpa');
cy.contains('li', "Confirm your identity and sign")
.should('contain', 'Not started')
.find('a')
.click();
.should('contain', 'Not started')
.find('a')
.click();

cy.url().should('contain', '/how-to-confirm-your-identity-and-sign');
cy.checkA11yApp();
Expand Down Expand Up @@ -360,9 +370,9 @@ describe('Confirm your identity and sign', () => {
it('errors when option not selected', () => {
cy.visit('/fixtures?redirect=/task-list&progress=payForTheLpa');
cy.contains('li', "Confirm your identity and sign")
.should('contain', 'Not started')
.find('a')
.click();
.should('contain', 'Not started')
.find('a')
.click();

cy.url().should('contain', '/how-to-confirm-your-identity-and-sign');
cy.checkA11yApp();
Expand Down
11 changes: 7 additions & 4 deletions cypress/e2e/donor/language-preferences.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ describe('Your preferred language', () => {
cy.url().should('contain', '/your-preferred-language')
});

it('can choose a language contact preference', () => {
cy.get('[name="language-preference"]').check('en', { force: true })
it('can choose language preferences', () => {
cy.get('[name="contact-language"]').check('en', { force: true })
cy.get('[name="lpa-language"]').check('en', { force: true })

cy.checkA11yApp();

Expand All @@ -21,9 +22,11 @@ describe('Your preferred language', () => {
cy.checkA11yApp();

cy.get('.govuk-error-summary').within(() => {
cy.contains('Select which language you’d like us to use when we contact you');
cy.contains('Select which language you would like us to use when we contact you');
cy.contains('Select the language in which you would like your LPA registered');
});

cy.contains('.govuk-fieldset .govuk-error-message', 'Select which language you’d like us to use when we contact you');
cy.contains('.govuk-fieldset .govuk-error-message', 'Select which language you would like us to use when we contact you');
cy.contains('.govuk-fieldset .govuk-error-message', 'Select the language in which you would like your LPA registered');
})
})
3 changes: 2 additions & 1 deletion cypress/e2e/donor/provide-your-details.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ describe('Provide your details', () => {

AddressFormAssertions.assertCanAddAddressFromSelect();

cy.get('[name="language-preference"]').check('en', { force: true });
cy.get('[name="contact-language"]').check('en', { force: true });
cy.get('[name="lpa-language"]').check('en', { force: true });
cy.contains('button', 'Save and continue').click();

cy.get('#f-lpa-type').check('property-and-affairs', { force: true });
Expand Down
4 changes: 4 additions & 0 deletions cypress/e2e/donor/signing-on-behalf.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ describe('Signing on behalf of the donor', () => {
cy.url().should('contain', '/read-your-lpa');
cy.contains('a', 'Continue').click();

cy.url().should('contain', '/your-lpa-language');
cy.contains('label', 'Continue and register my LPA in English').click();
cy.contains('button', 'Save and continue').click();

cy.url().should('contain', '/your-legal-rights-and-responsibilities');
cy.contains('a', 'Continue to signing page').click();
});
Expand Down
3 changes: 2 additions & 1 deletion cypress/e2e/supporter/dashboard.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ describe('Dashboard', () => {

AddressFormAssertions.assertCanAddAddressFromSelect()

cy.get('[name="language-preference"]').check('en', { force: true })
cy.get('[name="contact-language"]').check('en', { force: true })
cy.get('[name="lpa-language"]').check('en', { force: true })
cy.contains('button', 'Save and continue').click()

cy.get('#f-lpa-type').check('property-and-affairs');
Expand Down
2 changes: 2 additions & 0 deletions internal/actor/donor.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type Donor struct {
Channel Channel
// ContactLanguagePreference is the language the donor prefers to receive notifications in
ContactLanguagePreference localize.Lang
// LpaLanguagePreference is the language the donor prefers to receive the registered LPA in
LpaLanguagePreference localize.Lang
}

func (d Donor) FullName() string {
Expand Down
8 changes: 4 additions & 4 deletions internal/actor/donor_provided_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ func TestGenerateHash(t *testing.T) {
}

// DO change this value to match the updates
const modified uint64 = 0xe8ee03e19c4313a1
const modified uint64 = 0x60cf41a52d0f9ed2

// DO NOT change these initial hash values. If a field has been added/removed
// you will need to handle the version gracefully by modifying
// (*DonorProvidedDetails).HashInclude and adding another testcase for the new
// version.
testcases := map[uint8]uint64{
0: 0x240e672086c6a594,
0: 0x946ff61139e1f784,
}

for version, initial := range testcases {
Expand Down Expand Up @@ -91,13 +91,13 @@ func TestGenerateCheckedHash(t *testing.T) {
}

// DO change this value to match the updates
const modified uint64 = 0xed6b4d9634dfbb96
const modified uint64 = 0x4af298e82cc36153

// DO NOT change these initial hash values. If a field has been added/removed
// you will need to handle the version gracefully by modifying
// toCheck.HashInclude and adding another testcase for the new version.
testcases := map[uint8]uint64{
0: 0x8146b900161c34e3,
0: 0x49f8cef460cf416e,
}

for version, initial := range testcases {
Expand Down
1 change: 0 additions & 1 deletion internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ func App(
donor.Register(
rootMux,
logger,
tmpls,
donorTmpls,
sessionStore,
donorStore,
Expand Down
2 changes: 1 addition & 1 deletion internal/page/attorney/your_preferred_language.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func YourPreferredLanguage(tmpl template.Template, attorneyStore AttorneyStore,
}

if r.Method == http.MethodPost {
data.Form = form.ReadLanguagePreferenceForm(r, "whichLanguageYoudLikeUsToUseWhenWeContactYou")
data.Form = form.ReadLanguagePreferenceForm(r, "whichLanguageYouWouldLikeUsToUseWhenWeContactYou")
data.Errors = data.Form.Validate()

if data.Errors.None() {
Expand Down
4 changes: 2 additions & 2 deletions internal/page/attorney/your_preferred_language_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ func TestPostYourPreferredLanguageWhenInvalidData(t *testing.T) {
App: testAppData,
Form: &form.LanguagePreferenceForm{
Error: errors.New("invalid Lang 'not-a-lang'"),
ErrorLabel: "whichLanguageYoudLikeUsToUseWhenWeContactYou",
ErrorLabel: "whichLanguageYouWouldLikeUsToUseWhenWeContactYou",
},
Options: localize.LangValues,
FieldName: form.FieldNames.LanguagePreference,
Errors: validation.With(form.FieldNames.LanguagePreference, validation.SelectError{Label: "whichLanguageYoudLikeUsToUseWhenWeContactYou"}),
Errors: validation.With(form.FieldNames.LanguagePreference, validation.SelectError{Label: "whichLanguageYouWouldLikeUsToUseWhenWeContactYou"}),
Lpa: &lpastore.Lpa{},
}).
Return(nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func YourPreferredLanguage(tmpl template.Template, certificateProviderStore Cert
}

if r.Method == http.MethodPost {
data.Form = form.ReadLanguagePreferenceForm(r, "whichLanguageYoudLikeUsToUseWhenWeContactYou")
data.Form = form.ReadLanguagePreferenceForm(r, "whichLanguageYouWouldLikeUsToUseWhenWeContactYou")
data.Errors = data.Form.Validate()

if data.Errors.None() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,11 @@ func TestPostYourPreferredLanguageWhenInvalidData(t *testing.T) {
App: testAppData,
Form: &form.LanguagePreferenceForm{
Error: errors.New("invalid Lang 'not-a-lang'"),
ErrorLabel: "whichLanguageYoudLikeUsToUseWhenWeContactYou",
ErrorLabel: "whichLanguageYouWouldLikeUsToUseWhenWeContactYou",
},
Options: localize.LangValues,
FieldName: form.FieldNames.LanguagePreference,
Errors: validation.With(form.FieldNames.LanguagePreference, validation.SelectError{Label: "whichLanguageYoudLikeUsToUseWhenWeContactYou"}),
Errors: validation.With(form.FieldNames.LanguagePreference, validation.SelectError{Label: "whichLanguageYouWouldLikeUsToUseWhenWeContactYou"}),
Lpa: &lpastore.Lpa{},
}).
Return(nil)
Expand Down
6 changes: 4 additions & 2 deletions internal/page/donor/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ type ProgressTracker interface {
func Register(
rootMux *http.ServeMux,
logger Logger,
commonTmpls, tmpls template.Templates,
tmpls template.Templates,
sessionStore SessionStore,
donorStore DonorStore,
oneLoginClient OneLoginClient,
Expand Down Expand Up @@ -206,7 +206,7 @@ func Register(
handleWithDonor(page.Paths.WeHaveUpdatedYourDetails, page.None,
Guidance(tmpls.Get("we_have_updated_your_details.gohtml")))
handleWithDonor(page.Paths.YourPreferredLanguage, page.None,
YourPreferredLanguage(commonTmpls.Get("your_preferred_language.gohtml"), donorStore))
YourPreferredLanguage(tmpls.Get("your_preferred_language.gohtml"), donorStore))
handleWithDonor(page.Paths.LpaType, page.None,
LpaType(tmpls.Get("lpa_type.gohtml"), donorStore, eventClient))
handleWithDonor(page.Paths.CheckYouCanSign, page.None,
Expand Down Expand Up @@ -384,6 +384,8 @@ func Register(

handleWithDonor(page.Paths.ReadYourLpa, page.None,
Guidance(tmpls.Get("read_your_lpa.gohtml")))
handleWithDonor(page.Paths.YourLpaLanguage, page.CanGoBack,
YourLpaLanguage(tmpls.Get("your_lpa_language.gohtml"), donorStore))
handleWithDonor(page.Paths.LpaYourLegalRightsAndResponsibilities, page.CanGoBack,
Guidance(tmpls.Get("your_legal_rights_and_responsibilities.gohtml")))
handleWithDonor(page.Paths.SignYourLpa, page.CanGoBack,
Expand Down
2 changes: 1 addition & 1 deletion internal/page/donor/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

func TestRegister(t *testing.T) {
mux := http.NewServeMux()
Register(mux, &slog.Logger{}, template.Templates{}, template.Templates{}, &mockSessionStore{}, &mockDonorStore{}, &onelogin.Client{}, &place.Client{}, "http://example.org", &pay.Client{}, &mockShareCodeSender{}, &mockWitnessCodeSender{}, nil, &mockCertificateProviderStore{}, &mockNotifyClient{}, &mockEvidenceReceivedStore{}, &mockDocumentStore{}, &mockEventClient{}, &mockDashboardStore{}, &mockLpaStoreClient{}, &mockShareCodeStore{}, &mockProgressTracker{}, &lpastore.ResolvingService{})
Register(mux, &slog.Logger{}, template.Templates{}, &mockSessionStore{}, &mockDonorStore{}, &onelogin.Client{}, &place.Client{}, "http://example.org", &pay.Client{}, &mockShareCodeSender{}, &mockWitnessCodeSender{}, nil, &mockCertificateProviderStore{}, &mockNotifyClient{}, &mockEvidenceReceivedStore{}, &mockDocumentStore{}, &mockEventClient{}, &mockDashboardStore{}, &mockLpaStoreClient{}, &mockShareCodeStore{}, &mockProgressTracker{}, &lpastore.ResolvingService{})

assert.Implements(t, (*http.Handler)(nil), mux)
}
Expand Down
55 changes: 55 additions & 0 deletions internal/page/donor/your_lpa_language.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package donor

import (
"net/http"

"github.com/ministryofjustice/opg-go-common/template"
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor"
"github.com/ministryofjustice/opg-modernising-lpa/internal/form"
"github.com/ministryofjustice/opg-modernising-lpa/internal/localize"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/validation"
)

type yourLpaLanguageData struct {
App page.AppData
Errors validation.List
Form *form.YesNoForm
SelectedLanguage localize.Lang
UnselectedLanguage localize.Lang
}

func YourLpaLanguage(tmpl template.Template, donorStore DonorStore) Handler {
return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *actor.DonorProvidedDetails) error {
data := &yourLpaLanguageData{
App: appData,
Form: form.NewYesNoForm(form.YesNoUnknown),
SelectedLanguage: donor.Donor.LpaLanguagePreference,
}

if data.SelectedLanguage.IsEn() {
data.UnselectedLanguage = localize.Cy
} else {
data.UnselectedLanguage = localize.En
}

if r.Method == http.MethodPost {
f := form.ReadYesNoForm(r, "whatYouWouldLikeToDo")
data.Errors = f.Validate()

if data.Errors.None() {
if f.YesNo.IsNo() {
donor.Donor.LpaLanguagePreference = data.UnselectedLanguage

if err := donorStore.Put(r.Context(), donor); err != nil {
return err
}
}

return page.Paths.LpaYourLegalRightsAndResponsibilities.Redirect(w, r, appData, donor)
}
}

return tmpl(w, data)
}
}
Loading

0 comments on commit ec196d6

Please sign in to comment.