Skip to content

Commit

Permalink
test: Add strip html test
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Oct 23, 2024
1 parent 12dfdb1 commit f0cf4fd
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe("More information fields", () => {
const output = getDisplayDetailsForResult({
...mockQuestionResult,
key: "data.policyRef",
matchValue: "Rat"
matchValue: "Rat",
});

expect(output).toStrictEqual<Output>({
Expand All @@ -121,7 +121,7 @@ describe("More information fields", () => {
const output = getDisplayDetailsForResult({
...mockQuestionResult,
key: "data.info",
matchValue: "Octopus"
matchValue: "Octopus",
});

expect(output).toStrictEqual<Output>({
Expand All @@ -133,6 +133,7 @@ describe("More information fields", () => {
});
});
});

describe("checklist fields", () => {
it("renders data.categories.title", () => {
const output = getDisplayDetailsForResult(mockChecklistResult);
Expand Down Expand Up @@ -176,7 +177,7 @@ describe("nextSteps fields", () => {
const output = getDisplayDetailsForResult({
...mockNextStepsOptionResult,
key: "data.steps.description",
matchValue: "Vulture"
matchValue: "Vulture",
});

expect(output).toStrictEqual<Output>({
Expand Down Expand Up @@ -222,7 +223,7 @@ describe("fileUploadAndLabel fields", () => {
const output = getDisplayDetailsForResult({
...mockFileUploadAndLabelResult,
key: "data.fileTypes.moreInformation.info",
matchValue: "Kangaroo"
matchValue: "Kangaroo",
});

expect(output).toStrictEqual<Output>({
Expand All @@ -238,7 +239,7 @@ describe("fileUploadAndLabel fields", () => {
const output = getDisplayDetailsForResult({
...mockFileUploadAndLabelResult,
key: "data.fileTypes.moreInformation.policyRef",
matchValue: "Tiger"
matchValue: "Tiger",
});

expect(output).toStrictEqual<Output>({
Expand All @@ -254,7 +255,7 @@ describe("fileUploadAndLabel fields", () => {
const output = getDisplayDetailsForResult({
...mockFileUploadAndLabelResult,
key: "data.fileTypes.moreInformation.howMeasured",
matchValue: "Salamander"
matchValue: "Salamander",
});

expect(output).toStrictEqual<Output>({
Expand All @@ -280,6 +281,7 @@ describe("numberInput fields", () => {
});
});
});

describe("schemaComponents fields", () => {
it("renders data.schemaName", () => {
const output = getDisplayDetailsForResult(mockSchemaResult);
Expand Down Expand Up @@ -345,7 +347,7 @@ describe("schemaComponents fields", () => {
const output = getDisplayDetailsForResult({
...mockSchemaResult,
key: "data.schema.fields.data.options.data.description",
matchValue: "Parrot"
matchValue: "Parrot",
});

expect(output).toStrictEqual<Output>({
Expand Down Expand Up @@ -435,7 +437,7 @@ describe("confirmation fields", () => {
const output = getDisplayDetailsForResult({
...mockConfirmationResult,
key: "data.contactInfo",
matchValue: "Weasel"
matchValue: "Weasel",
});

expect(output).toStrictEqual<Output>({
Expand All @@ -451,7 +453,7 @@ describe("confirmation fields", () => {
const output = getDisplayDetailsForResult({
...mockConfirmationResult,
key: "data.nextSteps.title",
matchValue: "Llama"
matchValue: "Llama",
});

expect(output).toStrictEqual<Output>({
Expand Down Expand Up @@ -543,7 +545,7 @@ describe("drawBoundary fields", () => {
const output = getDisplayDetailsForResult({
...mockDrawBoundaryResult,
key: "data.descriptionForUploading",
matchValue: "Panda"
matchValue: "Panda",
});

expect(output).toStrictEqual<Output>({
Expand Down Expand Up @@ -687,7 +689,7 @@ describe("pay fields", () => {
const output = getDisplayDetailsForResult({
...mockPayResult,
key: "data.yourDetailsDescription",
matchValue: "Macaw"
matchValue: "Macaw",
});

expect(output).toStrictEqual<Output>({
Expand Down Expand Up @@ -754,7 +756,7 @@ describe("result fields", () => {
const output = getDisplayDetailsForResult({
...mockResultResult,
key: "data.overrides.IMMUNE.heading",
matchValue: "Squid"
matchValue: "Squid",
});

expect(output).toStrictEqual<Output>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,38 @@ it("should not have any accessibility violations on initial load", async () => {
const results = await axe(container);
expect(results).toHaveNoViolations();
});

describe("rich text fields", () => {
test("HTML tags are stripped out", async () => {
const {
user,
getByRole,
getAllByRole,
getByText,
queryByText,
getByLabelText,
} = setup(
<VirtuosoWrapper>
<Search />
</VirtuosoWrapper>,
);

const searchInput = getByLabelText("Search this flow and internal portals");
user.type(searchInput, "rich text");

// Search has completed
await waitFor(() => expect(getByRole("list")).toBeInTheDocument());
await waitFor(() => expect(getAllByRole("listitem")).toHaveLength(1));

// Single, correct, search result returned which has rich text as a description
expect(getByText(/1 result:/)).toBeVisible();
expect(getByText(/Pick a country/)).toBeVisible();
expect(getByText(/Description/)).toBeVisible();

// No HTML tags in text
// We must search by characters and not strings (e.g </h1>) as the string is split for the headline
expect(queryByText(/</)).not.toBeInTheDocument();
expect(queryByText(/>/)).not.toBeInTheDocument();
expect(queryByText(/\//)).not.toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export const flow: FlowGraph = {
data: {
fn: "country",
text: "Pick a country",
description:
"<h1>This is rich text</h1><ol><li>With many nested html tags</li><li>Like <b>this</b>one<li><ol>",
},
edges: ["VhSydY2fTe", "tR9tdaWOvF", "tvUxd2IoPo"],
},
Expand Down

0 comments on commit f0cf4fd

Please sign in to comment.