-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AUT-3779: Add utility to retrieve a channel-specific template
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
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); | ||
}); | ||
}); | ||
}); |