Skip to content

Commit

Permalink
MLPAB-2008 Add breadcrumb navigation for supporter task list (#1142)
Browse files Browse the repository at this point in the history
  • Loading branch information
hawx authored Mar 21, 2024
1 parent 4798303 commit 6c8e023
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 75 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/donor/enter-access-code.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ describe('Enter access code', () => {

cy.contains('M-FAKE-');
cy.contains('a', 'Go to task list').click();
cy.contains('Your task list');
cy.contains('LPA task list');
});
});
7 changes: 6 additions & 1 deletion internal/page/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ func (p SupporterLpaPath) Redirect(w http.ResponseWriter, r *http.Request, appDa
return nil
}

func (p SupporterLpaPath) RedirectQuery(w http.ResponseWriter, r *http.Request, appData AppData, lpaID string, query url.Values) error {
http.Redirect(w, r, appData.Lang.URL(p.Format(lpaID))+"?"+query.Encode(), http.StatusFound)
return nil
}

func (p SupporterLpaPath) IsManageOrganisation() bool {
return false
}
Expand Down Expand Up @@ -277,8 +282,8 @@ type SupporterPaths struct {
ManageTeamMembers SupporterPath
OrganisationCreated SupporterPath
OrganisationDetails SupporterPath
ViewLPA SupporterPath

ViewLPA SupporterLpaPath
DonorAccess SupporterLpaPath
}

Expand Down
13 changes: 13 additions & 0 deletions internal/page/paths_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,19 @@ func TestSupporterLpaPathRedirect(t *testing.T) {
assert.Equal(t, p.Format("abc"), resp.Header.Get("Location"))
}

func TestSupporterLpaPathRedirectQuery(t *testing.T) {
r, _ := http.NewRequest(http.MethodGet, "/", nil)
w := httptest.NewRecorder()
p := SupporterLpaPath("/something")

err := p.RedirectQuery(w, r, AppData{Lang: localize.En}, "abc", url.Values{"x": {"y"}})
resp := w.Result()

assert.Nil(t, err)
assert.Equal(t, http.StatusFound, resp.StatusCode)
assert.Equal(t, p.Format("abc")+"?x=y", resp.Header.Get("Location"))
}

func TestSupporterLpaPathIsManageOrganisation(t *testing.T) {
assert.False(t, SupporterLpaPath("").IsManageOrganisation())
}
Expand Down
9 changes: 3 additions & 6 deletions internal/page/supporter/donor_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ func DonorAccess(tmpl template.Template, donorStore DonorStore, shareCodeStore S
return err
}

