Skip to content

Commit

Permalink
Merge 20a4538 into 8bce032
Browse files Browse the repository at this point in the history
  • Loading branch information
acsauk authored May 31, 2024
2 parents 8bce032 + 20a4538 commit eee6397
Show file tree
Hide file tree
Showing 11 changed files with 189 additions and 264 deletions.
4 changes: 4 additions & 0 deletions internal/place/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ func (a Address) String() string {
return strings.Join(a.Lines(), ", ")
}

func (a Address) HTML() string {
return strings.Join(a.Lines(), "<br>")
}

func (ad *addressDetails) transformToAddress() Address {
a := Address{}

Expand Down
42 changes: 42 additions & 0 deletions internal/place/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,48 @@ func TestAddress(t *testing.T) {
})
}
})

t.Run("HTML", func(t *testing.T) {
testCases := []struct {
name string
address Address
want string
}{
{
"All props set",
Address{
Line1: "Line 1",
Line2: "Line 2",
Line3: "Line 3",
TownOrCity: "Town",
Postcode: "Postcode",
},
"Line 1<br>Line 2<br>Line 3<br>Town<br>Postcode",
},
{
"Some props set",
Address{
Line1: "Line 1",
Line2: "",
Line3: "Line 3",
TownOrCity: "Town",
Postcode: "",
},
"Line 1<br>Line 3<br>Town",
},
{
"No props set",
Address{},
"",
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
assert.Equal(t, tc.want, tc.address.HTML())
})
}
})
}

