-
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.
Merge pull request #3108 from ONSdigital/EAR-2382-replace-emphasis-wi…
…th-strong EAR 2382 and EAR 2383 replace emphasis tags with strong tags
- Loading branch information
Showing
37 changed files
with
245 additions
and
154 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,25 @@ | ||
const convertEmTagsToStrongTags = (inputData) => { | ||
if (inputData !== null && inputData !== undefined) { | ||
if (typeof inputData === "string") { | ||
/* | ||
Removes em tags wrapped in strong tags and em tags wrapped around strong tags before converting em tags | ||
Prevents wrapping text in two strong tags when it was previously wrapped in both strong and em tags | ||
*/ | ||
inputData = inputData | ||
.replace(/<strong><em>|<em><strong>/g, "<strong>") | ||
.replace(/<\/em><\/strong>|<\/strong><\/em>/g, "</strong>") | ||
.replace(/<em>/g, "<strong>") | ||
.replace(/<\/em>/g, "</strong>"); | ||
} else if (Array.isArray(inputData)) { | ||
inputData = inputData.map((item) => convertEmTagsToStrongTags(item)); | ||
} else if (typeof inputData === "object") { | ||
Object.keys(inputData).forEach((key) => { | ||
inputData[key] = convertEmTagsToStrongTags(inputData[key]); | ||
}); | ||
} | ||
} | ||
|
||
return inputData; | ||
}; | ||
|
||
module.exports = (questionnaire) => convertEmTagsToStrongTags(questionnaire); |
78 changes: 78 additions & 0 deletions
78
eq-author-api/migrations/convertEmTagsToStrongTags.test.js
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,78 @@ | ||
const convertEmTagsToStrongTags = require("./convertEmTagsToStrongTags"); | ||
|
||
describe("convertEmTagsToStrongTags", () => { | ||
it("should replace em tags with strong tags in a string", () => { | ||
const emText = "<em>Question 1</em>"; | ||
|
||
expect(convertEmTagsToStrongTags(emText)).toEqual( | ||
"<strong>Question 1</strong>" | ||
); | ||
}); | ||
|
||
it("should not replace strong tags", () => { | ||
const strongText = "<strong>Question 1</strong>"; | ||
|
||
expect(convertEmTagsToStrongTags(strongText)).toEqual(strongText); | ||
}); | ||
|
||
it("should replace em tags with strong tags in an array of strings", () => { | ||
const emArray = ["<em>Question 1</em>", "<em>Question 2</em>"]; | ||
|
||
expect(convertEmTagsToStrongTags(emArray)).toEqual([ | ||
"<strong>Question 1</strong>", | ||
"<strong>Question 2</strong>", | ||
]); | ||
}); | ||
|
||
it("should replace em tags with strong tags in an object", () => { | ||
const page = { | ||
title: "<em>Test title</em>", | ||
description: "<em>Test description</em>", | ||
answers: [ | ||
{ | ||
label: "<em>Answer 1</em>", | ||
}, | ||
{ | ||
label: "<em>Answer 2</em>", | ||
}, | ||
], | ||
}; | ||
|
||
expect(convertEmTagsToStrongTags(page)).toEqual({ | ||
title: "<strong>Test title</strong>", | ||
description: "<strong>Test description</strong>", | ||
answers: [ | ||
{ | ||
label: "<strong>Answer 1</strong>", | ||
}, | ||
{ | ||
label: "<strong>Answer 2</strong>", | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
it("should not wrap text in two strong tags when text is wrapped in strong and em tags", () => { | ||
const emTagsWrappedInStrong = "<strong><em>Question 1</em></strong>"; | ||
const strongTagsWrappedInEm = "<em><strong>Question 2</strong></em>"; | ||
|
||
expect(convertEmTagsToStrongTags(emTagsWrappedInStrong)).toEqual( | ||
"<strong>Question 1</strong>" | ||
); | ||
expect(convertEmTagsToStrongTags(strongTagsWrappedInEm)).toEqual( | ||
"<strong>Question 2</strong>" | ||
); | ||
}); | ||
|
||
it("should return undefined if inputData is undefined", () => { | ||
expect(convertEmTagsToStrongTags(undefined)).toBeUndefined(); // convertEmTagsToStrongTags returns inputData, which is undefined | ||
}); | ||
|
||
it("should return null if inputData is null", () => { | ||
expect(convertEmTagsToStrongTags(null)).toBeNull(); // convertEmTagsToStrongTags returns inputData, which is null | ||
}); | ||
|
||
it("should return inputData if inputData is not string, array, or object", () => { | ||
expect(convertEmTagsToStrongTags(true)).toEqual(true); | ||
}); | ||
}); |
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.