Skip to content

Commit

Permalink
AUT-3779: Add utility to retrieve a channel-specific template
Browse files Browse the repository at this point in the history
It has been decided that the Strategic App will reuse the
existing Web journey by replaying journeys created for the Web in
mobile WebViews. The ADR[^1] describes two technical approaches
to support this, one of which is 'Independent Pages' (i.e. where
there is significant difference between the Web and Mobile
presentation of a journey step, this will be reflected in there
being separate templates).

The utility added in this commit will support the 'Independent
Pages' approach by allowing the template to be selected based
on the channel and a mapping between Web templates and their
mobile equivalents.

[^1]: govuk-one-login/architecture#738
  • Loading branch information
gtvj committed Nov 4, 2024
1 parent 88b0550 commit 6c47b89
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/utils/get-channel-specific-template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { logger } from "./logger";

export function getChannelSpecificTemplate(
webTemplateAndPath: string,
isStrategicAppChannel: boolean,
templateMappings: Record<string, string>
): string {
if (!isStrategicAppChannel) {
return webTemplateAndPath;
}

const appTemplate = templateMappings[webTemplateAndPath];
if (appTemplate === undefined) {
logger.warn(
`No '${webTemplateAndPath}' property found in templateMappings. Falling back to web template`
);
return webTemplateAndPath;
}
return appTemplate;
}
43 changes: 43 additions & 0 deletions test/unit/utils/get-channel-specific-template.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { expect } from "chai";
import { describe } from "mocha";
import { getChannelSpecificTemplate } from "../../../src/utils/get-channel-specific-template";

const mappings = {
"webTemplate.njk": "mobileTemplate.njk",
};

describe("getChannelSpecificTemplate", () => {
describe("where the channel is not mobile", () => {
describe("and the webTemplateAndPath is not mapped", () => {
it("should return the original webTemplateAndPath", () => {
expect(
getChannelSpecificTemplate("notMappedTemplate.njk", false, mappings)
).to.equal("notMappedTemplate.njk");
});
});
describe("and the webTemplateAndPath is mapped", () => {
it("should return the original webTemplateAndPath", () => {
expect(
getChannelSpecificTemplate("webTemplate.njk", false, mappings)
).to.equal("webTemplate.njk");
});
});
});

describe("where the channel is mobile", () => {
describe("and the webTemplateAndPath is not mapped", () => {
it("should return the original webTemplateAndPath", () => {
expect(
getChannelSpecificTemplate("notMappedTemplate.njk", true, mappings)
).to.equal("notMappedTemplate.njk");
});
});
describe("and the webTemplateAndPath is mapped", () => {
it("should return the original webTemplateAndPath", () => {
expect(
getChannelSpecificTemplate("webTemplate.njk", true, mappings)
).to.equal("mobileTemplate.njk");
});
});
});
});

0 comments on commit 6c47b89

Please sign in to comment.