Skip to content

Commit 43ad05c

Browse files
authored
chore: merge upstream changes (#522)
1 parent 176fabd commit 43ad05c

File tree

8 files changed

+21
-26
lines changed

8 files changed

+21
-26
lines changed

e2e/cypress/e2e/runner/RepeatingSectionSummaryPageController.feature

Lines changed: 0 additions & 17 deletions
This file was deleted.

runner/src/server/plugins/engine/models/SummaryViewModel.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export class SummaryViewModel {
5656
_webhookData: WebhookData | undefined;
5757
callback?: InitialiseSessionOptions;
5858
showPaymentSkippedWarningPage: boolean = false;
59+
returnUrl: string;
5960
constructor(
6061
pageTitle: string,
6162
model: FormModel,
@@ -130,6 +131,7 @@ export class SummaryViewModel {
130131
const { feeOptions } = model;
131132
this.showPaymentSkippedWarningPage =
132133
feeOptions.showPaymentSkippedWarningPage ?? false;
134+
this.returnUrl = `/${model.basePath}/summary`;
133135
}
134136

135137
private processErrors(result, details) {

runner/src/server/plugins/engine/pageControllers/PageControllerBase.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export class PageControllerBase {
6666
backLinkFallback?: string;
6767
details?: any;
6868
disableBackLink?: boolean;
69+
returnUrl?: string;
6970

7071
// TODO: pageDef type
7172
constructor(model: FormModel, pageDef: { [prop: string]: any } = {}) {
@@ -154,6 +155,7 @@ export class PageControllerBase {
154155
backLink?: string;
155156
phaseTag?: string | undefined;
156157
details?: any;
158+
returnUrl?: string | undefined;
157159
} {
158160
let showTitle = true;
159161
let pageTitle = this.title;
@@ -205,6 +207,7 @@ export class PageControllerBase {
205207
errors,
206208
isStartPage: false,
207209
details: this.details || undefined,
210+
returnUrl: this.returnUrl || undefined,
208211
};
209212
}
210213

runner/src/server/plugins/engine/pageControllers/RepeatingSectionSummaryPageController.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { PageController } from "./PageController";
88
export class RepeatingSectionSummaryPageController extends PageController {
99
makeGetRouteHandler() {
1010
return async (request: HapiRequest, h: HapiResponseToolkit) => {
11-
const { remove } = request.query;
11+
const { remove, returnUrl } = request.query;
1212
const { cacheService } = request.services([]);
1313
const state = await cacheService.getState(request);
1414
const noInt = (str: string) => str.replace(/\d+/g, "");
@@ -34,22 +34,27 @@ export class RepeatingSectionSummaryPageController extends PageController {
3434
}
3535
});
3636
await cacheService.mergeState(request, newState);
37+
let param = "";
38+
if (returnUrl) param = `?returnUrl=${encodeURIComponent(returnUrl)}`;
3739

3840
if (int(this.path) === summaryFiltered.length) {
41+
const newPath = noInt(this.path) + (int(this.path) - 1);
3942
return h.redirect(
40-
`/${this.model.basePath}${noInt(this.path)}${int(this.path) - 1}`
43+
`/${this.model.basePath}${newPath}${param}`
4144
);
4245
}
43-
return h.redirect(`/${this.model.basePath}${this.path}`);
46+
return h.redirect(`/${this.model.basePath}${this.path}${param}`);
4447
}
4548

4649
this.details = summaryFiltered.map((detail) => {
50+
if (returnUrl) return detail;
4751
const currentPath = this.path.replace("/", "");
4852
return {
4953
...detail,
5054
card: detail.items[0].url.replace("summary", currentPath),
5155
};
5256
});
57+
this.returnUrl = returnUrl;
5358
return super.makeGetRouteHandler()(request, h);
5459
};
5560
}

runner/src/server/views/partials/summary-card.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% from "./summary-row.html" import summaryRow %} {% macro summaryCard(data, hideRemove)
1+
{% from "./summary-row.html" import summaryRow %} {% macro summaryCard(data, hideRemove, returnUrl)
22
%} {% set isRepeatableSection = (data.items[0] | isArray) %}
33

44
<div class="govuk-summary-card">
@@ -8,7 +8,7 @@ <h2 class="govuk-summary-card__title" name="{{data.title}}" id="{{data.title}}">
88
<ul class="govuk-summary-card__actions">
99
{% if not hideRemove %}
1010
<li class="govuk-summary-card__action">
11-
<a class="govuk-link" href="?remove={{ data.name }}">
11+
<a class="govuk-link" href="?remove={{ data.name }}{{ "&returnUrl=" + returnUrl if returnUrl }}">
1212
Delete<span class="govuk-visually-hidden"> {{data.title}}</span>
1313
</a>
1414
</li>

runner/src/server/views/repeating-section-summary.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ <h1 class="govuk-heading-l">
2323
{% if details.length === 1 %}
2424
{{ summaryCard(detail, true) }}
2525
{% else %}
26-
{{ summaryCard(detail) }}
26+
{{ summaryCard(detail, false, returnUrl) }}
2727
{% endif %}
2828
{% endfor %}
2929

runner/src/server/views/summary.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ <h1 class="govuk-heading-l">
3131
{% if not details[loop.index].card %}
3232
{% set splitDash = detail.items[0].pageId.split("-") %}
3333
{% set lastEntry = splitDash.slice(-1)[0] %}
34+
{% set formAction = splitDash.slice(0, -1).concat(["added", lastEntry]).join("-") %}
3435

35-
<form action="{{ splitDash.slice(0, -1).concat(["added", lastEntry]).join("-") }}" method="get">
36+
<form action="{{ formAction }}" method="get">
37+
<input type="hidden" name="returnUrl" value="{{ returnUrl }}" />
3638
<button class="govuk-button govuk-button--secondary">
3739
Add {% if lastEntry !== "1" %} or delete {% endif %}
3840
{{ detail.title.split(" ").slice(0, -1).join(" ") | lower }}

runner/test/cases/server/upload.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ suite("uploads", () => {
7070

7171
stub(UploadService.prototype, "uploadDocuments").callsFake(async () => {
7272
return {
73-
error: "The selected files contained a virus",
73+
error: 'The selected files contain a virus',
7474
};
7575
});
7676

@@ -87,7 +87,7 @@ suite("uploads", () => {
8787

8888
const $ = cheerio.load(response.payload);
8989
expect($("[href='#file1']").text().trim()).to.equal(
90-
"The selected files contained a virus"
90+
'The selected files contain a virus'
9191
);
9292
});
9393

0 commit comments

Comments
 (0)