Replace some enzyme tests by @testing-library/react (#9822)

* Replace MessageComposerButtons-test.tsx enzyme by @testing-library/react

* Replace HtmlUtils-test.tsx enzyme by @testing-library/react
This commit is contained in:
Florian Duros 2022-12-23 11:46:14 +01:00 committed by GitHub
parent 249bd779f2
commit 88c3864682
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 74 additions and 140 deletions

View file

@ -15,9 +15,8 @@ limitations under the License.
*/
import React from "react";
// eslint-disable-next-line deprecate/import
import { mount } from "enzyme";
import { mocked } from "jest-mock";
import { render, screen } from "@testing-library/react";
import { topicToHtml } from "../src/HtmlUtils";
import SettingsStore from "../src/settings/SettingsStore";
@ -31,38 +30,35 @@ const enableHtmlTopicFeature = () => {
};
describe("HtmlUtils", () => {
function getContent() {
return screen.getByRole("contentinfo").children[0].innerHTML;
}
it("converts plain text topic to HTML", () => {
const component = mount(<div>{topicToHtml("pizza", null, null, false)}</div>);
const wrapper = component.render();
expect(wrapper.children().first().html()).toEqual("pizza");
render(<div role="contentinfo">{topicToHtml("pizza", undefined, null, false)}</div>);
expect(getContent()).toEqual("pizza");
});
it("converts plain text topic with emoji to HTML", () => {
const component = mount(<div>{topicToHtml("pizza 🍕", null, null, false)}</div>);
const wrapper = component.render();
expect(wrapper.children().first().html()).toEqual('pizza <span class="mx_Emoji" title=":pizza:">🍕</span>');
render(<div role="contentinfo">{topicToHtml("pizza 🍕", undefined, null, false)}</div>);
expect(getContent()).toEqual('pizza <span class="mx_Emoji" title=":pizza:">🍕</span>');
});
it("converts literal HTML topic to HTML", async () => {
enableHtmlTopicFeature();
const component = mount(<div>{topicToHtml("<b>pizza</b>", null, null, false)}</div>);
const wrapper = component.render();
expect(wrapper.children().first().html()).toEqual("&lt;b&gt;pizza&lt;/b&gt;");
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();
const component = mount(<div>{topicToHtml("**pizza**", "<b>pizza</b>", null, false)}</div>);
const wrapper = component.render();
expect(wrapper.children().first().html()).toEqual("<b>pizza</b>");
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();
const component = mount(<div>{topicToHtml("**pizza** 🍕", "<b>pizza</b> 🍕", null, false)}</div>);
const wrapper = component.render();
expect(wrapper.children().first().html()).toEqual(
'<b>pizza</b> <span class="mx_Emoji" title=":pizza:">🍕</span>',
);
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>');
});
});