Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
acsauk authored Nov 20, 2024
2 parents 0422c51 + b0b938a commit a74dcf7
Show file tree
Hide file tree
Showing 48 changed files with 399 additions and 793 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/donor/can-you-sign-your-lpa.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('Can you sign your LPA', () => {
cy.checkA11yApp();
cy.contains('a', 'Return to task list').should('not.exist');

cy.get('#f-can-sign').check({ force: true });
cy.get('#f-selected').check({ force: true });

cy.contains('button', 'Save and continue').click();
cy.url().should('contain', '/your-preferred-language');
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/donor/lpa-type.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {AddressFormAssertions} from "../../support/e2e";
import { AddressFormAssertions } from "../../support/e2e";

describe('LPA type', () => {
it('can be submitted', () => {
Expand All @@ -19,7 +19,7 @@ describe('LPA type', () => {

cy.contains('a', 'Continue').click();

cy.get('#f-can-sign').check({ force: true });
cy.get('#f-selected').check({ force: true });
cy.contains('button', 'Save and continue').click();

cy.get('[name="contact-language"]').check('en', { force: true })
Expand Down
12 changes: 6 additions & 6 deletions cypress/e2e/donor/payment.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('Pay for LPA', { pageLoadTimeout: 8000 }, () => {
cy.url().should('contains', '/how-would-you-like-to-send-evidence')
cy.checkA11yApp();

cy.get('input[name="evidence-delivery"]').check('upload', { force: true });
cy.get('input[name="selected"]').check('upload', { force: true });
cy.contains('button', 'Continue').click();

cy.url().should('contains', '/upload-evidence')
Expand Down Expand Up @@ -148,7 +148,7 @@ describe('Pay for LPA', { pageLoadTimeout: 8000 }, () => {
cy.url().should('contains', '/how-would-you-like-to-send-evidence')
cy.checkA11yApp();

cy.get('input[name="evidence-delivery"]').check('upload', { force: true });
cy.get('input[name="selected"]').check('upload', { force: true });
cy.contains('button', 'Continue').click();

cy.url().should('contains', '/upload-evidence')
Expand Down Expand Up @@ -223,7 +223,7 @@ describe('Pay for LPA', { pageLoadTimeout: 8000 }, () => {
cy.url().should('contains', '/how-would-you-like-to-send-evidence')
cy.checkA11yApp();

cy.get('input[name="evidence-delivery"]').check('upload', { force: true });
cy.get('input[name="selected"]').check('upload', { force: true });
cy.contains('button', 'Continue').click();

cy.url().should('contains', '/upload-evidence')
Expand Down Expand Up @@ -329,7 +329,7 @@ describe('Pay for LPA', { pageLoadTimeout: 8000 }, () => {
cy.url().should('contains', '/how-would-you-like-to-send-evidence')
cy.checkA11yApp();

cy.get('input[name="evidence-delivery"]').check('post', { force: true });
cy.get('input[name="selected"]').check('post', { force: true });
cy.contains('button', 'Continue').click();

cy.url().should('contains', '/send-us-your-evidence-by-post')
Expand Down Expand Up @@ -435,7 +435,7 @@ describe('Pay for LPA', { pageLoadTimeout: 8000 }, () => {
cy.url().should('contains', '/how-much-did-you-previously-pay-for-your-lpa')
cy.checkA11yApp();

cy.get('input[name="previous-fee"]').check('Half', { force: true });
cy.get('input[name="selected"]').check('Half', { force: true });
cy.contains('button', 'Continue').click();

cy.url().should('contains', '/evidence-required')
Expand All @@ -447,7 +447,7 @@ describe('Pay for LPA', { pageLoadTimeout: 8000 }, () => {
cy.url().should('contains', '/how-would-you-like-to-send-evidence')
cy.checkA11yApp();

cy.get('input[name="evidence-delivery"]').check('post', { force: true });
cy.get('input[name="selected"]').check('post', { force: true });
cy.contains('button', 'Continue').click();

cy.url().should('contains', '/send-us-your-evidence-by-post')
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/donor/provide-your-details.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('Provide your details', () => {

cy.contains('a', 'Continue').click();

cy.get('#f-can-sign').check({ force: true });
cy.get('#f-selected').check({ force: true });
cy.contains('button', 'Save and continue').click();

cy.get('[name="contact-language"]').check('en', { force: true });
Expand Down
32 changes: 16 additions & 16 deletions cypress/e2e/donor/when-can-the-lpa-be-used.cy.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
describe('When can the LPA be used', () => {
beforeEach(() => {
cy.visit('/fixtures?redirect=/when-can-the-lpa-be-used&progress=chooseYourAttorneys');
});
beforeEach(() => {
cy.visit('/fixtures?redirect=/when-can-the-lpa-be-used&progress=chooseYourAttorneys');
});

it('can be submitted', () => {
cy.get('#f-selected').check('when-has-capacity', { force: true });

it('can be submitted', () => {
cy.get('#f-when').check('when-has-capacity', { force: true });
cy.checkA11yApp();

cy.checkA11yApp();
cy.contains('button', 'Save and continue').click();
cy.url().should('contain', '/task-list');
});

cy.contains('button', 'Save and continue').click();
cy.url().should('contain', '/task-list');
});
it('errors when unselected', () => {
cy.contains('button', 'Save and continue').click();

it('errors when unselected', () => {
cy.contains('button', 'Save and continue').click();
cy.get('.govuk-error-summary').within(() => {
cy.contains('Select when your attorneys can use your LPA');
});

cy.get('.govuk-error-summary').within(() => {
cy.contains('Select when your attorneys can use your LPA');
cy.contains('.govuk-fieldset .govuk-error-message', 'Select when your attorneys can use your LPA');
});

cy.contains('.govuk-fieldset .govuk-error-message', 'Select when your attorneys can use your LPA');
});
});
2 changes: 1 addition & 1 deletion cypress/e2e/supporter/dashboard.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('Dashboard', () => {
cy.get('#f-email').type('[email protected]');
cy.contains('button', 'Save and continue').click()

cy.get('#f-can-sign').check({ force: true });
cy.get('#f-selected').check({ force: true });
cy.contains('button', 'Save and continue').click()

cy.get('[name="contact-language"]').check('en', { force: true })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,27 @@ import (
"github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext"
"github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider"
"github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/form"
"github.com/ministryofjustice/opg-modernising-lpa/internal/validation"
)

type completingYourIdentityConfirmationData struct {
App appcontext.Data
Errors validation.List
Form *howWillYouConfirmYourIdentityForm
Options howYouWillConfirmYourIdentityOptions
Form *form.SelectForm[howYouWillConfirmYourIdentity, howYouWillConfirmYourIdentityOptions, *howYouWillConfirmYourIdentity]
Deadline time.Time
}

func CompletingYourIdentityConfirmation(tmpl template.Template) Handler {
return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, provided *certificateproviderdata.Provided) error {
data := &completingYourIdentityConfirmationData{
App: appData,
Form: &howWillYouConfirmYourIdentityForm{},
Options: howYouWillConfirmYourIdentityValues,
Form: form.NewEmptySelectForm[howYouWillConfirmYourIdentity](howYouWillConfirmYourIdentityValues, "howYouWouldLikeToContinue"),
Deadline: provided.IdentityDeadline(),
}

if r.Method == http.MethodPost {
data.Form = readHowWillYouConfirmYourIdentityForm(r, "howYouWouldLikeToContinue")
data.Form.Read(r)
data.Errors = data.Form.Validate()

if data.Errors.None() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider"
"github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/form"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/validation"
"github.com/stretchr/testify/assert"
Expand All @@ -22,9 +23,8 @@ func TestGetCompletingYourIdentityConfirmation(t *testing.T) {
template := newMockTemplate(t)
template.EXPECT().
Execute(w, &completingYourIdentityConfirmationData{
App: testAppData,
Form: &howWillYouConfirmYourIdentityForm{},
Options: howYouWillConfirmYourIdentityValues,
App: testAppData,
Form: form.NewEmptySelectForm[howYouWillConfirmYourIdentity](howYouWillConfirmYourIdentityValues, "howYouWouldLikeToContinue"),
}).
Return(nil)

Expand Down Expand Up @@ -69,7 +69,7 @@ func TestPostCompletingYourIdentityConfirmation(t *testing.T) {
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
form := url.Values{
"how": {tc.how.String()},
form.FieldNames.Select: {tc.how.String()},
}

w := httptest.NewRecorder()
Expand All @@ -94,7 +94,7 @@ func TestPostCompletingYourIdentityConfirmationWhenValidationErrors(t *testing.T
template := newMockTemplate(t)
template.EXPECT().
Execute(w, mock.MatchedBy(func(data *completingYourIdentityConfirmationData) bool {
return assert.Equal(t, validation.With("how", validation.SelectError{Label: "howYouWouldLikeToContinue"}), data.Errors)
return assert.Equal(t, validation.With(form.FieldNames.Select, validation.SelectError{Label: "howYouWouldLikeToContinue"}), data.Errors)
})).
Return(nil)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext"
"github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider"
"github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/form"
"github.com/ministryofjustice/opg-modernising-lpa/internal/task"
"github.com/ministryofjustice/opg-modernising-lpa/internal/validation"
)
Expand All @@ -23,26 +23,24 @@ const (
)

type howWillYouConfirmYourIdentityData struct {
App appcontext.Data
Errors validation.List
Form *howWillYouConfirmYourIdentityForm
Options howYouWillConfirmYourIdentityOptions
App appcontext.Data
Errors validation.List
Form *form.SelectForm[howYouWillConfirmYourIdentity, howYouWillConfirmYourIdentityOptions, *howYouWillConfirmYourIdentity]
}

func HowWillYouConfirmYourIdentity(tmpl template.Template, certificateProviderStore CertificateProviderStore) Handler {
return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, provided *certificateproviderdata.Provided) error {
data := &howWillYouConfirmYourIdentityData{
App: appData,
Form: &howWillYouConfirmYourIdentityForm{},
Options: howYouWillConfirmYourIdentityValues,
App: appData,
Form: form.NewEmptySelectForm[howYouWillConfirmYourIdentity](howYouWillConfirmYourIdentityValues, "howYouWillConfirmYourIdentity"),
}

if r.Method == http.MethodPost {
data.Form = readHowWillYouConfirmYourIdentityForm(r, "howYouWillConfirmYourIdentity")
data.Form.Read(r)
data.Errors = data.Form.Validate()

if data.Errors.None() {
switch data.Form.How {
switch data.Form.Selected {
case howYouWillConfirmYourIdentityAtPostOffice:
provided.Tasks.ConfirmYourIdentity = task.IdentityStatePending

Expand All @@ -61,26 +59,3 @@ func HowWillYouConfirmYourIdentity(tmpl template.Template, certificateProviderSt
return tmpl(w, data)
}
}

type howWillYouConfirmYourIdentityForm struct {
How howYouWillConfirmYourIdentity
errorLabel string
}

func readHowWillYouConfirmYourIdentityForm(r *http.Request, errorLabel string) *howWillYouConfirmYourIdentityForm {
howWillYouConfirmYourIdentity, _ := ParseHowYouWillConfirmYourIdentity(page.PostFormString(r, "how"))

return &howWillYouConfirmYourIdentityForm{
How: howWillYouConfirmYourIdentity,
errorLabel: errorLabel,
}
}

func (f *howWillYouConfirmYourIdentityForm) Validate() validation.List {
var errors validation.List

errors.Enum("how", f.errorLabel, f.How,
validation.Selected())

return errors
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider"
"github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/form"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/task"
"github.com/ministryofjustice/opg-modernising-lpa/internal/validation"
Expand All @@ -23,9 +24,8 @@ func TestGetHowWillYouConfirmYourIdentity(t *testing.T) {
template := newMockTemplate(t)
template.EXPECT().
Execute(w, &howWillYouConfirmYourIdentityData{
App: testAppData,
Form: &howWillYouConfirmYourIdentityForm{},
Options: howYouWillConfirmYourIdentityValues,
App: testAppData,
Form: form.NewEmptySelectForm[howYouWillConfirmYourIdentity](howYouWillConfirmYourIdentityValues, "howYouWillConfirmYourIdentity"),
}).
Return(nil)

Expand Down Expand Up @@ -70,7 +70,7 @@ func TestPostHowWillYouConfirmYourIdentity(t *testing.T) {
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
form := url.Values{
"how": {tc.how.String()},
form.FieldNames.Select: {tc.how.String()},
}

w := httptest.NewRecorder()
Expand All @@ -89,7 +89,7 @@ func TestPostHowWillYouConfirmYourIdentity(t *testing.T) {

func TestPostHowWillYouConfirmYourIdentityWhenAtPostOfficeSelected(t *testing.T) {
form := url.Values{
"how": {howYouWillConfirmYourIdentityAtPostOffice.String()},
form.FieldNames.Select: {howYouWillConfirmYourIdentityAtPostOffice.String()},
}

w := httptest.NewRecorder()
Expand All @@ -114,7 +114,7 @@ func TestPostHowWillYouConfirmYourIdentityWhenAtPostOfficeSelected(t *testing.T)

func TestPostHowWillYouConfirmYourIdentityWhenStoreErrors(t *testing.T) {
form := url.Values{
"how": {howYouWillConfirmYourIdentityAtPostOffice.String()},
form.FieldNames.Select: {howYouWillConfirmYourIdentityAtPostOffice.String()},
}

w := httptest.NewRecorder()
Expand All @@ -138,7 +138,7 @@ func TestPostHowWillYouConfirmYourIdentityWhenValidationErrors(t *testing.T) {
template := newMockTemplate(t)
template.EXPECT().
Execute(w, mock.MatchedBy(func(data *howWillYouConfirmYourIdentityData) bool {
return assert.Equal(t, validation.With("how", validation.SelectError{Label: "howYouWillConfirmYourIdentity"}), data.Errors)
return assert.Equal(t, validation.With(form.FieldNames.Select, validation.SelectError{Label: "howYouWillConfirmYourIdentity"}), data.Errors)
})).
Return(nil)

Expand All @@ -148,38 +148,3 @@ func TestPostHowWillYouConfirmYourIdentityWhenValidationErrors(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, http.StatusOK, resp.StatusCode)
}

func TestReadHowWillYouConfirmYourIdentityForm(t *testing.T) {
form := url.Values{
"how": {howYouWillConfirmYourIdentityAtPostOffice.String()},
}

r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(form.Encode()))
r.Header.Add("Content-Type", page.FormUrlEncoded)

result := readHowWillYouConfirmYourIdentityForm(r, "blah")
assert.Equal(t, howYouWillConfirmYourIdentityAtPostOffice, result.How)
}

func TestHowWillYouConfirmYourIdentityFormValidate(t *testing.T) {
testCases := map[string]struct {
form *howWillYouConfirmYourIdentityForm
errors validation.List
}{
"valid": {
form: &howWillYouConfirmYourIdentityForm{
How: howYouWillConfirmYourIdentityAtPostOffice,
},
},
"invalid": {
form: &howWillYouConfirmYourIdentityForm{errorLabel: "blah"},
errors: validation.With("how", validation.SelectError{Label: "blah"}),
},
}

for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
assert.Equal(t, tc.errors, tc.form.Validate())
})
}
}
Loading

0 comments on commit a74dcf7

Please sign in to comment.