You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-07-28 15:22:05 +03:00
Split up bodyToHtml (#12840)
* Split up bodyToHtml This (very incrementally) splits up the bodyToHtml function to avoid the multiple return types and hopefully make it a touch easier to comprehend. I'd also like to see what the test coverage says about this, so this is is somewhat experimental. This shouldn't change any behaviour but the comments in this function indiciate just how subtle it is. * Remove I prefix * Missed emoji formatting part
This commit is contained in:
@ -19,7 +19,7 @@ import { mocked } from "jest-mock";
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import { IContent } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { bodyToHtml, formatEmojis, topicToHtml } from "../src/HtmlUtils";
|
||||
import { bodyToNode, formatEmojis, topicToHtml } from "../src/HtmlUtils";
|
||||
import SettingsStore from "../src/settings/SettingsStore";
|
||||
|
||||
jest.mock("../src/settings/SettingsStore");
|
||||
@ -66,7 +66,7 @@ describe("topicToHtml", () => {
|
||||
|
||||
describe("bodyToHtml", () => {
|
||||
function getHtml(content: IContent, highlights?: string[]): string {
|
||||
return (bodyToHtml(content, highlights, {}) as ReactElement).props.dangerouslySetInnerHTML.__html;
|
||||
return (bodyToNode(content, highlights, {}) as ReactElement).props.dangerouslySetInnerHTML.__html;
|
||||
}
|
||||
|
||||
it("should apply highlights to HTML messages", () => {
|
||||
@ -108,14 +108,14 @@ describe("bodyToHtml", () => {
|
||||
});
|
||||
|
||||
it("generates big emoji for emoji made of multiple characters", () => {
|
||||
const { asFragment } = render(bodyToHtml({ body: "👨👩👧👦 ↔️ 🇮🇸", msgtype: "m.text" }, [], {}) as ReactElement);
|
||||
const { asFragment } = render(bodyToNode({ body: "👨👩👧👦 ↔️ 🇮🇸", msgtype: "m.text" }, [], {}) as ReactElement);
|
||||
|
||||
expect(asFragment()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("should generate big emoji for an emoji-only reply to a message", () => {
|
||||
const { asFragment } = render(
|
||||
bodyToHtml(
|
||||
bodyToNode(
|
||||
{
|
||||
"body": "> <@sender1:server> Test\n\n🥰",
|
||||
"format": "org.matrix.custom.html",
|
||||
@ -139,7 +139,7 @@ describe("bodyToHtml", () => {
|
||||
});
|
||||
|
||||
it("does not mistake characters in text presentation mode for emoji", () => {
|
||||
const { asFragment } = render(bodyToHtml({ body: "↔ ❗︎", msgtype: "m.text" }, [], {}) as ReactElement);
|
||||
const { asFragment } = render(bodyToNode({ body: "↔ ❗︎", msgtype: "m.text" }, [], {}) as ReactElement);
|
||||
|
||||
expect(asFragment()).toMatchSnapshot();
|
||||
});
|
||||
|
Reference in New Issue
Block a user