Skip to content

Commit

Permalink
[DFC-661]: Add conditional rendering of beta banner and integration t…
Browse files Browse the repository at this point in the history
…ests
  • Loading branch information
SophiaDWokoma committed Oct 1, 2024
1 parent 5450d8a commit cd4e48e
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
69 changes: 69 additions & 0 deletions src/components/common/layout/base-integration.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import request from "supertest";
import { describe } from "mocha";
import { expect } from "chai";
import * as cheerio from "cheerio";
import { sinon } from "../../../../test/utils/test-utils";
import nock = require("nock");
import decache from "decache";
import { PATH_NAMES, CHANNEL } from "../../../app.constants";

describe("Integration:: base page ", () => {
let app: any;

const setupApp = async (channel: string) => {
decache("../../../app");
decache("../../../middleware/session-middleware");
const sessionMiddleware = require("../../../middleware/session-middleware");
sinon
.stub(sessionMiddleware, "validateSessionMiddleware")
.callsFake(function (req: any, res: any, next: any): void {
res.locals.sessionId = "tDy103saszhcxbQq0-mjdzU854";
if (channel === CHANNEL.WEB) {
res.locals.webChannel = true;
} else if (channel === CHANNEL.STRATEGIC_APP) {
res.locals.strategicAppChannel = true;
}

req.session.client = {
serviceType: "MANDATORY",
};
req.session.user = {
email: "test@test.com",

phoneNumber: "7867",
journey: {
nextPath: PATH_NAMES.SIGN_IN_OR_CREATE,
},
};

next();
});

app = await require("../../../app").createApp();
};

beforeEach(() => {
nock.cleanAll();
});

after(() => {
sinon.restore();
app = undefined;
});

it("beta banner should be on page", async () => {
await setupApp(CHANNEL.WEB);
const response = await request(app).get(PATH_NAMES.SIGN_IN_OR_CREATE);
expect(response.status).to.equal(200);
const $ = cheerio.load(response.text);
expect($(".govuk-phase-banner").length).to.equal(1);
});

it("beta banner should not be on page", async () => {
await setupApp(CHANNEL.STRATEGIC_APP);
const response = await request(app).get(PATH_NAMES.SIGN_IN_OR_CREATE);
expect(response.status).to.equal(200);
const $ = cheerio.load(response.text);
expect($(".govuk-phase-banner").length).to.equal(0);
});
});
2 changes: 2 additions & 0 deletions src/components/common/layout/base.njk
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@

{% block main %}
<div class="govuk-width-container {{ containerClasses }}">
{% if webChannel %}
{{ govukPhaseBanner({
tag: {
text: 'general.phaseBanner.tag' | translate
},
html: phaseBannerText
}) }}
{% endif %}
{% block beforeContent %}{% endblock %}
{% if languageToggleEnabled %}
{{ languageSelect({
Expand Down

0 comments on commit cd4e48e

Please sign in to comment.