Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display change requests #114

Merged
merged 2 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,43 @@ export class PageController extends PageControllerBase {
},
};
}

makeGetRouteHandler() {
return async (request: HapiRequest, h: HapiResponseToolkit) => {
// Call the parent class's makeGetRouteHandler method and get the response
const parentResponse = await super.makeGetRouteHandler()(request, h);

const {adapterCacheService} = request.services([]);

// @ts-ignore
const state = await adapterCacheService.getState(request);

// Extract the viewModel from the parent's response
const viewModel = parentResponse.source.context;

viewModel.changeRequests = [];
const changeRequests = state.metadata?.change_requests;
if (changeRequests && Object.keys(changeRequests).length > 0) {
for (let componentName in changeRequests) {
const messages = changeRequests[componentName];

// Find the component with the matching the change request
const pageComponents = this.pageDef.components;
const component = pageComponents.find(component => {
return component.name === componentName
});

if (component) {
// Add an object to viewModel.changeRequests
viewModel.changeRequests.push({
title: component.title,
messages: messages
});
}
}
}

return h.view(this.viewName, viewModel);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
RelativeUrl,
} from "../../../../../../digital-form-builder/runner/src/server/plugins/engine";
import {
ChangeRequest,
HapiRequest,
HapiResponseObject,
HapiResponseToolkit,
Expand Down Expand Up @@ -153,6 +154,7 @@ export class PageControllerBase {
backLinkText?: string;
continueButtonText?: string;
phaseTag?: string | undefined;
changeRequests?: ChangeRequest[] | undefined;
} {
let showTitle = true;
let pageTitle = this.title;
Expand Down
6 changes: 6 additions & 0 deletions runner/src/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ import {AdapterStatusService} from "./services";
import {WebhookService} from "./services/WebhookService";
import {TranslationLoaderService} from "./services/TranslationLoaderService";


export type ChangeRequest = {
title: string;
messages: string[];
}

export type Services = (services: string[]) => {
adapterCacheService: AdapterCacheService;
notifyService: NotifyService;
Expand Down
5 changes: 5 additions & 0 deletions runner/src/server/views/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{% from "footer/macro.njk" import govukFooter -%}
{% from "phase-banner/macro.njk" import govukPhaseBanner %}
{% from "skip-link/macro.njk" import govukSkipLink -%}
{% from "./partials/change-requests-banner.html" import changeRequestsBanner %}


{% block head %}
Expand Down Expand Up @@ -191,6 +192,10 @@
text: backLinkText
}) }}
{% endif %}

{% if changeRequests.length > 0 %}
{{ changeRequestsBanner(changeRequests) }}
{% endif %}
{% endblock %}


Expand Down
25 changes: 25 additions & 0 deletions runner/src/server/views/partials/change-requests-banner.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{% macro changeRequestsBanner(changeRequests) %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<div class="govuk-!-margin-top-4">
<div class="govuk-notification-banner" role="region" aria-labelledby="govuk-notification-banner-title" data-module="govuk-notification-banner">
<div class="govuk-notification-banner__header">
<h2 class="govuk-notification-banner__title" id="govuk-notification-banner-title">
Change request
</h2>
</div>
<div class="govuk-notification-banner__content">
{% for question in changeRequests %}
<h3 class="govuk-heading-s govuk-!-margin-bottom-2">
{{ question.title }}
</h3>
{% for message in question.messages %}
<p class="govuk-body govuk-!-margin-bottom-1">{{ message }}</p>
{% endfor %}
{% endfor %}
</div>
</div>
</div>
</div>
</div>
{% endmacro %}
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,60 @@ suite("PageController", () => {
console.error("Error during test:", error);
}
});

test("should display change request banner on page with feedback", async () => {
server = await createServer({
formFileName: "sample-page.test.json",
formFilePath: path.join(__dirname, "../../../"),
enforceCsrf: false,
});

const { adapterCacheService } = server.services();
adapterCacheService.getState = () => {
return Promise.resolve({
metadata: {
change_requests: {
"VcyKVN": ["Assessor Feedback"]
}
}
});
};

const response = await server.inject({
method: 'GET',
url: '/sample-page.test/project-name',
});

$ = cheerio.load(response.payload);

expect($("h2").text()).to.contain("Change request");
});

test("should no display change request banner on page without feedback", async () => {
server = await createServer({
formFileName: "sample-page.test.json",
formFilePath: path.join(__dirname, "../../../"),
enforceCsrf: false,
});

const { adapterCacheService } = server.services();
adapterCacheService.getState = () => {
return Promise.resolve({
metadata: {
change_requests: {
"no_found": ["Assessor Feedback"]
}
}
});
};

const response = await server.inject({
method: 'GET',
url: '/sample-page.test/project-name',
});

$ = cheerio.load(response.payload);

expect($("h2").text()).to.not.contain("Change request");
});
});
84 changes: 84 additions & 0 deletions runner/test/cases/server/sample-page.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"startPage": "/project-details",
"pages": [
{
"path": "/summary",
"title": "Summary",
"components": [],
"next": [],
"section": "FabDefault",
"controller": "./pages/summary.js"
},
{
"title": "Project details",
"path": "/project-details",
"components": [
{
"name": "orUXQc",
"options": {},
"type": "Para",
"content": "<label class=\"govuk-!-font-weight-bold\">In this section, we'll ask about:\n</label>\n\n<div class=\"govuk-body\">\n<ul class=\"govuk-list govuk-list--bullet\">\n<li>project name</li>\n<li>project overview</li>\n</ul>\n</div>",
"schema": {}
}
],
"next": [
{
"path": "/project-name"
}
],
"controller": "./pages/start.js"
},
{
"path": "/project-overview",
"title": "Project overview",
"components": [
{
"options": {},
"type": "FreeTextField",
"title": "Project overview",
"hint": "Give a brief summary of your project, including what you hope to achieve",
"schema": {},
"name": "KJtdhs"
}
],
"next": [
{
"path": "/summary"
}
],
"section": "FabDefault"
},
{
"path": "/project-name",
"title": "Project name",
"components": [
{
"options": {},
"type": "TextField",
"title": "Project name",
"hint": "",
"schema": {},
"name": "VcyKVN"
}
],
"next": [
{
"path": "/project-overview"
}
],
"section": "FabDefault"
}
],
"lists": [],
"conditions": [],
"sections": [
{
"name": "FabDefault",
"title": "Default section",
"hideTitle": true
}
],
"outputs": [],
"skipSummary": false,
"name": "Apply for Sample Fund"
}
Loading