1
0
mirror of https://github.com/element-hq/element-web.git synced 2025-09-13 06:06:34 +03:00

Refactor several unit tests to use SettingsStore directly. (#29744)

* Refactor notifications-test.ts

* Refactor other tests to stop mocking SettingsStore
This commit is contained in:
Will Hunt
2025-04-15 09:01:35 +01:00
committed by GitHub
parent bb23a98bc6
commit 23a42e0d54
7 changed files with 146 additions and 66 deletions

View File

@@ -7,22 +7,19 @@ Please see LICENSE files in the repository root for full details.
*/
import React from "react";
import { mocked } from "jest-mock";
import { render, screen } from "jest-matrix-react";
import parse from "html-react-parser";
import { bodyToHtml, bodyToNode, formatEmojis, topicToHtml } from "../../src/HtmlUtils";
import SettingsStore from "../../src/settings/SettingsStore";
jest.mock("../../src/settings/SettingsStore");
const enableHtmlTopicFeature = () => {
mocked(SettingsStore).getValue.mockImplementation((arg): any => {
return arg === "feature_html_topic";
});
};
import { SettingLevel } from "../../src/settings/SettingLevel";
import SdkConfig from "../../src/SdkConfig";
describe("topicToHtml", () => {
afterEach(() => {
SettingsStore.reset();
});
function getContent() {
return screen.getByRole("contentinfo").children[0].innerHTML;
}
@@ -38,19 +35,19 @@ describe("topicToHtml", () => {
});
it("converts literal HTML topic to HTML", async () => {
enableHtmlTopicFeature();
SettingsStore.setValue("feature_html_topic", null, SettingLevel.DEVICE, true);
render(<div role="contentinfo">{topicToHtml("<b>pizza</b>", undefined, null, false)}</div>);
expect(getContent()).toEqual("&lt;b&gt;pizza&lt;/b&gt;");
});
it("converts true HTML topic to HTML", async () => {
enableHtmlTopicFeature();
SettingsStore.setValue("feature_html_topic", null, SettingLevel.DEVICE, true);
render(<div role="contentinfo">{topicToHtml("**pizza**", "<b>pizza</b>", null, false)}</div>);
expect(getContent()).toEqual("<b>pizza</b>");
});
it("converts true HTML topic with emoji to HTML", async () => {
enableHtmlTopicFeature();
SettingsStore.setValue("feature_html_topic", null, SettingLevel.DEVICE, true);
render(<div role="contentinfo">{topicToHtml("**pizza** 🍕", "<b>pizza</b> 🍕", null, false)}</div>);
expect(getContent()).toEqual('<b>pizza</b> <span class="mx_Emoji" title=":pizza:">🍕</span>');
});
@@ -107,7 +104,12 @@ describe("bodyToHtml", () => {
describe("feature_latex_maths", () => {
beforeEach(() => {
jest.spyOn(SettingsStore, "getValue").mockImplementation((feature) => feature === "feature_latex_maths");
SettingsStore.setValue("feature_latex_maths", null, SettingLevel.DEVICE, true);
});
afterEach(() => {
SettingsStore.reset();
SdkConfig.reset();
});
it("should render inline katex", () => {
@@ -228,4 +230,8 @@ describe("bodyToNode", () => {
expect(asFragment()).toMatchSnapshot();
});
afterEach(() => {
jest.resetAllMocks();
});
});