Skip to content

Commit

Permalink
Merge c26b5bc into 8bce032
Browse files Browse the repository at this point in the history
  • Loading branch information
acsauk authored May 30, 2024
2 parents 8bce032 + c26b5bc commit 3eadcf4
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 105 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
18 changes: 18 additions & 0 deletions internal/templatefn/fn.go
Original file line number Diff line number Diff line change
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 @@ -496,3 +498,19 @@ 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) map[string]any {
return map[string]any{
"App": app,
"Label": label,
"Value": value,
"ChangeLink": changeLink,
"FullName": fullName,
"Optional": optional,
"CanChange": canChange,
}
}

func html(s string) template.HTML {
return template.HTML(s)
}
18 changes: 18 additions & 0 deletions internal/templatefn/fn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,3 +560,21 @@ func TestLpaDecisionsWithDonorProvidedDetails(t *testing.T) {
CanChange: true,
}, lpaDecisions(app, &actor.DonorProvidedDetails{}, true))
}

func TestSummaryRow(t *testing.T) {
app := page.AppData{SessionID: "abc"}

assert.Equal(t, map[string]any{
"App": app,
"Label": "a-label",
"Value": "aValue",
"ChangeLink": "a-link.com",
"FullName": "Full Name",
"Optional": true,
"CanChange": true,
}, summaryRow(app, "a-label", "aValue", "a-link.com", "Full Name", true, true))
}

func TestHtml(t *testing.T) {
assert.Equal(t, template.HTML("s"), html("s"))
}
4 changes: 3 additions & 1 deletion lang/cy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1202,5 +1202,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 }}"
}
4 changes: 3 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1134,5 +1134,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 }}"
}
57 changes: 11 additions & 46 deletions web/template/layout/attorney-summary.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -89,52 +89,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 ) }}

{{ $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 ) }}

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

{{ $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 ) }}
</dl>
</div>
</div>
Expand Down
71 changes: 14 additions & 57 deletions web/template/layout/certificate-provider-details.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -9,67 +9,24 @@
</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">{{ .Lpa.CertificateProvider.FullName }}</dd>
{{ if .CanChange }}
<dd class="govuk-summary-list__actions">
<a class="govuk-link govuk-link--no-visited-state" href="{{ $detailsLink }}#f-first-names">
{{ tr .App "change" }}<span class="govuk-visually-hidden"> {{ lowerFirst (tr .App "certificateProvider") }}</span>
</a>
</dd>
{{ end }}
</div>
{{ $nameChangeLink := printf "%s#f-first-names" $detailsLink }}
{{ template "summary-row" (summaryRow $.App "name" .Lpa.CertificateProvider.FullName $nameChangeLink .Lpa.CertificateProvider.FullName false .CanChange ) }}

<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">{{ tr .App "mobile" }}</dt>
<dd class="govuk-summary-list__value">{{ formatPhone .Lpa.CertificateProvider.Phone }}</dd>
{{ if .CanChange }}
<dd class="govuk-summary-list__actions">
<a class="govuk-link govuk-link--no-visited-state" href="{{ $detailsLink }}#f-mobile">
{{ tr .App "change" }}<span class="govuk-visually-hidden"> {{ tr .App "certificateProviderMobile" }}</span>
</a>
</dd>
{{ end }}
</div>
{{ $mobileChangeLink := printf "%s#f-mobile" $detailsLink }}
{{ template "summary-row" (summaryRow $.App "mobile" (formatPhone .Lpa.CertificateProvider.Phone) $mobileChangeLink .Lpa.CertificateProvider.FullName false .CanChange ) }}

