Skip to content

Commit

Permalink
Merge pull request #3108 from ONSdigital/EAR-2382-replace-emphasis-wi…
Browse files Browse the repository at this point in the history
…th-strong

EAR 2382 and EAR 2383 replace emphasis tags with strong tags
  • Loading branch information
farres1 authored Apr 29, 2024
2 parents 4b3d30b + 164f092 commit 633395c
Show file tree
Hide file tree
Showing 37 changed files with 245 additions and 154 deletions.
25 changes: 25 additions & 0 deletions eq-author-api/migrations/convertEmTagsToStrongTags.js
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 eq-author-api/migrations/convertEmTagsToStrongTags.test.js
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);
});
});
1 change: 1 addition & 0 deletions eq-author-api/migrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const migrations = [
require("./addAdditonalContentsToAddItemPage"),
require("./updateHealthThemeToPandemicMonitoring"),
require("./addAllowableDataVersions"),
require("./convertEmTagsToStrongTags"),
];

const currentVersion = migrations.length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ const InlineField = styled(Field)`
const contentControls = {
heading: true,
bold: true,
emphasis: true,
list: true,
link: true,
};
Expand Down
15 changes: 0 additions & 15 deletions eq-author/src/App/history/HistoryItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,6 @@ const EventText = styled.div`
p {
margin: 0 0 1em;
word-break: break-all;
em {
background-color: ${colors.highlightGreen};
font-style: normal;
}
}
h2 {
em {
background-color: ${colors.highlightGreen};
font-style: normal;
}
}
ul {
margin-top: 0;
Expand All @@ -89,10 +79,6 @@ const EventText = styled.div`
span {
font-weight: bold;
}
em {
background-color: ${colors.highlightGreen};
font-style: normal;
}
}
}
`;
Expand Down Expand Up @@ -160,7 +146,6 @@ const HistoryItem = ({
value={noteState}
controls={{
heading: true,
emphasis: true,
list: true,
bold: true,
}}
Expand Down
1 change: 0 additions & 1 deletion eq-author/src/App/history/HistoryPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ const HistoryPageContent = ({ match }) => {
value={noteState.value}
controls={{
heading: true,
emphasis: true,
list: true,
bold: true,
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ exports[`CollapsibleEditor should render 1`] = `
controls={
Object {
"bold": true,
"emphasis": true,
"link": true,
"list": true,
"piping": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const Detail = styled.div`
position: relative;
`;


const DetailHeader = styled.div`
position: absolute;
top: 0.5em;
Expand Down Expand Up @@ -100,7 +99,6 @@ export const CollapsibleEditor = ({
onUpdate={onChangeUpdate}
multiline
controls={{
emphasis: true,
piping: true,
list: true,
bold: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ exports[`IntroductionEditor should render 1`] = `
autoFocus={false}
controls={
Object {
"bold": true,
"emphasis": true,
"heading": true,
"highlight": true,
"link": true,
"piping": true,
}
Expand Down Expand Up @@ -178,7 +177,6 @@ exports[`IntroductionEditor should render 1`] = `
controls={
Object {
"bold": true,
"emphasis": true,
"link": true,
"list": true,
"piping": true,
Expand Down Expand Up @@ -281,7 +279,7 @@ exports[`IntroductionEditor should render 1`] = `
autoFocus={false}
controls={
Object {
"emphasis": true,
"highlight": true,
"piping": true,
}
}
Expand All @@ -303,7 +301,6 @@ exports[`IntroductionEditor should render 1`] = `
controls={
Object {
"bold": true,
"emphasis": true,
"link": true,
"list": true,
"piping": true,
Expand Down Expand Up @@ -348,7 +345,7 @@ exports[`IntroductionEditor should render 1`] = `
autoFocus={false}
controls={
Object {
"emphasis": true,
"highlight": true,
"piping": true,
}
}
Expand All @@ -370,7 +367,6 @@ exports[`IntroductionEditor should render 1`] = `
controls={
Object {
"bold": true,
"emphasis": true,
"link": true,
"list": true,
"piping": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@ const SectionDescription = styled.p`
`;

const titleControls = {
emphasis: true,
highlight: true,
piping: true,
};

const descriptionControls = {
bold: true,
emphasis: true,
piping: true,
list: true,
link: true,
Expand Down Expand Up @@ -165,9 +164,8 @@ const IntroductionEditor = ({ introduction, history }) => {
}
controls={{
heading: true,
bold: true,
link: true,
emphasis: true,
highlight: true,
piping: true,
}}
testSelector="txt-intro-title"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ const Container = styled.div`
p:last-of-type {
margin-bottom: 0;
}
em {
background-color: ${colors.highlightGreen};
padding: 0 0.125em;
font-style: normal;
}
span[data-piped] {
background-color: #e0e0e0;
padding: 0 0.125em;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import CommentFragment from "graphql/fragments/comment.graphql";
import AnswerFragment from "graphql/fragments/answer.graphql";

const titleControls = {
emphasis: true,
highlight: true,
piping: true,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const StyledCollapsible = styled(Collapsible)`
margin-top: 1em;
`;
const titleControls = {
emphasis: true,
highlight: true,
piping: true,
};

Expand Down Expand Up @@ -148,6 +148,7 @@ const AddItemPageEditor = ({ fetchAnswers, page }) => {
})
}
errorValidationMsg={getErrorMessage("title")}
size="large"
controls={titleControls}
allowableTypes={[ANSWER, METADATA, VARIABLES]}
testSelector="add-item-question"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const HorizontalSeparator = styled.hr`
`;

const titleControls = {
emphasis: true,
highlight: true,
piping: true,
};

Expand Down Expand Up @@ -124,6 +124,7 @@ const ConfirmationPageEditor = ({ page, onUpdateOption }) => {
})
}
errorValidationMsg={getErrorMessage("title")}
size="large"
controls={titleControls}
allowableTypes={[ANSWER, METADATA, VARIABLES]}
testSelector="confirmation-question"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const HorizontalSeparator = styled.hr`
`;

const titleControls = {
emphasis: true,
highlight: true,
piping: true,
};

Expand Down Expand Up @@ -127,6 +127,7 @@ const QualifierPageEditor = ({ page, onUpdateOption }) => {
})
}
errorValidationMsg={getErrorMessage("title")}
size="large"
controls={titleControls}
allowableTypes={[ANSWER, METADATA, VARIABLES]}
testSelector="qualifier-question"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from "components/ContentPickerSelectv3/content-types";

const titleControls = {
emphasis: true,
highlight: true,
piping: true,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,18 @@ import {

const contentControls = {
bold: true,
emphasis: true,
list: true,
link: true,
};

const descriptionControls = {
emphasis: true,
bold: true,
piping: true,
link: true,
};

const definitionControls = {
list: true,
emphasis: true,
bold: true,
link: true,
};
Expand Down
Loading

0 comments on commit 633395c

Please sign in to comment.