Refactor languageHandler to avoid import cycles (#33948)

* Refactor languageHandler to avoid import cycles

Also move its tests to vitest

* Small refactor

* Iterate

* Iterate
This commit is contained in:
Michael Telatynski
2026-06-24 09:49:49 +00:00
committed by GitHub
parent 29b9c04d20
commit f9b97be1d7
38 changed files with 780 additions and 555 deletions
@@ -21,7 +21,7 @@ import {
import EventListSummary from "../../../../../src/components/views/elements/EventListSummary";
import { Layout } from "../../../../../src/settings/enums/Layout";
import MatrixClientContext from "../../../../../src/contexts/MatrixClientContext";
import * as languageHandler from "../../../../../src/languageHandler";
import * as languageSettings from "../../../../../src/i18n/settings";
describe("EventListSummary", function () {
const roomId = "!room:server.org";
@@ -130,7 +130,7 @@ describe("EventListSummary", function () {
beforeEach(function () {
jest.clearAllMocks();
jest.spyOn(languageHandler, "getUserLanguage").mockReturnValue("en-GB");
jest.spyOn(languageSettings, "getUserLanguage").mockReturnValue("en-GB");
});
afterAll(() => {
@@ -36,7 +36,7 @@ import {
import MatrixClientContext from "../../../../../src/contexts/MatrixClientContext";
import { type RoomPermalinkCreator } from "../../../../../src/utils/permalinks/Permalinks";
import { type MediaEventHelper } from "../../../../../src/utils/MediaEventHelper";
import * as languageHandler from "../../../../../src/languageHandler";
import * as languageSettings from "../../../../../src/i18n/settings";
const CHECKED = "mx_PollOption_checked";
const userId = "@me:example.com";
@@ -55,7 +55,7 @@ describe("MPollBody", () => {
mockClient.getRoom.mockReturnValue(null);
mockClient.relations.mockResolvedValue({ events: [] });
jest.spyOn(languageHandler, "getUserLanguage").mockReturnValue("en-GB");
jest.spyOn(languageSettings, "getUserLanguage").mockReturnValue("en-GB");
});
it("finds no votes if there are none", () => {
@@ -11,6 +11,7 @@ import { type MatrixClient, type MatrixEvent, PushRuleKind, type Room } from "ma
import { mocked, type MockedObject } from "jest-mock-vitest-adapter";
import { act, render, waitFor } from "jest-matrix-react";
import { PushProcessor } from "matrix-js-sdk/src/pushprocessor";
import { setMissingEntryGenerator } from "@element-hq/web-shared-components";
import {
getMockClientWithEventEmitter,
@@ -19,7 +20,6 @@ import {
mkStubRoom,
mockClientPushProcessor,
} from "../../../../test-utils";
import * as languageHandler from "../../../../../src/languageHandler";
import DMRoomMap from "../../../../../src/utils/DMRoomMap";
import { TextualBodyFactory as TextualBody } from "../../../../../src/components/views/messages/TextualBodyFactory";
import MatrixClientContext from "../../../../../src/contexts/MatrixClientContext";
@@ -470,7 +470,7 @@ describe("<TextualBody />", () => {
let matrixClient: MatrixClient;
beforeEach(() => {
languageHandler.setMissingEntryGenerator((key) => key.split("|", 2)[1]);
setMissingEntryGenerator((key) => key.split("|", 2)[1]);
matrixClient = getMockClientWithEventEmitter({
getRoom: jest.fn(),
getUserId: jest.fn(),
@@ -17,7 +17,7 @@ import {
ReadReceiptPerson,
readReceiptTooltip,
} from "../../../../../src/components/views/rooms/ReadReceiptGroup";
import * as languageHandler from "../../../../../src/languageHandler";
import * as languageSettings from "../../../../../src/i18n/settings";
import { stubClient } from "../../../../test-utils";
import dispatcher from "../../../../../src/dispatcher/dispatcher";
import { Action } from "../../../../../src/dispatcher/actions";
@@ -46,7 +46,7 @@ describe("ReadReceiptGroup", () => {
expect(readReceiptTooltip([], 1)).toBe("");
});
it("returns a pretty list without hasMore", () => {
jest.spyOn(languageHandler, "getUserLanguage").mockReturnValue("en-GB");
jest.spyOn(languageSettings, "getUserLanguage").mockReturnValue("en-GB");
expect(readReceiptTooltip(["Alice", "Bob", "Charlie", "Dan", "Eve"], 5)).toEqual(
"Alice, Bob, Charlie, Dan and Eve",
);
@@ -32,7 +32,7 @@ import {
getMockClientWithEventEmitter,
mockClientMethodsUser,
} from "../../../../test-utils";
import * as languageHandler from "../../../../../src/languageHandler";
import * as languageSettings from "../../../../../src/i18n/settings";
describe("RoomKnocksBar", () => {
const userId = "@alice:example.org";
@@ -132,7 +132,7 @@ describe("RoomKnocksBar", () => {
jest.spyOn(state, "hasSufficientPowerLevelFor").mockReturnValue(true);
jest.spyOn(Modal, "createDialog");
jest.spyOn(dis, "dispatch");
jest.spyOn(languageHandler, "getUserLanguage").mockReturnValue("en-GB");
jest.spyOn(languageSettings, "getUserLanguage").mockReturnValue("en-GB");
});
it("does not render if user can neither approve nor deny", () => {
@@ -18,7 +18,7 @@ import {
import { FormattingButtons } from "../../../../../../../src/components/views/rooms/wysiwyg_composer/components/FormattingButtons";
import * as LinkModal from "../../../../../../../src/components/views/rooms/wysiwyg_composer/components/LinkModal";
import { setLanguage } from "../../../../../../../src/languageHandler";
import { setLanguage } from "../../../../../../../src/i18n/settings";
const mockWysiwyg = {
bold: jest.fn(),