@@ -132,7 +132,7 @@ exports[`messageForSyncError should match snapshot for M_RESOURCE_LIMIT_EXCEEDED
`;
-exports[`messageForSyncError should match snapshot for other errors 1`] = `
+exports[`messageForSyncError > should match snapshot for other errors 1`] = `
Unable to connect to Homeserver. Retrying…
diff --git a/apps/web/test/unit-tests/utils/leave-behaviour-test.ts b/apps/web/src/utils/leave-behaviour.test.ts
similarity index 74%
rename from apps/web/test/unit-tests/utils/leave-behaviour-test.ts
rename to apps/web/src/utils/leave-behaviour.test.ts
index 334e518e5f..929d6ebfa4 100644
--- a/apps/web/test/unit-tests/utils/leave-behaviour-test.ts
+++ b/apps/web/src/utils/leave-behaviour.test.ts
@@ -6,25 +6,29 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
Please see LICENSE files in the repository root for full details.
*/
-import { mocked, type Mocked } from "jest-mock-vitest-adapter";
+// @vitest-environment happy-dom
+
+import { vi, describe, it, expect, beforeEach, afterEach, type Mocked } from "vitest";
import { type MatrixClient, type Room } from "matrix-js-sdk/src/matrix";
import { sleep } from "matrix-js-sdk/src/utils";
+import { mkRoom, resetAsyncStoreWithClient, setupAsyncStoreWithClient, stubClient } from "test-utils/test-utils";
-import { MatrixClientPeg } from "../../../src/MatrixClientPeg";
-import { mkRoom, resetAsyncStoreWithClient, setupAsyncStoreWithClient, stubClient } from "../../test-utils";
-import defaultDispatcher from "../../../src/dispatcher/dispatcher";
-import { type ViewRoomPayload } from "../../../src/dispatcher/payloads/ViewRoomPayload";
-import { Action } from "../../../src/dispatcher/actions";
-import { leaveRoomBehaviour } from "../../../src/utils/leave-behaviour";
-import { SDKContextClass } from "../../../src/contexts/SDKContextClass";
-import DMRoomMap from "../../../src/utils/DMRoomMap";
-import SpaceStore from "../../../src/stores/spaces/SpaceStore";
-import { MetaSpace } from "../../../src/stores/spaces";
-import { type ActionPayload } from "../../../src/dispatcher/payloads";
-import SettingsStore from "../../../src/settings/SettingsStore";
-import { CallStore } from "../../../src/stores/CallStore";
-import { type Call } from "../../../src/models/Call";
-import LegacyCallHandler from "../../../src/LegacyCallHandler";
+import { MatrixClientPeg } from "../MatrixClientPeg";
+import defaultDispatcher from "../dispatcher/dispatcher";
+import { type ViewRoomPayload } from "../dispatcher/payloads/ViewRoomPayload";
+import { Action } from "../dispatcher/actions";
+import { leaveRoomBehaviour } from "./leave-behaviour";
+import { SDKContextClass } from "../contexts/SDKContextClass";
+import DMRoomMap from "../utils/DMRoomMap";
+import SpaceStore from "../stores/spaces/SpaceStore";
+import { MetaSpace } from "../stores/spaces";
+import { type ActionPayload } from "../dispatcher/payloads";
+import SettingsStore from "../settings/SettingsStore";
+import { CallStore } from "../stores/CallStore";
+import { type Call } from "../models/Call";
+import LegacyCallHandler from "../LegacyCallHandler";
+
+vi.mock("../Modal.tsx");
describe("leaveRoomBehaviour", () => {
SDKContextClass.instance.constructEagerStores(); // Initialize RoomViewStore
@@ -35,7 +39,7 @@ describe("leaveRoomBehaviour", () => {
beforeEach(async () => {
stubClient();
- client = mocked(MatrixClientPeg.safeGet());
+ client = vi.mocked(MatrixClientPeg.safeGet());
DMRoomMap.makeShared(client);
room = mkRoom(client, "!1:example.org");
@@ -58,7 +62,7 @@ describe("leaveRoomBehaviour", () => {
afterEach(async () => {
SpaceStore.instance.setActiveSpace(MetaSpace.Home);
await resetAsyncStoreWithClient(SpaceStore.instance);
- jest.restoreAllMocks();
+ vi.restoreAllMocks();
});
const viewRoom = (room: Room) =>
@@ -72,7 +76,7 @@ describe("leaveRoomBehaviour", () => {
);
const expectDispatch = async (payload: T) => {
- const dispatcherSpy = jest.fn();
+ const dispatcherSpy = vi.fn();
const dispatcherRef = defaultDispatcher.register(dispatcherSpy);
await sleep(0);
expect(dispatcherSpy).toHaveBeenCalledWith(payload);
@@ -80,7 +84,7 @@ describe("leaveRoomBehaviour", () => {
};
it("hangs up legacy calls when leaving a room", async () => {
- const hangupSpy = jest.spyOn(LegacyCallHandler.instance, "hangupOrReject").mockImplementation(() => {});
+ const hangupSpy = vi.spyOn(LegacyCallHandler.instance, "hangupOrReject").mockImplementation(() => {});
viewRoom(room);
await leaveRoomBehaviour(client, room.roomId);
@@ -90,10 +94,10 @@ describe("leaveRoomBehaviour", () => {
it("disconnects widget-based calls when leaving a room", async () => {
const mockCall = {
- disconnect: jest.fn().mockResolvedValue(undefined),
+ disconnect: vi.fn().mockResolvedValue(undefined),
} as unknown as Call;
- jest.spyOn(CallStore.instance, "getActiveCall").mockReturnValue(mockCall);
+ vi.spyOn(CallStore.instance, "getActiveCall").mockReturnValue(mockCall);
viewRoom(room);
await leaveRoomBehaviour(client, room.roomId);
@@ -109,7 +113,7 @@ describe("leaveRoomBehaviour", () => {
});
it("returns to the parent space after leaving a room inside of a space that was being viewed", async () => {
- jest.spyOn(SpaceStore.instance, "getCanonicalParent").mockImplementation((roomId) =>
+ vi.spyOn(SpaceStore.instance, "getCanonicalParent").mockImplementation((roomId) =>
roomId === room.roomId ? space : null,
);
viewRoom(room);
@@ -133,7 +137,7 @@ describe("leaveRoomBehaviour", () => {
it("returns to the parent space after leaving a subspace that was being viewed", async () => {
room.isSpaceRoom.mockReturnValue(true);
- jest.spyOn(SpaceStore.instance, "getCanonicalParent").mockImplementation((roomId) =>
+ vi.spyOn(SpaceStore.instance, "getCanonicalParent").mockImplementation((roomId) =>
roomId === room.roomId ? space : null,
);
viewRoom(room);
@@ -149,7 +153,7 @@ describe("leaveRoomBehaviour", () => {
describe("If the feature_dynamic_room_predecessors is not enabled", () => {
beforeEach(() => {
- jest.spyOn(SettingsStore, "getValue").mockReturnValue(false);
+ vi.spyOn(SettingsStore, "getValue").mockReturnValue(false);
});
it("Passes through the dynamic predecessor setting", async () => {
@@ -161,7 +165,7 @@ describe("leaveRoomBehaviour", () => {
describe("If the feature_dynamic_room_predecessors is enabled", () => {
beforeEach(() => {
// Turn on feature_dynamic_room_predecessors setting
- jest.spyOn(SettingsStore, "getValue").mockImplementation(
+ vi.spyOn(SettingsStore, "getValue").mockImplementation(
(settingName) => settingName === "feature_dynamic_room_predecessors",
);
});
diff --git a/apps/web/test/viewmodels/room/WidgetPip-test.ts b/apps/web/src/viewmodels/room/WidgetPipViewModel.test.ts
similarity index 71%
rename from apps/web/test/viewmodels/room/WidgetPip-test.ts
rename to apps/web/src/viewmodels/room/WidgetPipViewModel.test.ts
index 714a61ad39..646ee476b5 100644
--- a/apps/web/test/viewmodels/room/WidgetPip-test.ts
+++ b/apps/web/src/viewmodels/room/WidgetPipViewModel.test.ts
@@ -5,18 +5,20 @@
* Please see LICENSE files in the repository root for full details.
*/
-import { type MatrixClient, type Room, RoomEvent } from "matrix-js-sdk/src/matrix";
-import { type MockedObject } from "jest-mock-vitest-adapter";
-import { createRef } from "react";
+// @vitest-environment happy-dom
-import { mkRoom, stubClient } from "../../test-utils";
-import { WidgetPipViewModel } from "../../../src/viewmodels/room/WidgetPipViewModel";
-import WidgetStore, { type IApp } from "../../../src/stores/WidgetStore";
-import defaultDispatcher from "../../../src/dispatcher/dispatcher";
-import { Action } from "../../../src/dispatcher/actions";
-import { WidgetLayoutStore } from "../../../src/stores/widgets/WidgetLayoutStore";
-import { CallStore, CallStoreEvent } from "../../../src/stores/CallStore";
-import { type Call } from "../../../src/models/Call";
+import { type MatrixClient, type Room, RoomEvent } from "matrix-js-sdk/src/matrix";
+import { vi, describe, it, expect, beforeEach, afterEach, type MockedObject } from "vitest";
+import { createRef } from "react";
+import { mkRoom, stubClient } from "test-utils";
+
+import { WidgetPipViewModel } from "./WidgetPipViewModel";
+import WidgetStore, { type IApp } from "../../stores/WidgetStore";
+import defaultDispatcher from "../../dispatcher/dispatcher";
+import { Action } from "../../dispatcher/actions";
+import { WidgetLayoutStore } from "../../stores/widgets/WidgetLayoutStore";
+import { CallStore, CallStoreEvent } from "../../stores/CallStore";
+import { type Call } from "../../models/Call";
const userId = "@example:example.org";
const widgetId = "test-widget-id";
@@ -25,8 +27,8 @@ type BackClickEvent = Parameters[0];
const createBackClickEvent = (): BackClickEvent =>
({
- preventDefault: jest.fn(),
- stopPropagation: jest.fn(),
+ preventDefault: vi.fn(),
+ stopPropagation: vi.fn(),
}) as unknown as BackClickEvent;
describe("WidgetPipViewModel", () => {
@@ -46,7 +48,7 @@ describe("WidgetPipViewModel", () => {
name: "Test Widget",
data: {},
} as unknown as IApp;
- jest.spyOn(WidgetStore.instance, "getApps").mockReturnValue([widget]);
+ vi.spyOn(WidgetStore.instance, "getApps").mockReturnValue([widget]);
vm = new WidgetPipViewModel({
room,
@@ -58,7 +60,7 @@ describe("WidgetPipViewModel", () => {
afterEach(() => {
vm.dispose();
- jest.restoreAllMocks();
+ vi.restoreAllMocks();
});
it("updates room name", () => {
@@ -68,7 +70,7 @@ describe("WidgetPipViewModel", () => {
});
it("updates onBackClick if call changes", () => {
- const dispatchSpy = jest.spyOn(defaultDispatcher, "dispatch").mockImplementation(() => {});
+ const dispatchSpy = vi.spyOn(defaultDispatcher, "dispatch").mockImplementation(() => {});
vm.onBackClick(createBackClickEvent());
expect(dispatchSpy).toHaveBeenCalledWith({
@@ -91,8 +93,8 @@ describe("WidgetPipViewModel", () => {
});
it("updates onBackClick if viewingRoom changes", () => {
- const dispatchSpy = jest.spyOn(defaultDispatcher, "dispatch").mockImplementation(() => {});
- const moveSpy = jest.spyOn(WidgetLayoutStore.instance, "moveToContainer").mockImplementation(() => {});
+ const dispatchSpy = vi.spyOn(defaultDispatcher, "dispatch").mockImplementation(() => {});
+ const moveSpy = vi.spyOn(WidgetLayoutStore.instance, "moveToContainer").mockImplementation(() => {});
vm.setViewingRoom(true);
vm.onBackClick(createBackClickEvent());
diff --git a/apps/web/test/test-utils/jest-matrix-react.tsx b/apps/web/test/test-utils/jest-matrix-react.tsx
index 76150df478..f9009b73f6 100644
--- a/apps/web/test/test-utils/jest-matrix-react.tsx
+++ b/apps/web/test/test-utils/jest-matrix-react.tsx
@@ -10,7 +10,9 @@ import React, { type ReactElement } from "react";
// eslint-disable-next-line no-restricted-imports
import { render, type RenderOptions } from "@testing-library/react";
import { TooltipProvider } from "@vector-im/compound-web";
-import { I18nContext } from "@element-hq/web-shared-components";
+import { I18nApi, I18nContext } from "@element-hq/web-shared-components";
+
+const i18nApi = new I18nApi();
/**
* Wraps the provided components in:
@@ -26,7 +28,7 @@ const wrapWithStandardContexts = (Wrapper: RenderOptions["wrapper"]) => {
if (Wrapper) {
return (
-
+
{children}
@@ -34,7 +36,7 @@ const wrapWithStandardContexts = (Wrapper: RenderOptions["wrapper"]) => {
} else {
return (
- {children}
+ {children}
);
}