Skip to content

Commit

Permalink
Merge 1bfe391 into 58f03c6
Browse files Browse the repository at this point in the history
  • Loading branch information
acsauk authored Jun 5, 2024
2 parents 58f03c6 + 1bfe391 commit 06cf893
Show file tree
Hide file tree
Showing 27 changed files with 310 additions and 410 deletions.
15 changes: 11 additions & 4 deletions cmd/enumerator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,10 +739,15 @@ func (g *Generator) buildOneRun(runs [][]Value, typeName string) {
if values[0].signed {
lessThanZero = "i < 0 || "
}
emptyEarlyReturn := ""
if g.empty {
emptyEarlyReturn = "if i == 0 {\n return \"\"\n}\n"
}

if values[0].value == 0 { // Signed or unsigned, 0 is still 0.
g.Printf(stringOneRun, typeName, usize(len(values)), lessThanZero)
g.Printf(stringOneRun, typeName, usize(len(values)), lessThanZero, emptyEarlyReturn)
} else {
g.Printf(stringOneRunWithOffset, typeName, values[0].String(), usize(len(values)), lessThanZero)
g.Printf(stringOneRunWithOffset, typeName, values[0].String(), usize(len(values)), lessThanZero, emptyEarlyReturn)
}
}

Expand All @@ -751,8 +756,9 @@ func (g *Generator) buildOneRun(runs [][]Value, typeName string) {
// [1]: type name
// [2]: size of index element (8 for uint8 etc.)
// [3]: less than zero check (for signed types)
// [4]: early return when empty set and empty string
const stringOneRun = `func (i %[1]s) String() string {
if %[3]si >= %[1]s(len(_%[1]s_index)-1) {
%[4]s if %[3]si >= %[1]s(len(_%[1]s_index)-1) {
return "%[1]s(" + strconv.FormatInt(int64(i), 10) + ")"
}
return _%[1]s_name[_%[1]s_index[i]:_%[1]s_index[i+1]]
Expand All @@ -765,8 +771,9 @@ const stringOneRun = `func (i %[1]s) String() string {
// [2]: lowest defined value for type, as a string
// [3]: size of index element (8 for uint8 etc.)
// [4]: less than zero check (for signed types)
// [5]: early return when empty set and empty string
const stringOneRunWithOffset = `func (i %[1]s) String() string {
i -= %[2]s
%[5]s i -= %[2]s
if %[4]si >= %[1]s(len(_%[1]s_index)-1) {
return "%[1]s(" + strconv.FormatInt(int64(i + %[2]s), 10) + ")"
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/enumerator/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ const _Day_name = "MondayTuesdayWednesdayThursdayFridaySaturdaySunday"
var _Day_index = [...]uint8{0, 6, 13, 22, 30, 36, 44, 50}
func (i Day) String() string {
if i == 0 {
return ""
}
i -= 1
if i < 0 || i >= Day(len(_Day_index)-1) {
return "Day(" + strconv.FormatInt(int64(i+1), 10) + ")"
Expand Down
2 changes: 1 addition & 1 deletion docker/mlpa/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ COPY --from=asset-env /app/web/static web/static

ARG TARGETOS TARGETARCH

RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go install github.com/cosmtrek/air@latest && go install github.com/go-delve/delve/cmd/dlv@latest
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go install github.com/air-verse/air@latest && go install github.com/go-delve/delve/cmd/dlv@latest

ENTRYPOINT ["air"]

Expand Down
3 changes: 3 additions & 0 deletions internal/actor/enum_attorneysact.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions internal/actor/enum_certificateproviderrelationship.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions internal/actor/enum_channel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions internal/actor/enum_lifesustainingtreatment.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions internal/actor/enum_lpatype.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions internal/actor/enum_replacementattorneysstepin.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions internal/actor/enum_yesnomaybe.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions internal/localize/enum_lang.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions internal/pay/enum_evidencedelivery.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions internal/pay/enum_previousfee.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 41 additions & 13 deletions internal/templatefn/fn.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/ministryofjustice/opg-modernising-lpa/internal/localize"
"github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/place"
)

// Globals contains values that are used in templates and do not change as the
Expand Down Expand Up @@ -51,7 +52,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 +80,9 @@ func All(globals *Globals) map[string]any {
"notificationBanner": notificationBanner,
"checkboxEq": checkboxEq,
"lpaDecisions": lpaDecisions,
"summaryRow": summaryRow,
"addressSummaryRow": addressSummaryRow,
"optionalSummaryRow": optionalSummaryRow,
}
}

Expand Down Expand Up @@ -184,18 +188,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 @@ -496,3 +488,39 @@ func lpaDecisions(app page.AppData, lpa any, canChange bool) lpaDecisionsData {

return data
}

func summaryRow(app page.AppData, label, value, changeLink, fullName string, canChange, summarisingSelf bool) map[string]any {
return map[string]any{
"App": app,
"Label": label,
"Value": value,
"ChangeLink": changeLink,
"FullName": fullName,
"CanChange": canChange,
"SummarisingSelf": summarisingSelf,
}
}

func addressSummaryRow(app page.AppData, label string, address place.Address, changeLink, fullName string, canChange, summarisingSelf bool) map[string]any {
return map[string]any{
"App": app,
"Label": label,
"Address": address,
"ChangeLink": changeLink,
"FullName": fullName,
"CanChange": canChange,
"SummarisingSelf": summarisingSelf,
}
}

func optionalSummaryRow(app page.AppData, label, value, changeLink, fullName string, canChange, summarisingSelf bool) map[string]any {
return map[string]any{
"App": app,
"Label": label,
"Value": value,
"ChangeLink": changeLink,
"FullName": fullName,
"CanChange": canChange,
"SummarisingSelf": summarisingSelf,
}
}
62 changes: 55 additions & 7 deletions internal/templatefn/fn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/ministryofjustice/opg-modernising-lpa/internal/localize"
"github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/place"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -158,13 +159,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 @@ -560,3 +554,57 @@ 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"

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

func TestAddressSummaryRow(t *testing.T) {
app := page.AppData{SessionID: "abc"}
label := "a-label"
address := place.Address{Line1: "a"}
changeLink := "a-link.com"
fullName := "Full Name"

assert.Equal(t, map[string]any{
"App": app,
"Label": label,
"Address": address,
"ChangeLink": changeLink,
"FullName": fullName,
"CanChange": true,
"SummarisingSelf": true,
}, addressSummaryRow(app, label, address, changeLink, fullName, true, true))
}

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

assert.Equal(t, map[string]any{
"App": app,
"Label": label,
"Value": value,
"ChangeLink": changeLink,
"FullName": fullName,
"CanChange": true,
"SummarisingSelf": true,
}, optionalSummaryRow(app, label, value, changeLink, fullName, true, true))
}
11 changes: 3 additions & 8 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 @@ -669,10 +665,8 @@
"whatToDoIfAnyDetailsAreIncorrect": "Beth i’w wneud os yw unrhyw rai o’r manylion a roddwyd amdanoch yn anghywir",
"whatToDoIfAnyDetailsAreIncorrectAttorneyContent": "<p class=\"govuk-body\">Os byddwch yn gweld camgymeriad yn yr enw, y dyddiad geni neu’r cyfeiriad y mae’r rhoddwr wedi’u darparu ar eich cyfer, ni ddylech barhau.</p><p class=\"govuk-body\">Bydd angen i chi roi gwybod i’r rhoddwr fel y bydd yn gallu newid eich manylion.</p><p class=\"govuk-body\">Unwaith y bydd wedi newid eich manylion, bydd angen i chi fewngofnodi eto a chadarnhau bod eich manylion yn gywir.</p>",
"anyErrorsInYourDetailsCanDelay": "Gall unrhyw gamgymeriadau yn eich manylion achosi oedi cyn prosesu’r LPA.",
"changeDateOfBirthLink": "Newid<span class=\"govuk-visually-hidden\"> dyddiad geni</span>",
"mobileNumber": "Rhif ffôn symudol",
"telephoneNumber": "Rhif ffôn",
"changeTelephoneNumberLink": "Newid<span class=\"govuk-visually-hidden\"> y rhif ffôn</span>",
"anyErrorsInYourDetailsCanMakeLpaDifficultToUse": "Os bydd unrhyw wallau yn eich manylion, gall hynny ei gwneud yn anodd defnyddio’r LPA. Mae’n bosibl na fydd sefydliadau’n derbyn yr LPA os nad yw’ch manylion yn cyfateb i’ch data adnabod.",
"youHaveUnsavedChanges": "Rydych wedi gwneud newidiadau sydd heb eu cadw",
"unsavedChangesDialogContent": "I gadw’r rhain, ewch yn ôl i’r dudalen a dewis <span class=\"govuk-body govuk-!-font-weight-bold\">Cadw a pharhau</span>.",
Expand Down Expand Up @@ -950,7 +944,6 @@
"yourHomeAddressWillNotBeShown": "Ni fydd cyfeiriad eich cartref yn cael ei ddangos i’r rhoddwr ac ni fydd yn ymddangos ar yr LPA ar ôl ei chwblhau.",
"selectYourHomeAddress": "Dewis eich cyfeiriad cartref",
"yourHomeAddress": "Eich cyfeiriad cartref",
"changeHomeAddressLink": "Newid eich<span class=\"govuk-visually-hidden\"> cyfeiriad cartref</span>",
"homeAddress": "Cyfeiriad cartref",
"goToDashboard": "I’r dangosfwrdd",
"printThisPage": "Argraffu’r dudalen hon",
Expand Down Expand Up @@ -1202,5 +1195,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 }}"
}
Loading

0 comments on commit 06cf893

Please sign in to comment.