|
| 1 | +import React from "react"; |
| 2 | +import { render } from "@testing-library/react"; |
| 3 | + |
| 4 | +import "@testing-library/jest-dom"; |
| 5 | + |
| 6 | +import { Markdown, TextReducer } from "./../../"; |
| 7 | +import { Default as TextReducerStory } from "./TextReducer.stories"; |
| 8 | + |
| 9 | +describe("TextReducer", () => { |
| 10 | + it("should display encoded HTML entities by default if they are used in the transformed markup", () => { |
| 11 | + const { queryByText } = render(<TextReducer {...TextReducerStory.args} />); |
| 12 | + expect(queryByText("'entities' & "quotes"", { exact: false })).not.toBeNull(); |
| 13 | + expect(queryByText(`'entities' & "quotes"`, { exact: false })).toBeNull(); |
| 14 | + }); |
| 15 | + it("should not display encoded HTML entities if `decodeHtmlEntities` is enabled", () => { |
| 16 | + const { queryByText } = render(<TextReducer {...TextReducerStory.args} decodeHtmlEntities />); |
| 17 | + expect(queryByText("'entities' & "quotes"", { exact: false })).toBeNull(); |
| 18 | + expect(queryByText(`'entities' & "quotes"`, { exact: false })).not.toBeNull(); |
| 19 | + }); |
| 20 | + it("should only decode if correct encoded HTML entities are found (strict mode)", () => { |
| 21 | + const { queryByText } = render( |
| 22 | + <TextReducer decodeHtmlEntities> |
| 23 | + <Markdown>&</Markdown>& foo&bar |
| 24 | + </TextReducer> |
| 25 | + ); |
| 26 | + expect(queryByText("& & foo&bar", { exact: false })).not.toBeNull(); |
| 27 | + expect(queryByText("& & foo&bar", { exact: false })).toBeNull(); |
| 28 | + }); |
| 29 | + it("should allow decoding non-strict encoded HTML entities", () => { |
| 30 | + const { queryByText } = render( |
| 31 | + <TextReducer decodeHtmlEntities decodeHtmlEntitiesOptions={{ strict: false }}> |
| 32 | + <Markdown>&</Markdown>& foo&bar |
| 33 | + </TextReducer> |
| 34 | + ); |
| 35 | + expect(queryByText("& & foo&bar", { exact: false })).toBeNull(); |
| 36 | + expect(queryByText("& & foo&bar", { exact: false })).not.toBeNull(); |
| 37 | + }); |
| 38 | +}); |
0 commit comments