From 04457b3b53c1d9a8e5f1dad8751631fe8941dc7b Mon Sep 17 00:00:00 2001
From: doug-s-nava <92806979+doug-s-nava@users.noreply.github.com>
Date: Wed, 13 Nov 2024 13:05:08 -0500
Subject: [PATCH] [Issue #2776] fix broken markup parsing when links are
present (#2831)
* markup splitter will ignore anything contained in quotes within a tag
* disables collapsed content if markup splitter returns no content to hide
---
.../opportunity/OpportunityDescription.tsx | 12 +++++
frontend/src/utils/generalUtils.ts | 13 +++++
.../OpportunityDescription.test.tsx | 54 +++++++++++++++++++
frontend/tests/utils/generalUtils.test.ts | 11 ++++
4 files changed, 90 insertions(+)
diff --git a/frontend/src/components/opportunity/OpportunityDescription.tsx b/frontend/src/components/opportunity/OpportunityDescription.tsx
index ba9b685f8..a36634ecb 100644
--- a/frontend/src/components/opportunity/OpportunityDescription.tsx
+++ b/frontend/src/components/opportunity/OpportunityDescription.tsx
@@ -69,6 +69,18 @@ const SummaryDescriptionDisplay = ({
const purifiedSummary = DOMPurify.sanitize(summaryDescription);
const { preSplit, postSplit } = splitMarkup(purifiedSummary, 600);
+
+ if (!postSplit) {
+ return (
+
({
+ preSplit: content.substring(0, index),
+ postSplit: content.substring(index),
+ }));
+
jest.mock("isomorphic-dompurify", () => ({
sanitize: jest.fn((input: string) => input),
}));
@@ -16,6 +23,15 @@ jest.mock("next-intl", () => ({
useTranslations: () => useTranslationsMock(),
}));
+jest.mock("src/utils/generalUtils", () => ({
+ splitMarkup: (content: string, index: number) =>
+ // eslint-disable-next-line
+ splitMarkupMock(content, index),
+}));
+
+const longDescription =
+ "Its young really risk. College call month identify out east. Defense writer ahead trip smile. Picture data area system manager hour none. Doctor pay visit save test. Again feeling little throughout. Improve drug play remain face word somebody. Baby miss may drive treat letter. Laugh message as car position team. Want build last. Model or base within bag manager brother. How still teacher son fish pay until. Debate doctor visit because success. Message will white risk. Follow sell nearly individual family crime particularly understand. Police street federal six really major owner. Should friend minute team material trade special. Example above government usually deal fill few. Kid middle our sometimes appear. Ready share century nor take let. Water sort choice beat design she sport commercial. Nature if natural feel. Yes door cold realize. Receive trade central good realize number woman them. Actually there common order purpose within. Enough trouble develop station almost read. Who attack include company.";
+
const mockSummaryData: Summary = {
summary_description: "
Summary Description
",
applicant_types: [
@@ -46,6 +62,44 @@ describe("OpportunityDescription", () => {
);
});
+ it("splits opportunity description after 600 characters if description is longer than 750 characters", () => {
+ render(
+
,
+ );
+
+ expect(
+ screen.getByText(
+ "Its young really risk. College call month identify out east. Defense writer ahead trip smile. Picture data area system manager hour none. Doctor pay visit save test. Again feeling little throughout. Improve drug play remain face word somebody. Baby miss may drive treat letter. Laugh message as car position team. Want build last. Model or base within bag manager brother. How still teacher son fish pay until. Debate doctor visit because success. Message will white risk. Follow sell nearly individual family crime particularly understand. Police street federal six really major owner. Should friend...",
+ ),
+ ).toBeInTheDocument();
+ expect(
+ screen.queryAllByText(
+ " minute team material trade special. Example above government usually deal fill few. Kid middle our sometimes appear. Ready share century nor take let. Water sort choice beat design she sport commercial. Nature if natural feel. Yes door cold realize. Receive trade central good realize number woman them. Actually there common order purpose within. Enough trouble develop station almost read. Who attack include company.",
+ ),
+ ).toHaveLength(0);
+ });
+
+ it("shows all description if parsed mark up comes out with no content to hide", () => {
+ splitMarkupMock.mockImplementation((content: string) => ({
+ preSplit: content,
+ postSplit: "",
+ }));
+
+ render(
+
,
+ );
+
+ expect(
+ screen.getByText(
+ "Its young really risk. College call month identify out east. Defense writer ahead trip smile. Picture data area system manager hour none. Doctor pay visit save test. Again feeling little throughout. Improve drug play remain face word somebody. Baby miss may drive treat letter. Laugh message as car position team. Want build last. Model or base within bag manager brother. How still teacher son fish pay until. Debate doctor visit because success. Message will white risk. Follow sell nearly individual family crime particularly understand. Police street federal six really major owner. Should friend minute team material trade special. Example above government usually deal fill few. Kid middle our sometimes appear. Ready share century nor take let. Water sort choice beat design she sport commercial. Nature if natural feel. Yes door cold realize. Receive trade central good realize number woman them. Actually there common order purpose within. Enough trouble develop station almost read. Who attack include company.",
+ ),
+ ).toBeInTheDocument();
+ });
+
it("renders the eligible applicants with mapped values", () => {
render(
);
diff --git a/frontend/tests/utils/generalUtils.test.ts b/frontend/tests/utils/generalUtils.test.ts
index 555b611aa..787fdc670 100644
--- a/frontend/tests/utils/generalUtils.test.ts
+++ b/frontend/tests/utils/generalUtils.test.ts
@@ -69,6 +69,17 @@ describe("splitMarkup", () => {
"
that I've been turning over in my mind ever since.
",
);
});
+ it("ignores anything that is within quotes within a tag and allows it to pass through", () => {
+ const exampleMarkup =
+ "
In
my younger and more
vulnerable years myme some
advice
that I've been turning over in my mind ever since.
";
+ const { preSplit, postSplit } = splitMarkup(exampleMarkup, 75);
+ expect(preSplit).toEqual(
+ "
In
my younger and more
vulnerable years myme some
advice
",
+ );
+ expect(postSplit).toEqual(
+ "
that I've been turning over in my mind ever since.
",
+ );
+ });
});
describe("findFirstWhitespace", () => {