func TestTransformAddressDetailsToAddress(t *testing.T) {
Expand Down
43 changes: 26 additions & 17 deletions internal/templatefn/fn.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func All(globals *Globals) map[string]any {
"details": details,
"inc": inc,
"link": link,
"contains": contains,
"stringContains": strings.Contains,
"tr": tr,
"trFormat": trFormat,
"trFormatHtml": trFormatHtml,
Expand Down Expand Up @@ -79,6 +79,8 @@ func All(globals *Globals) map[string]any {
"notificationBanner": notificationBanner,
"checkboxEq": checkboxEq,
"lpaDecisions": lpaDecisions,
"summaryRow": summaryRow,
"html": html,
}
}

Expand Down Expand Up @@ -184,18 +186,6 @@ func link(app page.AppData, path string) string {
return app.Lang.URL(path)
}

func contains(needle string, list any) bool {
if list == nil {
return false
}

if slist, ok := list.([]string); ok {
return slices.Contains(slist, needle)
}

return false
}

// checkboxEq allows matching in the checkboxes.gohtml template for a value that
// is a list of strings, or a single string (where we are emulating a switch)
func checkboxEq(needle string, in any) bool {
Expand Down Expand Up @@ -332,6 +322,7 @@ type attorneySummaryData struct {
Attorneys []lpastore.Attorney
Link attorneySummaryDataLinks
HeadingLevel int
IsReplacement bool
}

type attorneySummaryDataLinks struct {
Expand All @@ -341,9 +332,10 @@ type attorneySummaryDataLinks struct {

func listAttorneys(app page.AppData, attorneys any, attorneyType string, headingLevel int, canChange bool) attorneySummaryData {
data := attorneySummaryData{
App: app,
CanChange: canChange,
HeadingLevel: headingLevel,
App: app,
CanChange: canChange,
HeadingLevel: headingLevel,
IsReplacement: attorneyType == "replacement",
}

switch v := attorneys.(type) {
Expand Down Expand Up @@ -375,7 +367,7 @@ func listAttorneys(app page.AppData, attorneys any, attorneyType string, heading
panic("unsupported type of attorneys for listAttorneys")
}

if attorneyType == "replacement" {
if data.IsReplacement {
data.Link.Attorney = fmt.Sprintf("%s?from=%s", page.Paths.ChooseReplacementAttorneys.Format(app.LpaID), app.Page)
data.Link.AttorneyAddress = fmt.Sprintf("%s?from=%s", page.Paths.ChooseReplacementAttorneysAddress.Format(app.LpaID), app.Page)
data.Link.RemoveAttorney = fmt.Sprintf("%s?from=%s", page.Paths.RemoveReplacementAttorney.Format(app.LpaID), app.Page)
Expand Down Expand Up @@ -496,3 +488,20 @@ func lpaDecisions(app page.AppData, lpa any, canChange bool) lpaDecisionsData {

return data
}

func summaryRow(app page.AppData, label, value, changeLink, fullName string, optional, canChange bool, summarisingActorType actor.Type) map[string]any {
return map[string]any{
"App": app,
"Label": label,
"Value": value,
"ChangeLink": changeLink,
"FullName": fullName,
"Optional": optional,
"CanChange": canChange,
"SummarisingActorType": summarisingActorType,
}
}

func html(s string) template.HTML {
return template.HTML(s)
}
35 changes: 28 additions & 7 deletions internal/templatefn/fn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,6 @@ func TestLink(t *testing.T) {
assert.Equal(t, "/cy/dashboard", link(page.AppData{Lang: localize.Cy}, "/dashboard"))
}

func TestContains(t *testing.T) {
assert.True(t, contains("b", []string{"a", "b", "c"}))
assert.False(t, contains("d", []string{"a", "b", "c"}))

assert.False(t, contains("", nil))
}

func TestCheckboxEq(t *testing.T) {
assert.True(t, checkboxEq("b", []string{"a", "b", "c"}))
assert.False(t, checkboxEq("d", []string{"a", "b", "c"}))
Expand Down Expand Up @@ -361,6 +354,7 @@ func TestListAttorneysWithAttorneys(t *testing.T) {
HeadingLevel: headingLevel,
CanChange: true,
Link: attorneyLinks,
IsReplacement: false,
},
},
"dynamo": {
Expand All @@ -376,6 +370,7 @@ func TestListAttorneysWithAttorneys(t *testing.T) {
HeadingLevel: headingLevel,
CanChange: true,
Link: attorneyLinks,
IsReplacement: false,
},
},
"lpastore replacement": {
Expand All @@ -391,6 +386,7 @@ func TestListAttorneysWithAttorneys(t *testing.T) {
HeadingLevel: headingLevel,
CanChange: true,
Link: replacementLinks,
IsReplacement: true,
},
},
"dynamo replacement": {
Expand All @@ -406,6 +402,7 @@ func TestListAttorneysWithAttorneys(t *testing.T) {
HeadingLevel: headingLevel,
CanChange: true,
Link: replacementLinks,
IsReplacement: true,
},
},
}
Expand Down Expand Up @@ -560,3 +557,27 @@ func TestLpaDecisionsWithDonorProvidedDetails(t *testing.T) {
CanChange: true,
}, lpaDecisions(app, &actor.DonorProvidedDetails{}, true))
}

func TestSummaryRow(t *testing.T) {
app := page.AppData{SessionID: "abc"}
label := "a-label"
value := "aValue"
changeLink := "a-link.com"
fullName := "Full Name"
actorType := actor.TypeDonor

assert.Equal(t, map[string]any{
"App": app,
"Label": label,
"Value": value,
"ChangeLink": changeLink,
"FullName": fullName,
"Optional": true,
"CanChange": true,
"SummarisingActorType": actorType,
}, summaryRow(app, label, value, changeLink, fullName, true, true, actorType))
}

func TestHtml(t *testing.T) {
assert.Equal(t, template.HTML("s"), html("s"))
}
8 changes: 3 additions & 5 deletions lang/cy.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,6 @@
"many": "Rydych wedi ychwanegu {{.PluralCount}} o atwrneiod",
"other": "Rydych wedi ychwanegu {{.PluralCount}} o atwrneiod"
},
"changeNameLinkText": "Newid<span class=\"govuk-visually-hidden\"> enw am {{ .FirstNames }} {{ .LastName }}</span>",
"changeDOBLinkText": "Newid<span class=\"govuk-visually-hidden\"> dyddiad geni am {{ .FirstNames }} {{ .LastName }}</span>",
"changeEmailLinkText": "Newid<span class=\"govuk-visually-hidden\"> e-bost am {{ .FirstNames }} {{ .LastName }}</span>",
"changeAddressLink": "Newid<span class=\"govuk-visually-hidden\"> cyfeiriad am {{ .FirstNames }} {{ .LastName }}</span>",
"doYouWantToAddAnotherAttorney": "Ydych chi eisiau ychwanegu atwrnai gwreiddiol arall?",
"yesToAddAnotherAttorney": "ie i ychwanegu atwrnai arall",
"yesToAddAnotherReplacementAttorney": "ie i ychwanegu atwrnai wrth gefn arall",
Expand Down Expand Up @@ -1202,5 +1198,7 @@
"weHaveContactedDonorToLetThemKnowYourDecision": "Welsh {{ .DonorFullName }} Welsh",
"reportAConcernContent": "<h2 class=\"govuk-heading-m\">Welsh</h2> <p class=\"govuk-body\">Welsh:</p> <ul class=\"govuk-list govuk-list--bullet\"> <li>Welsh: 0115 934 2777</li> <li>Welsh: <a class=\"govuk-link\" href=\"mailto:[email protected]\">[email protected]</a> </li> </ul> <p class=\"govuk-body\">Welsh <a class=\"govuk-link\" href=\"#\">Welsh</a> Welsh</p>",
"yourAddress": "Welsh",
"yourAddressWarning": "Welsh"
"yourAddressWarning": "Welsh",
"enter": "Welsh",
"forFullName": "Welsh {{ .FullName }}"
}
8 changes: 3 additions & 5 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,6 @@
"one": "You have added {{.PluralCount}} original attorney",
"other": "You have added {{.PluralCount}} attorneys"
},
"changeNameLinkText": "Change<span class=\"govuk-visually-hidden\"> name for {{ .FirstNames }} {{ .LastName }}</span>",
"changeDOBLinkText": "Change<span class=\"govuk-visually-hidden\"> date of birth for {{ .FirstNames }} {{ .LastName }}</span>",
"changeEmailLinkText": "Change<span class=\"govuk-visually-hidden\"> email for {{ .FirstNames }} {{ .LastName }}</span>",
"changeAddressLink": "Change<span class=\"govuk-visually-hidden\"> address for {{ .FirstNames }} {{ .LastName }}</span>",
"doYouWantToAddAnotherAttorney": "Do you want to add another original attorney?",
"yesToAddAnotherAttorney": "yes to add another attorney",
"yesToAddAnotherReplacementAttorney": "yes to add another replacement attorney",
Expand Down Expand Up @@ -1134,5 +1130,7 @@
"weHaveContactedDonorToLetThemKnowYourDecision": "We have contacted {{ .DonorFullName }} to let them know of your decision to not be their certificate provider",
"reportAConcernContent": "<h2 class=\"govuk-heading-m\">Report a concern</h2> <p class=\"govuk-body\">If you have concerns about this LPA you can contact our safeguarding team:</p> <ul class=\"govuk-list govuk-list--bullet\"> <li>call: 0115 934 2777</li> <li>email: <a class=\"govuk-link\" href=\"mailto:[email protected]\">[email protected]</a> </li> </ul> <p class=\"govuk-body\">You can also <a class=\"govuk-link\" href=\"#\">report a concern</a> using our online form.</p>",
"yourAddress": "Your address",
"yourAddressWarning": "You should only enter your address. You cannot make an LPA for someone else using your account."
"yourAddressWarning": "You should only enter your address. You cannot make an LPA for someone else using your account.",
"enter": "Enter",
"forFullName": "for {{ .FullName }}"
}
114 changes: 24 additions & 90 deletions web/template/layout/attorney-summary.gohtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{{ define "attorney-summary" }}
{{ $attorneyType := global.ActorTypes.Attorney }}
{{ if $.IsReplacement }}
{{ $attorneyType := global.ActorTypes.ReplacementAttorney }}
{{ end }}

{{ if .TrustCorporation.Name }}
<div class="govuk-summary-card">
<div class="govuk-summary-card__title-wrapper">
Expand All @@ -18,53 +23,17 @@
</div>
<div class="govuk-summary-card__content">
<dl class="govuk-summary-list">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">{{ tr .App "companyName" }}</dt>
<dd class="govuk-summary-list__value">{{ .TrustCorporation.Name }}</dd>
{{ if .CanChange }}
<dd class="govuk-summary-list__actions">
<a class="govuk-link govuk-link--no-visited-state" href="{{ link .App .Link.TrustCorporation }}#f-name">
{{ trHtml .App "changeCompanyNameLink" }}
</a>
</dd>
{{ end }}
</div>
{{ $companyNameChangeLink := printf "%s#f-name" (link .App .Link.TrustCorporation) }}
{{ template "summary-row" (summaryRow $.App "name" .TrustCorporation.Name $companyNameChangeLink .TrustCorporation.Name false $.CanChange $attorneyType) }}

<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">{{ tr .App "companyNumber" }}</dt>
<dd class="govuk-summary-list__value">{{ .TrustCorporation.CompanyNumber }}</dd>
{{ if .CanChange }}
<dd class="govuk-summary-list__actions">
<a class="govuk-link govuk-link--no-visited-state" href="{{ link .App .Link.TrustCorporation }}#f-company-number">
{{ trHtml .App "changeCompanyNumberLink" }}
</a>
</dd>
{{ end }}
</div>
{{ $companyNumberChangeLink := printf "%s#f-company-number" (link .App .Link.TrustCorporation) }}
{{ template "summary-row" (summaryRow $.App "companyNumber" .TrustCorporation.CompanyNumber $companyNumberChangeLink .TrustCorporation.Name false $.CanChange $attorneyType) }}

<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key ">{{ tr .App "companyEmailAddress" }}</dt>
<dd class="govuk-summary-list__value">{{ .TrustCorporation.Email }}</dd>
{{ if .CanChange }}
<dd class="govuk-summary-list__actions">
<a class="govuk-link govuk-link--no-visited-state" href="{{ link .App .Link.TrustCorporation }}#f-email">
{{ trHtml .App "changeCompanyEmailLink" }}
</a>
</dd>
{{ end }}
</div>
{{ $companyEmailAddressChangeLink := printf "%s#f-email" (link .App .Link.TrustCorporation) }}
{{ template "summary-row" (summaryRow $.App "companyEmailAddress" .TrustCorporation.Email $companyEmailAddressChangeLink .TrustCorporation.Name true $.CanChange $attorneyType) }}

<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">{{ tr .App "address" }}</dt>
<dd class="govuk-summary-list__value">{{ template "address-lines" .TrustCorporation.Address }}</dd>
{{ if .CanChange }}
<dd class="govuk-summary-list__actions">
<a class="govuk-link govuk-link--no-visited-state" href="{{ link .App .Link.TrustCorporationAddress }}#f-address-line-1">
{{ trHtml .App "changeCompanyAddressLink" }}
</a>
</dd>
{{ end }}
</div>
{{ $companyAddressChangeLink := printf "%s#f-address-line-1" (link .App .Link.TrustCorporationAddress) }}
{{ template "summary-row" (summaryRow $.App "address" .TrustCorporation.Address.HTML $companyAddressChangeLink .TrustCorporation.Name false $.CanChange $attorneyType) }}
</dl>
</div>
</div>
Expand All @@ -89,52 +58,17 @@
</div>
<div class="govuk-summary-card__content">
<dl class="govuk-summary-list">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">{{ tr $.App "name" }}</dt>
<dd class="govuk-summary-list__value">{{ .FullName }}</dd>
{{ if $.CanChange }}
<dd class="govuk-summary-list__actions">
<a class="govuk-link govuk-link--no-visited-state" href="{{ link $.App $.Link.Attorney }}&id={{ .UID }}#f-first-names">
{{ trFormatHtml $.App "changeNameLinkText" "FirstNames" .FirstNames "LastName" .LastName }}
</a>
</dd>
{{ end }}
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">{{ tr $.App "dateOfBirth" }}</dt>
<dd class="govuk-summary-list__value">{{ formatDate $.App .DateOfBirth }}</dd>
{{ if $.CanChange }}
<dd class="govuk-summary-list__actions">
<a class="govuk-link govuk-link--no-visited-state" href="{{ link $.App $.Link.Attorney }}&id={{ .UID }}#f-date-of-birth">
{{ trFormatHtml $.App "changeDOBLinkText" "FirstNames" .FirstNames "LastName" .LastName }}
</a>
</dd>
{{ end }}
</div>
{{ if .Email }}
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">{{ tr $.App "email" }}</dt>
<dd class="govuk-summary-list__value">{{ .Email }}</dd>
{{ if $.CanChange }}
<dd class="govuk-summary-list__actions">
<a class="govuk-link govuk-link--no-visited-state" href="{{ link $.App $.Link.Attorney }}&id={{ .UID }}#f-email">
{{ trFormatHtml $.App "changeEmailLinkText" "FirstNames" .FirstNames "LastName" .LastName }}
</a>
</dd>
{{ end }}
</div>
{{ end }}
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">{{ tr $.App "address" }}</dt>
<dd class="govuk-summary-list__value">{{ template "address-lines" .Address }}</dd>
{{ if $.CanChange }}
<dd class="govuk-summary-list__actions">
<a class="govuk-link govuk-link--no-visited-state" href="{{ link $.App $.Link.AttorneyAddress }}&id={{ .UID }}#f-address-line-1">
{{ trFormatHtml $.App "changeAddressLink" "FirstNames" .FirstNames "LastName" .LastName }}
</a>
</dd>
{{ end }}
</div>
{{ $nameChangeLink := printf "%s&id=%s#f-first-names" (link $.App $.Link.Attorney) .UID }}
{{ template "summary-row" (summaryRow $.App "name" .FullName $nameChangeLink .FullName false $.CanChange $attorneyType) }}

{{ $dobChangeLink := printf "%s&id=%s#f-date-of-birth" (link $.App $.Link.Attorney) .UID }}
{{ template "summary-row" (summaryRow $.App "dateOfBirth" (formatDate $.App .DateOfBirth) $dobChangeLink .FullName false $.CanChange $attorneyType) }}

{{ $emailChangeLink := printf "%s&id=%s#f-email" (link $.App $.Link.Attorney) .UID }}
{{ template "summary-row" (summaryRow $.App "email" .Email $emailChangeLink .FullName true $.CanChange $attorneyType) }}

{{ $addressChangeLink := printf "%s&id=%s#f-address-line-1" (link $.App $.Link.AttorneyAddress) .UID }}
{{ template "summary-row" (summaryRow $.App "address" .Address.HTML $addressChangeLink .FullName false $.CanChange $attorneyType) }}
</dl>
</div>
</div>
Expand Down
Loading

0 comments on commit eee6397

Please sign in to comment.