return page.Paths.Supporter.ViewLPA.RedirectQuery(w, r, appData, url.Values{
"id": {appData.LpaID},
return page.Paths.Supporter.ViewLPA.RedirectQuery(w, r, appData, appData.LpaID, url.Values{
"inviteRecalledFor": {shareCodeData.InviteSentTo},
})

Expand All @@ -63,8 +62,7 @@ func DonorAccess(tmpl template.Template, donorStore DonorStore, shareCodeStore S
return err
}

return page.Paths.Supporter.ViewLPA.RedirectQuery(w, r, appData, url.Values{
"id": {appData.LpaID},
return page.Paths.Supporter.ViewLPA.RedirectQuery(w, r, appData, appData.LpaID, url.Values{
"accessRemovedFor": {shareCodeData.InviteSentTo},
})

Expand Down Expand Up @@ -113,8 +111,7 @@ func DonorAccess(tmpl template.Template, donorStore DonorStore, shareCodeStore S
return err
}

return page.Paths.Supporter.ViewLPA.RedirectQuery(w, r, appData, url.Values{
"id": {appData.LpaID},
return page.Paths.Supporter.ViewLPA.RedirectQuery(w, r, appData, appData.LpaID, url.Values{
"inviteSentTo": {data.Form.Email},
})
}
Expand Down
6 changes: 3 additions & 3 deletions internal/page/supporter/donor_access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func TestPostDonorAccess(t *testing.T) {

assert.Nil(t, err)
assert.Equal(t, http.StatusFound, resp.StatusCode)
assert.Equal(t, page.Paths.Supporter.ViewLPA.Format()+"?id=lpa-id&inviteSentTo=email%40example.com", resp.Header.Get("Location"))
assert.Equal(t, page.Paths.Supporter.ViewLPA.Format("lpa-id")+"?inviteSentTo=email%40example.com", resp.Header.Get("Location"))
}

func TestPostDonorAccessWhenDonorUpdateErrors(t *testing.T) {
Expand Down Expand Up @@ -306,7 +306,7 @@ func TestPostDonorAccessRecall(t *testing.T) {

assert.Nil(t, err)
assert.Equal(t, http.StatusFound, resp.StatusCode)
assert.Equal(t, page.Paths.Supporter.ViewLPA.Format()+"?id=lpa-id&inviteRecalledFor=email%40example.com", resp.Header.Get("Location"))
assert.Equal(t, page.Paths.Supporter.ViewLPA.Format("lpa-id")+"?inviteRecalledFor=email%40example.com", resp.Header.Get("Location"))
}

func TestPostDonorAccessRecallWhenDeleteErrors(t *testing.T) {
Expand Down Expand Up @@ -414,7 +414,7 @@ func TestPostDonorAccessRemove(t *testing.T) {

assert.Nil(t, err)
assert.Equal(t, http.StatusFound, resp.StatusCode)
assert.Equal(t, page.Paths.Supporter.ViewLPA.Format()+"?accessRemovedFor=email%40example.com&id=lpa-id", resp.Header.Get("Location"))
assert.Equal(t, page.Paths.Supporter.ViewLPA.Format("lpa-id")+"?accessRemovedFor=email%40example.com", resp.Header.Get("Location"))
}

func TestPostDonorAccessRemoveWhenDonorHasPaid(t *testing.T) {
Expand Down
20 changes: 3 additions & 17 deletions internal/page/supporter/view_lpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,17 @@ type viewLPAData struct {

func ViewLPA(tmpl template.Template, donorStore DonorStore, certificateProviderStore CertificateProviderStore, attorneyStore AttorneyStore, progressTracker ProgressTracker) Handler {
return func(appData page.AppData, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation, _ *actor.Member) error {
sessionData, err := page.SessionDataFromContext(r.Context())
donor, err := donorStore.Get(r.Context())
if err != nil {
return err
}

lpaID := r.FormValue("id")
if lpaID == "" {
return errors.New("lpaID missing from query")
}

sessionData.LpaID = lpaID

ctx := page.ContextWithSessionData(r.Context(), sessionData)

donor, err := donorStore.Get(ctx)
if err != nil {
return err
}

certificateProvider, err := certificateProviderStore.GetAny(ctx)
certificateProvider, err := certificateProviderStore.GetAny(r.Context())
if err != nil && !errors.Is(err, dynamo.NotFoundError{}) {
return err
}

attorneys, err := attorneyStore.GetAny(ctx)
attorneys, err := attorneyStore.GetAny(r.Context())
if err != nil && !errors.Is(err, dynamo.NotFoundError{}) {
return err
}
Expand Down
37 changes: 8 additions & 29 deletions internal/page/supporter/view_lpa_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package supporter

import (
"context"
"net/http"
"net/http/httptest"
"testing"
Expand All @@ -22,25 +21,23 @@ func TestGetViewLPA(t *testing.T) {
for name, storeError := range testcases {
t.Run(name, func(t *testing.T) {
w := httptest.NewRecorder()
r, _ := http.NewRequestWithContext(page.ContextWithSessionData(context.Background(), &page.SessionData{}), http.MethodGet, "/?id=lpa-id", nil)
r, _ := http.NewRequest(http.MethodGet, "/", nil)

donor := &actor.DonorProvidedDetails{LpaID: "lpa-id"}

ctx := page.ContextWithSessionData(r.Context(), &page.SessionData{LpaID: "lpa-id"})

donorStore := newMockDonorStore(t)
donorStore.EXPECT().
Get(ctx).
Get(r.Context()).
Return(donor, nil)

certificateProviderStore := newMockCertificateProviderStore(t)
certificateProviderStore.EXPECT().
GetAny(ctx).
GetAny(r.Context()).
Return(&actor.CertificateProviderProvidedDetails{}, storeError)

attorneyStore := newMockAttorneyStore(t)
attorneyStore.EXPECT().
GetAny(ctx).
GetAny(r.Context()).
Return([]*actor.AttorneyProvidedDetails{{}}, storeError)

progressTracker := newMockProgressTracker(t)
Expand All @@ -65,27 +62,9 @@ func TestGetViewLPA(t *testing.T) {

}

func TestGetViewLPAWithSessionMissing(t *testing.T) {
w := httptest.NewRecorder()
r, _ := http.NewRequestWithContext(page.ContextWithSessionData(context.Background(), &page.SessionData{}), http.MethodGet, "/", nil)

err := ViewLPA(nil, nil, nil, nil, nil)(testAppData, w, r, &actor.Organisation{}, nil)

assert.Error(t, err)
}

func TestGetViewLPAMissingLPAId(t *testing.T) {
w := httptest.NewRecorder()
r, _ := http.NewRequest(http.MethodGet, "/", nil)

err := ViewLPA(nil, nil, nil, nil, nil)(testAppData, w, r, &actor.Organisation{}, nil)

assert.Error(t, err)
}

func TestGetViewLPAWithDonorStoreError(t *testing.T) {
w := httptest.NewRecorder()
r, _ := http.NewRequestWithContext(page.ContextWithSessionData(context.Background(), &page.SessionData{}), http.MethodGet, "/?id=lpa-id", nil)
r, _ := http.NewRequest(http.MethodGet, "/", nil)

donorStore := newMockDonorStore(t)
donorStore.EXPECT().
Expand All @@ -99,7 +78,7 @@ func TestGetViewLPAWithDonorStoreError(t *testing.T) {

func TestGetViewLPAWhenCertificateProviderStoreError(t *testing.T) {
w := httptest.NewRecorder()
r, _ := http.NewRequestWithContext(page.ContextWithSessionData(context.Background(), &page.SessionData{}), http.MethodGet, "/?id=lpa-id", nil)
r, _ := http.NewRequest(http.MethodGet, "/", nil)

donor := &actor.DonorProvidedDetails{LpaID: "lpa-id", SK: "ORGANISATION"}

Expand All @@ -120,7 +99,7 @@ func TestGetViewLPAWhenCertificateProviderStoreError(t *testing.T) {

func TestGetViewLPAWhenAttorneyStoreError(t *testing.T) {
w := httptest.NewRecorder()
r, _ := http.NewRequestWithContext(page.ContextWithSessionData(context.Background(), &page.SessionData{}), http.MethodGet, "/?id=lpa-id", nil)
r, _ := http.NewRequest(http.MethodGet, "/", nil)

donor := &actor.DonorProvidedDetails{LpaID: "lpa-id", SK: "ORGANISATION"}

Expand All @@ -146,7 +125,7 @@ func TestGetViewLPAWhenAttorneyStoreError(t *testing.T) {

func TestGetViewLPAWhenTemplateError(t *testing.T) {
w := httptest.NewRecorder()
r, _ := http.NewRequestWithContext(page.ContextWithSessionData(context.Background(), &page.SessionData{}), http.MethodGet, "/?id=lpa-id", nil)
r, _ := http.NewRequest(http.MethodGet, "/", nil)

donor := &actor.DonorProvidedDetails{LpaID: "lpa-id"}

Expand Down
4 changes: 3 additions & 1 deletion lang/cy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1157,5 +1157,7 @@
"inviteRecalled": "Welsh",
"youRecalledTheInviteFor": "Welsh {{.Email}}",
"accessRemoved": "Welsh",
"youRemovedAccessToThisLPAFor": "Welsh <span class=\"govuk-!-font-weight-bold\">{{.Email}}</span>."
"youRemovedAccessToThisLPAFor": "Welsh <span class=\"govuk-!-font-weight-bold\">{{.Email}}</span>.",
"lpaTaskList": "Welsh",
"donorsTypeLpa": "{{.DonorFullNamePossessive}} {{.LpaType}} Welsh"
}
4 changes: 3 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1089,5 +1089,7 @@
"inviteRecalled": "Invite recalled",
"youRecalledTheInviteFor": "You recalled the invite to this LPA for <span class=\"govuk-!-font-weight-bold\">{{.Email}}</span>.",
"accessRemoved": "Access removed",
"youRemovedAccessToThisLPAFor": "You removed access to this LPA for <span class=\"govuk-!-font-weight-bold\">{{.Email}}</span>."
"youRemovedAccessToThisLPAFor": "You removed access to this LPA for <span class=\"govuk-!-font-weight-bold\">{{.Email}}</span>.",
"lpaTaskList": "LPA task list",
"donorsTypeLpa": "{{.DonorFullNamePossessive}} {{.LpaType}} LPA"
}
65 changes: 50 additions & 15 deletions web/template/donor/task_list.gohtml
Original file line number Diff line number Diff line change
@@ -1,25 +1,60 @@
{{ template "page" . }}

{{ define "pageTitle" }}{{ tr .App "yourTaskList" }}{{ end }}
{{ define "pageTitle" }}
{{ if .App.IsSupporter }}
{{ tr .App "lpaTaskList" }}
{{ else }}
{{ tr .App "yourTaskList" }}
{{ end }}
{{ end }}

{{ define "main" }}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<span class="govuk-caption-xl">{{ trFormat .App "makeYourTypeLpa" "Type" (tr .App .Donor.Type.String | lowerFirst) }}</span>
<h1 class="govuk-heading-xl">{{ tr .App "yourTaskList" }}</h1>
{{ if .App.IsSupporter }}
<div class="govuk-breadcrumbs">
<ol class="govuk-breadcrumbs__list">
<li class="govuk-breadcrumbs__list-item">
<a class="govuk-breadcrumbs__link" href="{{ link .App (global.Paths.Supporter.ViewLPA.Format .Donor.LpaID) }}">{{ trFormat .App "donorsTypeLpa" "DonorFullNamePossessive" (possessive .App .Donor.Donor.FullName) "LpaType" (tr .App .Donor.Type.String | lowerFirst) }}</a>
</li>
</ol>
</div>

<h1 class="govuk-heading-xl">{{ template "pageTitle" . }}</h1>

<div class="govuk-inset-text">
<dl class="govuk-summary-list govuk-summary-list--no-border app-summary-list--no-vertical-padding">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">{{ tr .App "donor" }}</dt>
<dd class="govuk-summary-list__value">{{ .Donor.Donor.FullName }}</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">{{ tr .App "lpaType" }}</dt>
<dd class="govuk-summary-list__value">{{ tr .App .Donor.Type.String }}</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">{{ tr .App "referenceNumber" }}</dt>
<dd class="govuk-summary-list__value">{{ .Donor.LpaUID }}</dd>
</div>
</dl>
</div>
{{ else }}
<span class="govuk-caption-xl">{{ trFormat .App "makeYourTypeLpa" "Type" (tr .App .Donor.Type.String | lowerFirst) }}</span>
<h1 class="govuk-heading-xl">{{ template "pageTitle" . }}</h1>

<div class="govuk-inset-text">
<dl class="govuk-summary-list govuk-summary-list--no-border app-summary-list--no-vertical-padding">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">{{ tr .App "donor" }}</dt>
<dd class="govuk-summary-list__value">{{ .Donor.Donor.FullName }}</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">{{ tr .App "referenceNumber" }}</dt>
<dd class="govuk-summary-list__value">{{ .Donor.LpaUID }}</dd>
</div>
</dl>
</div>
<div class="govuk-inset-text">
<dl class="govuk-summary-list govuk-summary-list--no-border app-summary-list--no-vertical-padding">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">{{ tr .App "donor" }}</dt>
<dd class="govuk-summary-list__value">{{ .Donor.Donor.FullName }}</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">{{ tr .App "referenceNumber" }}</dt>
<dd class="govuk-summary-list__value">{{ .Donor.LpaUID }}</dd>
</div>
</dl>
</div>
{{ end }}

{{ template "details" (details . "taskListHelp" "taskListHelpContent" false) }}

Expand Down
2 changes: 1 addition & 1 deletion web/template/supporter/dashboard.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<span class="govuk-!-font-weight-bold">{{ .Donor.FullName }}</span><br/>
{{ .Donor.Address.Postcode }}
</td>
<td class="govuk-table__cell"><a class="govuk-link" href="{{ link $.App (global.Paths.Supporter.ViewLPA.Format) }}?id={{ .LpaID }}">{{ .LpaUID }}</a></td>
<td class="govuk-table__cell"><a class="govuk-link" href="{{ link $.App (global.Paths.Supporter.ViewLPA.Format .LpaID) }}">{{ .LpaUID }}</a></td>
<td class="govuk-table__cell">{{ tr $.App .Type.String }}</td>
<td class="govuk-table__cell">
{{ if not .SignedAt.IsZero }}
Expand Down

0 comments on commit 6c8e023

Please sign in to comment.