<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">{{ tr .App "contactPreference" }}</dt>
<dd class="govuk-summary-list__value">{{ if .Lpa.CertificateProvider.Channel.IsPaper }}{{ tr .App "usingPaperForms" }}{{ else if .Lpa.CertificateProvider.Channel.IsOnline }}{{ tr .App "byEmail" }}{{ end }}</dd>
{{ if .CanChange }}
<dd class="govuk-summary-list__actions">
<a class="govuk-link govuk-link--no-visited-state" href="{{ $carryOutByLink }}">
{{ tr .App "change" }}<span class="govuk-visually-hidden"> {{ tr .App "certificateProviderContactPreference" }}</span>
</a>
</dd>
{{ end }}
</div>
{{ $contactValue := "" }}
{{ if .Lpa.CertificateProvider.Channel.IsPaper }} {{ $contactValue = tr .App "usingPaperForms" }} {{ else if .Lpa.CertificateProvider.Channel.IsOnline }} {{ $contactValue = tr .App "byEmail" }} {{ end }}

{{ if .Lpa.CertificateProvider.Email }}
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">{{ tr .App "email" }}</dt>
<dd class="govuk-summary-list__value">{{ .Lpa.CertificateProvider.Email }}</dd>
{{ if .CanChange }}
<dd class="govuk-summary-list__actions">
<a class="govuk-link govuk-link--no-visited-state" href="{{ $carryOutByLink }}#f-email">
{{ tr .App "change" }}<span class="govuk-visually-hidden"> {{ tr .App "certificateProviderEmail" }}</span>
</a>
</dd>
{{ end }}
</div>
{{ end }}
{{ template "summary-row" (summaryRow $.App "contactPreference" $contactValue $carryOutByLink .Lpa.CertificateProvider.FullName false .CanChange ) }}

<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">{{ if .Lpa.CertificateProvider.Relationship.IsProfessionally }} {{ tr .App "workAddress" }} {{ else }} {{ tr .App "address" }} {{ end }}</dt>
<dd class="govuk-summary-list__value">{{ template "address-lines" .Lpa.CertificateProvider.Address }}</dd>
{{ if .CanChange }}
<dd class="govuk-summary-list__actions">
<a class="govuk-link govuk-link--no-visited-state" href="{{ $addressLink }}#f-address-line-1">
{{ tr .App "change" }}<span class="govuk-visually-hidden"> {{ tr .App "certificateProviderAddress" }}</span>
</a>
</dd>
{{ end }}
</div>
{{ $emailChangeLink := printf "%s#f-email" $carryOutByLink }}
{{ template "summary-row" (summaryRow $.App "email" .Lpa.CertificateProvider.Email $emailChangeLink .Lpa.CertificateProvider.FullName true .CanChange ) }}

{{ $addressChangeLink := printf "%s#f-address-line-1" $addressLink }}
{{ $addressLabel := tr .App "address" }}
{{ if .Lpa.CertificateProvider.Relationship.IsProfessionally }} {{ $addressLabel = tr .App "workAddress" }} {{ end }}
{{ template "summary-row" (summaryRow $.App $addressLabel .Lpa.CertificateProvider.Address.HTML $addressChangeLink .Lpa.CertificateProvider.FullName false .CanChange ) }}
</dl>
</div>
</div>
Expand Down
18 changes: 18 additions & 0 deletions web/template/layout/summary-row.gohtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{ define "summary-row" }}
<div class="govuk-summary-list__row {{ if eq "" .Value }} govuk-summary-list__row--no-actions {{ end }}">
<dt class="govuk-summary-list__key">{{ tr .App .Label }} {{ if .Optional }} ({{ tr .App "optional" }}) {{ end }}</dt>
<dd class="govuk-summary-list__value">
{{ if .Value }}
{{ html .Value }}
{{ else }}
<a href="{{ .ChangeLink }}" class="govuk-link">{{ tr .App "enter" }} {{ lowerFirst (tr .App .Label) }}<span class="govuk-visually-hidden"> {{ trFormat .App "forFullName" "FullName" .FullName }}</span></a>
{{ end }}
</dd>
{{ if and .Value .CanChange }}
<dd class="govuk-summary-list__actions">
<a class="govuk-link govuk-link--no-visited-state" href="{{ .ChangeLink }}">{{ tr .App "change" }}<span class="govuk-visually-hidden"> {{ lowerFirst (tr .App .Label) }} {{ trFormat .App "forFullName" "FullName" .FullName }}</span>
</a>
</dd>
{{ end }}
</div>
{{ end }}

0 comments on commit 3eadcf4

Please sign in to comment.