diff --git a/src/components/common/layout/base-integration.test.ts b/src/components/common/layout/base-integration.test.ts new file mode 100644 index 0000000000..236407f801 --- /dev/null +++ b/src/components/common/layout/base-integration.test.ts @@ -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); + }); +}); diff --git a/src/components/common/layout/base.njk b/src/components/common/layout/base.njk index a829c6df2e..83487049d5 100644 --- a/src/components/common/layout/base.njk +++ b/src/components/common/layout/base.njk @@ -59,12 +59,14 @@ {% block main %}
+ {% if webChannel %} {{ govukPhaseBanner({ tag: { text: 'general.phaseBanner.tag' | translate }, html: phaseBannerText }) }} + {% endif %} {% block beforeContent %}{% endblock %} {% if languageToggleEnabled %} {{ languageSelect({