Skip to content

Commit

Permalink
Edit start page when Change Reqeusts exist
Browse files Browse the repository at this point in the history
  • Loading branch information
albertkol committed Feb 5, 2025
1 parent e09046f commit 36788da
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,34 @@ export class PageControllerBase {
}
}
}

// if page is start page and we have change requests for the form
if (isStartPage && state["metadata"] && state["metadata"]["change_requests"]) {
// make sure all components on the start page are HTML components
let allComponentsArePara = true;
for (let component of viewModel.components) {
if (component.type !== "Para") {
allComponentsArePara = false;
break;
}
}

// if all components are HTML components, replace them with a change request message
if (allComponentsArePara) {
const title = "<h1 class='govuk-heading-m'>Change requested</h1>";
const paragraph = "<p class='govuk-body'>We need you to make some changes to parts of this section. You will need to go through the section to:</p>";
const list = "<ul class='govuk-list govuk-list--bullet govuk-!-margin-bottom-8'><li>amend the parts where a change request has been made</li><li>check your other information</li><li>send the changes back for approval</li></ul>";
const changeRequestMessage = title + paragraph + list
console.log(viewModel.components[0])
viewModel.components = [{
type: "Para",
model: {
content: changeRequestMessage
}
}];
}
}

return h.view(this.viewName, viewModel);
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const {suite, test, before, after, beforeEach, afterEach} = lab;
suite("StartPageController", () => {
let server;
let response;
let adapterCacheService;
let $;
let sandbox;

Expand Down Expand Up @@ -86,4 +87,33 @@ suite("StartPageController", () => {
expect(viewModel.isStartPage).to.be.true();
expect(viewModel.skipTimeoutWarning).to.be.true();
});

test("start page show change request message", async () => {
// Define the mock state with metadata
const mockState = {
metadata: {
change_requests: {
"aBcDeFg": ["Change request message"],
}
}
// Add any other necessary metadata here
};

// Stub getState to return the mock state
adapterCacheService.getState.resolves(mockState);

const pages = [...form.pages];
const firstPage = pages.shift();
const formDef = {...form, pages: [firstPage, ...pages]};
let formModel = new AdapterFormModel(formDef, {});
const pageController = new StartPageController(formModel, firstPage);
const vm = pageController.getViewModel({}, formModel);
vm.i18n = {
__: mockI18n
};
response = await server.render("summary", vm);

$ = cheerio.load(response);
expect($(".govuk-heading-m").text()).to.contain("Change requested");
});
});

0 comments on commit 36788da

Please sign in to comment.