Migrate batch of tests to vitest (#34108)
* Migrate utils/dm tests to vitest * Migrate utils/room tests to vitest * Migrate utils/location tests to vitest * Fix types * Satisfy tsc & knip
This commit is contained in:
+17
-15
@@ -6,23 +6,25 @@ 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 } from "jest-mock";
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { vi, describe, it, expect, beforeEach } from "vitest";
|
||||
import { EventType, KNOWN_SAFE_ROOM_VERSION, type MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { createTestClient } from "test-utils";
|
||||
|
||||
import { canEncryptToAllUsers } from "../../../../src/createRoom";
|
||||
import { type LocalRoom, LOCAL_ROOM_ID_PREFIX } from "../../../../src/models/LocalRoom";
|
||||
import { DirectoryMember, type Member, ThreepidMember } from "../../../../src/utils/direct-messages";
|
||||
import { createDmLocalRoom } from "../../../../src/utils/dm/createDmLocalRoom";
|
||||
import { privateShouldBeEncrypted } from "../../../../src/utils/rooms";
|
||||
import { createTestClient } from "../../../test-utils";
|
||||
import { canEncryptToAllUsers } from "../../createRoom";
|
||||
import { type LocalRoom, LOCAL_ROOM_ID_PREFIX } from "../../models/LocalRoom";
|
||||
import { DirectoryMember, type Member, ThreepidMember } from "../direct-messages";
|
||||
import { createDmLocalRoom } from "./createDmLocalRoom";
|
||||
import { privateShouldBeEncrypted } from "../rooms";
|
||||
|
||||
jest.mock("../../../../src/utils/rooms", () => ({
|
||||
privateShouldBeEncrypted: jest.fn(),
|
||||
vi.mock("../rooms", () => ({
|
||||
privateShouldBeEncrypted: vi.fn(),
|
||||
}));
|
||||
|
||||
jest.mock("../../../../src/createRoom", () => ({
|
||||
canEncryptToAllUsers: jest.fn(),
|
||||
vi.mock("../../createRoom", () => ({
|
||||
canEncryptToAllUsers: vi.fn(),
|
||||
}));
|
||||
|
||||
function assertLocalRoom(room: LocalRoom, targets: Member[], encrypted: boolean) {
|
||||
@@ -60,7 +62,7 @@ describe("createDmLocalRoom", () => {
|
||||
|
||||
describe("when rooms should be encrypted", () => {
|
||||
beforeEach(() => {
|
||||
mocked(privateShouldBeEncrypted).mockReturnValue(true);
|
||||
vi.mocked(privateShouldBeEncrypted).mockReturnValue(true);
|
||||
});
|
||||
|
||||
it("should create an encrytped room for 3PID targets", async () => {
|
||||
@@ -71,7 +73,7 @@ describe("createDmLocalRoom", () => {
|
||||
|
||||
describe("for MXID targets with encryption available", () => {
|
||||
beforeEach(() => {
|
||||
mocked(canEncryptToAllUsers).mockResolvedValue(true);
|
||||
vi.mocked(canEncryptToAllUsers).mockResolvedValue(true);
|
||||
});
|
||||
|
||||
it("should create an encrypted room", async () => {
|
||||
@@ -83,7 +85,7 @@ describe("createDmLocalRoom", () => {
|
||||
|
||||
describe("for MXID targets with encryption unavailable", () => {
|
||||
beforeEach(() => {
|
||||
mocked(canEncryptToAllUsers).mockResolvedValue(false);
|
||||
vi.mocked(canEncryptToAllUsers).mockResolvedValue(false);
|
||||
});
|
||||
|
||||
it("should create an unencrypted room", async () => {
|
||||
@@ -96,7 +98,7 @@ describe("createDmLocalRoom", () => {
|
||||
|
||||
describe("if rooms should not be encrypted", () => {
|
||||
beforeEach(() => {
|
||||
mocked(privateShouldBeEncrypted).mockReturnValue(false);
|
||||
vi.mocked(privateShouldBeEncrypted).mockReturnValue(false);
|
||||
});
|
||||
|
||||
it("should create an unencrypted room", async () => {
|
||||
+3
-1
@@ -6,7 +6,9 @@ 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 { filterValidMDirect } from "../../../../src/utils/dm/filterValidMDirect";
|
||||
import { describe, it, expect } from "vitest";
|
||||
|
||||
import { filterValidMDirect } from "./filterValidMDirect";
|
||||
|
||||
const roomId1 = "!room1:example.com";
|
||||
const roomId2 = "!room2:example.com";
|
||||
+20
-18
@@ -6,18 +6,20 @@ 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 } from "jest-mock";
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { vi, describe, it, expect, beforeEach } from "vitest";
|
||||
import { type MatrixClient, Room } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { createTestClient, makeMembershipEvent, mkThirdPartyInviteEvent } from "test-utils";
|
||||
|
||||
import DMRoomMap from "../../../../src/utils/DMRoomMap";
|
||||
import { createTestClient, makeMembershipEvent, mkThirdPartyInviteEvent } from "../../../test-utils";
|
||||
import { LocalRoom } from "../../../../src/models/LocalRoom";
|
||||
import { findDMForUser } from "../../../../src/utils/dm/findDMForUser";
|
||||
import { getFunctionalMembers } from "../../../../src/utils/room/getFunctionalMembers";
|
||||
import DMRoomMap from "../DMRoomMap";
|
||||
import { LocalRoom } from "../../models/LocalRoom";
|
||||
import { findDMForUser } from "./findDMForUser";
|
||||
import { getFunctionalMembers } from "../room/getFunctionalMembers";
|
||||
|
||||
jest.mock("../../../../src/utils/room/getFunctionalMembers", () => ({
|
||||
getFunctionalMembers: jest.fn(),
|
||||
vi.mock("../room/getFunctionalMembers", () => ({
|
||||
getFunctionalMembers: vi.fn(),
|
||||
}));
|
||||
|
||||
describe("findDMForUser", () => {
|
||||
@@ -41,7 +43,7 @@ describe("findDMForUser", () => {
|
||||
mockClient = createTestClient();
|
||||
|
||||
// always return the bot user as functional member
|
||||
mocked(getFunctionalMembers).mockReturnValue([botId]);
|
||||
vi.mocked(getFunctionalMembers).mockReturnValue([botId]);
|
||||
|
||||
room1 = new Room("!room1:example.com", mockClient, userId1);
|
||||
room1.getMyMembership = () => KnownMembership.Join;
|
||||
@@ -92,7 +94,7 @@ describe("findDMForUser", () => {
|
||||
mkThirdPartyInviteEvent(thirdPartyId, "third-party", room7.roomId),
|
||||
]);
|
||||
|
||||
mocked(mockClient.getRoom).mockImplementation((roomId: string) => {
|
||||
vi.mocked(mockClient.getRoom).mockImplementation((roomId?: string) => {
|
||||
return (
|
||||
{
|
||||
[room1.roomId]: room1,
|
||||
@@ -102,14 +104,14 @@ describe("findDMForUser", () => {
|
||||
[room5.roomId]: room5,
|
||||
[room6.roomId]: room6,
|
||||
[room7.roomId]: room7,
|
||||
}[roomId] || null
|
||||
}[roomId!] || null
|
||||
);
|
||||
});
|
||||
|
||||
dmRoomMap = {
|
||||
getDMRoomForIdentifiers: jest.fn(),
|
||||
getDMRoomsForUserId: jest.fn(),
|
||||
getRoomIds: jest.fn().mockReturnValue(
|
||||
getDMRoomForIdentifiers: vi.fn(),
|
||||
getDMRoomsForUserId: vi.fn(),
|
||||
getRoomIds: vi.fn().mockReturnValue(
|
||||
new Set([
|
||||
room1.roomId,
|
||||
room2.roomId,
|
||||
@@ -122,8 +124,8 @@ describe("findDMForUser", () => {
|
||||
]),
|
||||
),
|
||||
} as unknown as DMRoomMap;
|
||||
jest.spyOn(DMRoomMap, "shared").mockReturnValue(dmRoomMap);
|
||||
mocked(dmRoomMap.getDMRoomsForUserId).mockImplementation((userId: string) => {
|
||||
vi.spyOn(DMRoomMap, "shared").mockReturnValue(dmRoomMap);
|
||||
vi.mocked(dmRoomMap.getDMRoomsForUserId).mockImplementation((userId: string) => {
|
||||
if (userId === userId1) {
|
||||
return [room1.roomId, room2.roomId, room3.roomId, room4.roomId, room5.roomId, unknownRoomId];
|
||||
}
|
||||
@@ -138,8 +140,8 @@ describe("findDMForUser", () => {
|
||||
|
||||
describe("for an empty DM room list", () => {
|
||||
beforeEach(() => {
|
||||
mocked(dmRoomMap.getDMRoomsForUserId).mockReturnValue([]);
|
||||
mocked(dmRoomMap.getRoomIds).mockReturnValue(new Set());
|
||||
vi.mocked(dmRoomMap.getDMRoomsForUserId).mockReturnValue([]);
|
||||
vi.mocked(dmRoomMap.getRoomIds).mockReturnValue(new Set());
|
||||
});
|
||||
|
||||
it("should return undefined", () => {
|
||||
+19
-17
@@ -6,18 +6,20 @@ 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 } from "jest-mock";
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { vi, describe, it, expect, beforeEach } from "vitest";
|
||||
import { type MatrixClient, Room } from "matrix-js-sdk/src/matrix";
|
||||
import { createTestClient } from "test-utils";
|
||||
|
||||
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
||||
import { DirectoryMember, ThreepidMember } from "../../../../src/utils/direct-messages";
|
||||
import { findDMForUser } from "../../../../src/utils/dm/findDMForUser";
|
||||
import { findDMRoom } from "../../../../src/utils/dm/findDMRoom";
|
||||
import DMRoomMap from "../../../../src/utils/DMRoomMap";
|
||||
import { createTestClient } from "../../../test-utils";
|
||||
import { MatrixClientPeg } from "../../MatrixClientPeg";
|
||||
import { DirectoryMember, ThreepidMember } from "../direct-messages";
|
||||
import { findDMForUser } from "./findDMForUser";
|
||||
import { findDMRoom } from "./findDMRoom";
|
||||
import DMRoomMap from "../DMRoomMap";
|
||||
|
||||
jest.mock("../../../../src/utils/dm/findDMForUser", () => ({
|
||||
findDMForUser: jest.fn(),
|
||||
vi.mock("../dm/findDMForUser", () => ({
|
||||
findDMForUser: vi.fn(),
|
||||
}));
|
||||
|
||||
describe("findDMRoom", () => {
|
||||
@@ -30,33 +32,33 @@ describe("findDMRoom", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
mockClient = createTestClient();
|
||||
jest.spyOn(MatrixClientPeg, "get").mockReturnValue(mockClient);
|
||||
vi.spyOn(MatrixClientPeg, "get").mockReturnValue(mockClient);
|
||||
room1 = new Room("!room1:example.com", mockClient, userId1);
|
||||
|
||||
dmRoomMap = {
|
||||
getDMRoomForIdentifiers: jest.fn(),
|
||||
getDMRoomsForUserId: jest.fn(),
|
||||
getDMRoomForIdentifiers: vi.fn(),
|
||||
getDMRoomsForUserId: vi.fn(),
|
||||
} as unknown as DMRoomMap;
|
||||
jest.spyOn(DMRoomMap, "shared").mockReturnValue(dmRoomMap);
|
||||
vi.spyOn(DMRoomMap, "shared").mockReturnValue(dmRoomMap);
|
||||
});
|
||||
|
||||
it("should return the room for a single target with a room", () => {
|
||||
mocked(findDMForUser).mockReturnValue(room1);
|
||||
vi.mocked(findDMForUser).mockReturnValue(room1);
|
||||
expect(findDMRoom(mockClient, [member1])).toBe(room1);
|
||||
});
|
||||
|
||||
it("should return undefined for a single target without a room", () => {
|
||||
mocked(findDMForUser).mockReturnValue(undefined);
|
||||
vi.mocked(findDMForUser).mockReturnValue(undefined);
|
||||
expect(findDMRoom(mockClient, [member1])).toBeNull();
|
||||
});
|
||||
|
||||
it("should return the room for 2 targets with a room", () => {
|
||||
mocked(dmRoomMap.getDMRoomForIdentifiers).mockReturnValue(room1);
|
||||
vi.mocked(dmRoomMap.getDMRoomForIdentifiers).mockReturnValue(room1);
|
||||
expect(findDMRoom(mockClient, [member1, member2])).toBe(room1);
|
||||
});
|
||||
|
||||
it("should return null for 2 targets without a room", () => {
|
||||
mocked(dmRoomMap.getDMRoomForIdentifiers).mockReturnValue(null);
|
||||
vi.mocked(dmRoomMap.getDMRoomForIdentifiers).mockReturnValue(null);
|
||||
expect(findDMRoom(mockClient, [member1, member2])).toBeNull();
|
||||
});
|
||||
});
|
||||
+2
-1
@@ -6,6 +6,7 @@ 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 { describe, it, expect } from "vitest";
|
||||
import {
|
||||
M_TEXT,
|
||||
type ILocationContent,
|
||||
@@ -16,7 +17,7 @@ import {
|
||||
ContentHelpers,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { isSelfLocation } from "../../../../src/utils/location";
|
||||
import { isSelfLocation } from "./isSelfLocation";
|
||||
|
||||
describe("isSelfLocation", () => {
|
||||
it("Returns true for a full m.asset event", () => {
|
||||
+6
-3
@@ -6,9 +6,12 @@ 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 { createMapSiteLinkFromEvent } from "../../../../src/utils/location";
|
||||
import { mkMessage } from "../../../test-utils";
|
||||
import { makeLegacyLocationEvent, makeLocationEvent } from "../../../test-utils/location";
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { mkMessage, makeLegacyLocationEvent, makeLocationEvent } from "test-utils";
|
||||
|
||||
import { createMapSiteLinkFromEvent } from "./links";
|
||||
|
||||
describe("createMapSiteLinkFromEvent", () => {
|
||||
it("returns null if event does not contain geouri", () => {
|
||||
+4
-2
@@ -6,8 +6,10 @@ 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 { locationEventGeoUri } from "../../../../src/utils/location";
|
||||
import { makeLegacyLocationEvent, makeLocationEvent } from "../../../test-utils/location";
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { makeLegacyLocationEvent, makeLocationEvent } from "test-utils/location";
|
||||
|
||||
import { locationEventGeoUri } from "./locationEventGeoUri";
|
||||
|
||||
describe("locationEventGeoUri()", () => {
|
||||
it("returns m.location uri when available", () => {
|
||||
+3
-1
@@ -6,7 +6,9 @@ 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 { parseGeoUri } from "../../../../src/utils/location/parseGeoUri";
|
||||
import { describe, it, expect } from "vitest";
|
||||
|
||||
import { parseGeoUri } from "./parseGeoUri";
|
||||
|
||||
describe("parseGeoUri", () => {
|
||||
it("fails if the supplied URI is empty", () => {
|
||||
+3
-1
@@ -6,7 +6,9 @@ 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 { positionFailureMessage } from "../../../../src/utils/location/positionFailureMessage";
|
||||
import { describe, it, expect } from "vitest";
|
||||
|
||||
import { positionFailureMessage } from "./positionFailureMessage";
|
||||
|
||||
describe("positionFailureMessage()", () => {
|
||||
// error codes from GeolocationPositionError
|
||||
+22
-20
@@ -6,22 +6,24 @@ 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 } from "jest-mock";
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { vi, describe, it, expect, beforeEach, afterEach } from "vitest";
|
||||
import { JoinRule, Room } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { getMockClientWithEventEmitter, mockClientMethodsUser } from "test-utils";
|
||||
|
||||
import { shouldShowComponent } from "../../../../src/customisations/helpers/UIComponents";
|
||||
import { UIComponent } from "../../../../src/settings/UIFeature";
|
||||
import { canInviteTo } from "../../../../src/utils/room/canInviteTo";
|
||||
import { getMockClientWithEventEmitter, mockClientMethodsUser } from "../../../test-utils";
|
||||
import { shouldShowComponent } from "../../customisations/helpers/UIComponents";
|
||||
import { UIComponent } from "../../settings/UIFeature";
|
||||
import { canInviteTo } from "./canInviteTo";
|
||||
|
||||
jest.mock("../../../../src/customisations/helpers/UIComponents", () => ({
|
||||
shouldShowComponent: jest.fn(),
|
||||
vi.mock("../../customisations/helpers/UIComponents", () => ({
|
||||
shouldShowComponent: vi.fn(),
|
||||
}));
|
||||
|
||||
describe("canInviteTo()", () => {
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
const userId = "@alice:server.org";
|
||||
@@ -32,14 +34,14 @@ describe("canInviteTo()", () => {
|
||||
...mockClientMethodsUser(userId),
|
||||
});
|
||||
const room = new Room(roomId, client, userId);
|
||||
jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Join);
|
||||
jest.spyOn(room, "getJoinRule").mockReturnValue(JoinRule.Public);
|
||||
jest.spyOn(room, "canInvite").mockReturnValue(true);
|
||||
vi.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Join);
|
||||
vi.spyOn(room, "getJoinRule").mockReturnValue(JoinRule.Public);
|
||||
vi.spyOn(room, "canInvite").mockReturnValue(true);
|
||||
return room;
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
mocked(shouldShowComponent).mockReturnValue(true);
|
||||
vi.mocked(shouldShowComponent).mockReturnValue(true);
|
||||
});
|
||||
|
||||
describe("when user has permissions to issue an invite for this room", () => {
|
||||
@@ -47,14 +49,14 @@ describe("canInviteTo()", () => {
|
||||
|
||||
it("should return false when current user membership is not joined", () => {
|
||||
const room = makeRoom();
|
||||
jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Invite);
|
||||
vi.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Invite);
|
||||
|
||||
expect(canInviteTo(room)).toEqual(false);
|
||||
});
|
||||
|
||||
it("should return false when UIComponent.InviteUsers customisation hides invite", () => {
|
||||
const room = makeRoom();
|
||||
mocked(shouldShowComponent).mockReturnValue(false);
|
||||
vi.mocked(shouldShowComponent).mockReturnValue(false);
|
||||
|
||||
expect(canInviteTo(room)).toEqual(false);
|
||||
expect(shouldShowComponent).toHaveBeenCalledWith(UIComponent.InviteUsers);
|
||||
@@ -72,16 +74,16 @@ describe("canInviteTo()", () => {
|
||||
|
||||
it("should return false when room is a private space", () => {
|
||||
const room = makeRoom();
|
||||
jest.spyOn(room, "getJoinRule").mockReturnValue(JoinRule.Invite);
|
||||
jest.spyOn(room, "isSpaceRoom").mockReturnValue(true);
|
||||
jest.spyOn(room, "canInvite").mockReturnValue(false);
|
||||
vi.spyOn(room, "getJoinRule").mockReturnValue(JoinRule.Invite);
|
||||
vi.spyOn(room, "isSpaceRoom").mockReturnValue(true);
|
||||
vi.spyOn(room, "canInvite").mockReturnValue(false);
|
||||
|
||||
expect(canInviteTo(room)).toEqual(false);
|
||||
});
|
||||
|
||||
it("should return false when room is just a room", () => {
|
||||
const room = makeRoom();
|
||||
jest.spyOn(room, "canInvite").mockReturnValue(false);
|
||||
vi.spyOn(room, "canInvite").mockReturnValue(false);
|
||||
|
||||
expect(canInviteTo(room)).toEqual(false);
|
||||
});
|
||||
@@ -89,8 +91,8 @@ describe("canInviteTo()", () => {
|
||||
it("should return true when room is a public space", () => {
|
||||
const room = makeRoom();
|
||||
// default join rule is public
|
||||
jest.spyOn(room, "isSpaceRoom").mockReturnValue(true);
|
||||
jest.spyOn(room, "canInvite").mockReturnValue(false);
|
||||
vi.spyOn(room, "isSpaceRoom").mockReturnValue(true);
|
||||
vi.spyOn(room, "canInvite").mockReturnValue(false);
|
||||
|
||||
expect(canInviteTo(room)).toEqual(true);
|
||||
});
|
||||
+14
-14
@@ -6,14 +6,14 @@ 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 } from "jest-mock";
|
||||
import { vi, describe, it, expect, beforeEach } from "vitest";
|
||||
import { type MatrixClient, Room, RoomMember } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { getFunctionalMembers } from "../../../../src/utils/room/getFunctionalMembers";
|
||||
import { getJoinedNonFunctionalMembers } from "../../../../src/utils/room/getJoinedNonFunctionalMembers";
|
||||
import { getFunctionalMembers } from "./getFunctionalMembers";
|
||||
import { getJoinedNonFunctionalMembers } from "./getJoinedNonFunctionalMembers";
|
||||
|
||||
jest.mock("../../../../src/utils/room/getFunctionalMembers", () => ({
|
||||
getFunctionalMembers: jest.fn(),
|
||||
vi.mock("./getFunctionalMembers", () => ({
|
||||
getFunctionalMembers: vi.fn(),
|
||||
}));
|
||||
|
||||
describe("getJoinedNonFunctionalMembers", () => {
|
||||
@@ -23,7 +23,7 @@ describe("getJoinedNonFunctionalMembers", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
room = new Room("!room:example.com", {} as unknown as MatrixClient, "@user:example.com");
|
||||
room.getJoinedMembers = jest.fn();
|
||||
room.getJoinedMembers = vi.fn();
|
||||
|
||||
roomMember1 = new RoomMember(room.roomId, "@user1:example.com");
|
||||
roomMember2 = new RoomMember(room.roomId, "@user2:example.com");
|
||||
@@ -31,8 +31,8 @@ describe("getJoinedNonFunctionalMembers", () => {
|
||||
|
||||
describe("if there are no members", () => {
|
||||
beforeEach(() => {
|
||||
mocked(room.getJoinedMembers).mockReturnValue([]);
|
||||
mocked(getFunctionalMembers).mockReturnValue([]);
|
||||
vi.mocked(room.getJoinedMembers).mockReturnValue([]);
|
||||
vi.mocked(getFunctionalMembers).mockReturnValue([]);
|
||||
});
|
||||
|
||||
it("should return an empty list", () => {
|
||||
@@ -42,8 +42,8 @@ describe("getJoinedNonFunctionalMembers", () => {
|
||||
|
||||
describe("if there are only regular room members", () => {
|
||||
beforeEach(() => {
|
||||
mocked(room.getJoinedMembers).mockReturnValue([roomMember1, roomMember2]);
|
||||
mocked(getFunctionalMembers).mockReturnValue([]);
|
||||
vi.mocked(room.getJoinedMembers).mockReturnValue([roomMember1, roomMember2]);
|
||||
vi.mocked(getFunctionalMembers).mockReturnValue([]);
|
||||
});
|
||||
|
||||
it("should return the room members", () => {
|
||||
@@ -55,8 +55,8 @@ describe("getJoinedNonFunctionalMembers", () => {
|
||||
|
||||
describe("if there are only functional room members", () => {
|
||||
beforeEach(() => {
|
||||
mocked(room.getJoinedMembers).mockReturnValue([]);
|
||||
mocked(getFunctionalMembers).mockReturnValue(["@functional:example.com"]);
|
||||
vi.mocked(room.getJoinedMembers).mockReturnValue([]);
|
||||
vi.mocked(getFunctionalMembers).mockReturnValue(["@functional:example.com"]);
|
||||
});
|
||||
|
||||
it("should return an empty list", () => {
|
||||
@@ -66,8 +66,8 @@ describe("getJoinedNonFunctionalMembers", () => {
|
||||
|
||||
describe("if there are some functional room members", () => {
|
||||
beforeEach(() => {
|
||||
mocked(room.getJoinedMembers).mockReturnValue([roomMember1, roomMember2]);
|
||||
mocked(getFunctionalMembers).mockReturnValue([roomMember1.userId]);
|
||||
vi.mocked(room.getJoinedMembers).mockReturnValue([roomMember1, roomMember2]);
|
||||
vi.mocked(getFunctionalMembers).mockReturnValue([roomMember1.userId]);
|
||||
});
|
||||
|
||||
it("should only return the non-functional members", () => {
|
||||
+6
-3
@@ -6,10 +6,13 @@ 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 { Room, UNSTABLE_ELEMENT_FUNCTIONAL_USERS } from "matrix-js-sdk/src/matrix";
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { getFunctionalMembers } from "../../../../src/utils/room/getFunctionalMembers";
|
||||
import { createTestClient, mkEvent } from "../../../test-utils";
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { Room, UNSTABLE_ELEMENT_FUNCTIONAL_USERS } from "matrix-js-sdk/src/matrix";
|
||||
import { createTestClient, mkEvent } from "test-utils";
|
||||
|
||||
import { getFunctionalMembers } from "./getFunctionalMembers";
|
||||
|
||||
describe("getRoomFunctionalMembers", () => {
|
||||
const client = createTestClient();
|
||||
+9
-6
@@ -5,16 +5,19 @@
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { vi, describe, it, expect } from "vitest";
|
||||
import { type Room } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { DefaultTagID } from "../../../../src/stores/room-list-v3/skip-list/tag";
|
||||
import { CUSTOM_SECTION_TAG_PREFIX } from "../../../../src/stores/room-list-v3/section";
|
||||
import { getSectionTagForRoom } from "../../../../src/utils/room/getSectionTagForRoom";
|
||||
import { getTagsForRoom } from "../../../../src/utils/room/getTagsForRoom";
|
||||
import { DefaultTagID } from "../../stores/room-list-v3/skip-list/tag";
|
||||
import { CUSTOM_SECTION_TAG_PREFIX } from "../../stores/room-list-v3/section";
|
||||
import { getSectionTagForRoom } from "./getSectionTagForRoom";
|
||||
import { getTagsForRoom } from "./getTagsForRoom";
|
||||
|
||||
jest.mock("../../../../src/utils/room/getTagsForRoom");
|
||||
vi.mock("./getTagsForRoom");
|
||||
|
||||
const mockGetTagsForRoom = jest.mocked(getTagsForRoom);
|
||||
const mockGetTagsForRoom = vi.mocked(getTagsForRoom);
|
||||
|
||||
describe("getSectionTagForRoom", () => {
|
||||
const room = {} as Room;
|
||||
+27
-25
@@ -5,14 +5,16 @@
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { vi, describe, it, expect, beforeEach } from "vitest";
|
||||
import { JoinRule, type MatrixClient, type Room } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { mocked } from "jest-mock";
|
||||
import { createTestClient, mkRoom } from "test-utils";
|
||||
|
||||
import { createTestClient, mkRoom } from "../../../test-utils";
|
||||
import { DefaultTagID } from "../../../../src/stores/room-list-v3/skip-list/tag";
|
||||
import { getTagsForRoom } from "../../../../src/utils/room/getTagsForRoom";
|
||||
import DMRoomMap from "../../../../src/utils/DMRoomMap";
|
||||
import { DefaultTagID } from "../../stores/room-list-v3/skip-list/tag";
|
||||
import { getTagsForRoom } from "./getTagsForRoom";
|
||||
import DMRoomMap from "../DMRoomMap";
|
||||
|
||||
describe("getTagsForRoom", () => {
|
||||
let client: MatrixClient;
|
||||
@@ -23,21 +25,21 @@ describe("getTagsForRoom", () => {
|
||||
rooms = [];
|
||||
|
||||
const dmRoomMap = {
|
||||
getUserIdForRoomId: jest.fn().mockReturnValue(undefined),
|
||||
getUserIdForRoomId: vi.fn().mockReturnValue(undefined),
|
||||
} as unknown as DMRoomMap;
|
||||
DMRoomMap.setShared(dmRoomMap);
|
||||
});
|
||||
|
||||
function makeRoom(roomId: string): Room {
|
||||
mkRoom(client, roomId, rooms);
|
||||
mocked(client).getRoom.mockImplementation((id) => rooms.find((r) => r.roomId === id) ?? null);
|
||||
mocked(client).getRooms.mockImplementation(() => rooms);
|
||||
vi.mocked(client).getRoom.mockImplementation((id) => rooms.find((r) => r.roomId === id) ?? null);
|
||||
vi.mocked(client).getRooms.mockImplementation(() => rooms);
|
||||
return client.getRoom(roomId)!;
|
||||
}
|
||||
|
||||
it("should return [Invite] for a room where the user is invited", () => {
|
||||
const room = makeRoom("!invited:server");
|
||||
(room.getMyMembership as jest.Mock).mockReturnValue(KnownMembership.Invite);
|
||||
vi.mocked(room.getMyMembership).mockReturnValue(KnownMembership.Invite);
|
||||
|
||||
const tags = getTagsForRoom(room);
|
||||
expect(tags).toEqual([DefaultTagID.Invite]);
|
||||
@@ -47,7 +49,7 @@ describe("getTagsForRoom", () => {
|
||||
"should return [Archived] for a room where the user has %s",
|
||||
(membership) => {
|
||||
const room = makeRoom(`!${membership.toLowerCase()}:server`);
|
||||
(room.getMyMembership as jest.Mock).mockReturnValue(membership);
|
||||
vi.mocked(room.getMyMembership).mockReturnValue(membership);
|
||||
|
||||
const tags = getTagsForRoom(room);
|
||||
expect(tags).toEqual([DefaultTagID.Archived]);
|
||||
@@ -58,7 +60,7 @@ describe("getTagsForRoom", () => {
|
||||
describe("with no user-defined tags and not a DM", () => {
|
||||
it("should return [Untagged] when the room has no tags and is not a DM", () => {
|
||||
const room = makeRoom("!plain:server");
|
||||
(room.getMyMembership as jest.Mock).mockReturnValue(KnownMembership.Join);
|
||||
vi.mocked(room.getMyMembership).mockReturnValue(KnownMembership.Join);
|
||||
(room as any).tags = {};
|
||||
|
||||
const tags = getTagsForRoom(room);
|
||||
@@ -68,10 +70,10 @@ describe("getTagsForRoom", () => {
|
||||
|
||||
it("should return [DM] when the room is a DM", () => {
|
||||
const room = makeRoom("!dm:server");
|
||||
(room.getMyMembership as jest.Mock).mockReturnValue(KnownMembership.Join);
|
||||
vi.mocked(room.getMyMembership).mockReturnValue(KnownMembership.Join);
|
||||
(room as any).tags = {};
|
||||
|
||||
mocked(DMRoomMap.shared().getUserIdForRoomId as jest.Mock).mockReturnValue("@alice:server");
|
||||
vi.mocked(DMRoomMap.shared().getUserIdForRoomId).mockReturnValue("@alice:server");
|
||||
|
||||
const tags = getTagsForRoom(room);
|
||||
expect(tags).toContain(DefaultTagID.DM);
|
||||
@@ -81,7 +83,7 @@ describe("getTagsForRoom", () => {
|
||||
describe("rooms with user-defined tags", () => {
|
||||
it("should return the user-defined tags", () => {
|
||||
const room = makeRoom("!tagged:server");
|
||||
(room.getMyMembership as jest.Mock).mockReturnValue(KnownMembership.Join);
|
||||
vi.mocked(room.getMyMembership).mockReturnValue(KnownMembership.Join);
|
||||
(room as any).tags = { "m.favourite": {}, "u.alice": {} };
|
||||
|
||||
const tags = getTagsForRoom(room);
|
||||
@@ -92,11 +94,11 @@ describe("getTagsForRoom", () => {
|
||||
|
||||
it("should not check DM status when user-defined tags are already present", () => {
|
||||
const room = makeRoom("!tagged-dm:server");
|
||||
(room.getMyMembership as jest.Mock).mockReturnValue(KnownMembership.Join);
|
||||
vi.mocked(room.getMyMembership).mockReturnValue(KnownMembership.Join);
|
||||
(room as any).tags = { "m.lowpriority": {} };
|
||||
|
||||
// Even if the room is a DM, user-defined tags take priority
|
||||
mocked(DMRoomMap.shared().getUserIdForRoomId as jest.Mock).mockReturnValue("@alice:server");
|
||||
vi.mocked(DMRoomMap.shared().getUserIdForRoomId).mockReturnValue("@alice:server");
|
||||
|
||||
const tags = getTagsForRoom(room);
|
||||
expect(tags).toContain("m.lowpriority");
|
||||
@@ -110,9 +112,9 @@ describe("getTagsForRoom", () => {
|
||||
"should include Conference tag for a call room with %s join rule",
|
||||
(joinRule) => {
|
||||
const room = makeRoom(`!call:${joinRule}:server`);
|
||||
(room.getMyMembership as jest.Mock).mockReturnValue(KnownMembership.Join);
|
||||
(room.isCallRoom as jest.Mock).mockReturnValue(true);
|
||||
(room.getJoinRule as jest.Mock).mockReturnValue(joinRule);
|
||||
vi.mocked(room.getMyMembership).mockReturnValue(KnownMembership.Join);
|
||||
vi.mocked(room.isCallRoom).mockReturnValue(true);
|
||||
vi.mocked(room.getJoinRule).mockReturnValue(joinRule);
|
||||
|
||||
const tags = getTagsForRoom(room);
|
||||
expect(tags).toContain(DefaultTagID.Conference);
|
||||
@@ -123,9 +125,9 @@ describe("getTagsForRoom", () => {
|
||||
"should not include Conference tag for a call room with %s join rule",
|
||||
(joinRule) => {
|
||||
const room = makeRoom(`!call:${joinRule}:server`);
|
||||
(room.getMyMembership as jest.Mock).mockReturnValue(KnownMembership.Join);
|
||||
(room.isCallRoom as jest.Mock).mockReturnValue(true);
|
||||
(room.getJoinRule as jest.Mock).mockReturnValue(joinRule);
|
||||
vi.mocked(room.getMyMembership).mockReturnValue(KnownMembership.Join);
|
||||
vi.mocked(room.isCallRoom).mockReturnValue(true);
|
||||
vi.mocked(room.getJoinRule).mockReturnValue(joinRule);
|
||||
|
||||
const tags = getTagsForRoom(room);
|
||||
expect(tags).not.toContain(DefaultTagID.Conference);
|
||||
@@ -134,10 +136,10 @@ describe("getTagsForRoom", () => {
|
||||
|
||||
it("should include Conference alongside Untagged for a public call room with no other tags", () => {
|
||||
const room = makeRoom("!callPublicPlain:server");
|
||||
(room.getMyMembership as jest.Mock).mockReturnValue(KnownMembership.Join);
|
||||
vi.mocked(room.getMyMembership).mockReturnValue(KnownMembership.Join);
|
||||
(room as any).tags = {};
|
||||
(room.isCallRoom as jest.Mock).mockReturnValue(true);
|
||||
(room.getJoinRule as jest.Mock).mockReturnValue(JoinRule.Public);
|
||||
vi.mocked(room.isCallRoom).mockReturnValue(true);
|
||||
vi.mocked(room.getJoinRule).mockReturnValue(JoinRule.Public);
|
||||
|
||||
const tags = getTagsForRoom(room);
|
||||
// Conference is added to the tag list before the Untagged fallback check,
|
||||
+12
-9
@@ -6,11 +6,14 @@ 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 { Room } from "matrix-js-sdk/src/matrix";
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import defaultDispatcher from "../../../../src/dispatcher/dispatcher";
|
||||
import { inviteToRoom } from "../../../../src/utils/room/inviteToRoom";
|
||||
import { getMockClientWithEventEmitter } from "../../../test-utils";
|
||||
import { vi, describe, it, expect, beforeEach, afterEach } from "vitest";
|
||||
import { Room } from "matrix-js-sdk/src/matrix";
|
||||
import { getMockClientWithEventEmitter } from "test-utils";
|
||||
|
||||
import defaultDispatcher from "../../dispatcher/dispatcher";
|
||||
import { inviteToRoom } from "./inviteToRoom";
|
||||
|
||||
describe("inviteToRoom()", () => {
|
||||
const userId = "@alice:server.org";
|
||||
@@ -18,7 +21,7 @@ describe("inviteToRoom()", () => {
|
||||
|
||||
const makeRoom = (): Room => {
|
||||
const client = getMockClientWithEventEmitter({
|
||||
isGuest: jest.fn(),
|
||||
isGuest: vi.fn(),
|
||||
});
|
||||
const room = new Room(roomId, client, userId);
|
||||
return room;
|
||||
@@ -26,17 +29,17 @@ describe("inviteToRoom()", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
// stub
|
||||
jest.spyOn(defaultDispatcher, "dispatch").mockImplementation(() => {});
|
||||
vi.spyOn(defaultDispatcher, "dispatch").mockImplementation(() => {});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it("requires registration when a guest tries to invite to a room", () => {
|
||||
const room = makeRoom();
|
||||
|
||||
jest.spyOn(room.client, "isGuest").mockReturnValue(true);
|
||||
vi.spyOn(room.client, "isGuest").mockReturnValue(true);
|
||||
|
||||
inviteToRoom(room);
|
||||
|
||||
@@ -47,7 +50,7 @@ describe("inviteToRoom()", () => {
|
||||
it("opens the room inviter", () => {
|
||||
const room = makeRoom();
|
||||
|
||||
jest.spyOn(room.client, "isGuest").mockReturnValue(false);
|
||||
vi.spyOn(room.client, "isGuest").mockReturnValue(false);
|
||||
|
||||
inviteToRoom(room);
|
||||
|
||||
+13
-11
@@ -6,16 +6,18 @@ 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 } from "jest-mock";
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { vi, describe, it, expect, beforeAll, beforeEach } from "vitest";
|
||||
import { type MatrixClient, type MatrixEvent, Room } from "matrix-js-sdk/src/matrix";
|
||||
import { mkRoomMemberJoinEvent, mkThirdPartyInviteEvent, stubClient } from "test-utils";
|
||||
|
||||
import DMRoomMap from "../../../../src/utils/DMRoomMap";
|
||||
import { shouldEncryptRoomWithSingle3rdPartyInvite } from "../../../../src/utils/room/shouldEncryptRoomWithSingle3rdPartyInvite";
|
||||
import { privateShouldBeEncrypted } from "../../../../src/utils/rooms";
|
||||
import { mkRoomMemberJoinEvent, mkThirdPartyInviteEvent, stubClient } from "../../../test-utils";
|
||||
import DMRoomMap from "../DMRoomMap";
|
||||
import { shouldEncryptRoomWithSingle3rdPartyInvite } from "./shouldEncryptRoomWithSingle3rdPartyInvite";
|
||||
import { privateShouldBeEncrypted } from "../rooms";
|
||||
|
||||
jest.mock("../../../../src/utils/rooms", () => ({
|
||||
privateShouldBeEncrypted: jest.fn(),
|
||||
vi.mock("../rooms", () => ({
|
||||
privateShouldBeEncrypted: vi.fn(),
|
||||
}));
|
||||
|
||||
describe("shouldEncryptRoomWithSingle3rdPartyInvite", () => {
|
||||
@@ -40,12 +42,12 @@ describe("shouldEncryptRoomWithSingle3rdPartyInvite", () => {
|
||||
mkRoomMemberJoinEvent(client.getSafeUserId(), roomWithOneThirdPartyInvite.roomId),
|
||||
thirdPartyInviteEvent,
|
||||
]);
|
||||
jest.spyOn(DMRoomMap.shared(), "getRoomIds").mockReturnValue(new Set([roomWithOneThirdPartyInvite.roomId]));
|
||||
vi.spyOn(DMRoomMap.shared(), "getRoomIds").mockReturnValue(new Set([roomWithOneThirdPartyInvite.roomId]));
|
||||
});
|
||||
|
||||
describe("when well-known promotes encryption", () => {
|
||||
beforeEach(() => {
|
||||
mocked(privateShouldBeEncrypted).mockReturnValue(true);
|
||||
vi.mocked(privateShouldBeEncrypted).mockReturnValue(true);
|
||||
});
|
||||
|
||||
it("should return true + invite event for a DM room with one third-party invite", () => {
|
||||
@@ -56,7 +58,7 @@ describe("shouldEncryptRoomWithSingle3rdPartyInvite", () => {
|
||||
});
|
||||
|
||||
it("should return false for a non-DM room with one third-party invite", () => {
|
||||
mocked(DMRoomMap.shared().getRoomIds).mockReturnValue(new Set());
|
||||
vi.mocked(DMRoomMap.shared().getRoomIds).mockReturnValue(new Set());
|
||||
|
||||
expect(shouldEncryptRoomWithSingle3rdPartyInvite(roomWithOneThirdPartyInvite)).toEqual({
|
||||
shouldEncrypt: false,
|
||||
@@ -90,7 +92,7 @@ describe("shouldEncryptRoomWithSingle3rdPartyInvite", () => {
|
||||
|
||||
describe("when well-known does not promote encryption", () => {
|
||||
beforeEach(() => {
|
||||
mocked(privateShouldBeEncrypted).mockReturnValue(false);
|
||||
vi.mocked(privateShouldBeEncrypted).mockReturnValue(false);
|
||||
});
|
||||
|
||||
it("should return false for a DM room with one third-party invite", () => {
|
||||
+8
-5
@@ -5,12 +5,15 @@ 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 { type Room } from "matrix-js-sdk/src/matrix";
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { createTestClient } from "../../../test-utils";
|
||||
import { getMockedRooms } from "../../stores/room-list-v3/skip-list/getMockedRooms";
|
||||
import { DefaultTagID } from "../../../../src/stores/room-list-v3/skip-list/tag";
|
||||
import { compareRoomsByRecency, sortRoomsByRecency } from "../../../../src/utils/room/sortRoomsByRecency";
|
||||
import { describe, it, expect, beforeEach } from "vitest";
|
||||
import { type Room } from "matrix-js-sdk/src/matrix";
|
||||
import { createTestClient } from "test-utils";
|
||||
|
||||
import { getMockedRooms } from "../../../test/unit-tests/stores/room-list-v3/skip-list/getMockedRooms";
|
||||
import { DefaultTagID } from "../../stores/room-list-v3/skip-list/tag";
|
||||
import { compareRoomsByRecency, sortRoomsByRecency } from "./sortRoomsByRecency";
|
||||
|
||||
describe("sortRoomsByRecency", () => {
|
||||
let userId: string;
|
||||
+16
-13
@@ -6,15 +6,18 @@ 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 { Room } from "matrix-js-sdk/src/matrix";
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import RoomListActions from "../../../../src/actions/RoomListActions";
|
||||
import defaultDispatcher from "../../../../src/dispatcher/dispatcher";
|
||||
import { DefaultTagID, type TagID } from "../../../../src/stores/room-list-v3/skip-list/tag";
|
||||
import { CHATS_TAG, CUSTOM_SECTION_TAG_PREFIX } from "../../../../src/stores/room-list-v3/section";
|
||||
import { tagRoom } from "../../../../src/utils/room/tagRoom";
|
||||
import { getMockClientWithEventEmitter } from "../../../test-utils";
|
||||
import * as getSectionTagForRoomUtils from "../../../../src/utils/room/getSectionTagForRoom";
|
||||
import { vi, describe, it, expect, beforeEach, afterEach } from "vitest";
|
||||
import { Room } from "matrix-js-sdk/src/matrix";
|
||||
import { getMockClientWithEventEmitter } from "test-utils";
|
||||
|
||||
import RoomListActions from "../../actions/RoomListActions";
|
||||
import defaultDispatcher from "../../dispatcher/dispatcher";
|
||||
import { DefaultTagID, type TagID } from "../../stores/room-list-v3/skip-list/tag";
|
||||
import { CHATS_TAG, CUSTOM_SECTION_TAG_PREFIX } from "../../stores/room-list-v3/section";
|
||||
import { tagRoom } from "./tagRoom";
|
||||
import * as getSectionTagForRoomUtils from "./getSectionTagForRoom";
|
||||
|
||||
describe("tagRoom()", () => {
|
||||
const userId = "@alice:server.org";
|
||||
@@ -23,23 +26,23 @@ describe("tagRoom()", () => {
|
||||
|
||||
const makeRoom = (currentSectionTag: TagID | null = null): Room => {
|
||||
const client = getMockClientWithEventEmitter({
|
||||
isGuest: jest.fn(),
|
||||
isGuest: vi.fn(),
|
||||
});
|
||||
const room = new Room(roomId, client, userId);
|
||||
|
||||
jest.spyOn(getSectionTagForRoomUtils, "getSectionTagForRoom").mockReturnValue(currentSectionTag);
|
||||
vi.spyOn(getSectionTagForRoomUtils, "getSectionTagForRoom").mockReturnValue(currentSectionTag);
|
||||
|
||||
return room;
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
// stub
|
||||
jest.spyOn(defaultDispatcher, "dispatch").mockImplementation(() => {});
|
||||
jest.spyOn(RoomListActions, "tagRoom").mockReturnValue({ action: "mocked_tag_room_action", fn: () => {} });
|
||||
vi.spyOn(defaultDispatcher, "dispatch").mockImplementation(() => {});
|
||||
vi.spyOn(RoomListActions, "tagRoom").mockReturnValue({ action: "mocked_tag_room_action", fn: () => {} });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it("does nothing when room tag is not allowed", () => {
|
||||
@@ -7,6 +7,7 @@ Please see LICENSE files in the repository root for full details.
|
||||
|
||||
import type { MatrixClient, Room } from "matrix-js-sdk/src/matrix";
|
||||
import { mkMessage, mkStubRoom } from "../../../../test-utils";
|
||||
import { vi } from "../../../../setup/adapter.ts";
|
||||
|
||||
export function getMockedRooms(client: MatrixClient, roomCount: number = 100): Room[] {
|
||||
const rooms: Room[] = [];
|
||||
@@ -14,7 +15,7 @@ export function getMockedRooms(client: MatrixClient, roomCount: number = 100): R
|
||||
const roomId = `!foo${i}:matrix.org`;
|
||||
const room = mkStubRoom(roomId, `Foo Room ${i}`, client);
|
||||
const event = mkMessage({ room: roomId, user: `@foo${i}:matrix.org`, ts: i + 1, event: true });
|
||||
jest.spyOn(room.getLiveTimeline(), "getEvents").mockReturnValue([event]);
|
||||
vi.spyOn(room.getLiveTimeline(), "getEvents").mockReturnValue([event]);
|
||||
rooms.push(room);
|
||||
}
|
||||
return rooms;
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
"paths": {
|
||||
"jest-matrix-react": ["./test/test-utils/jest-matrix-react"],
|
||||
"test-utils-rtl": ["./test/test-utils/jest-matrix-react"],
|
||||
"test-utils": ["./test/test-utils"],
|
||||
"test-utils/*": ["./test/test-utils/*"],
|
||||
"jest-mock-vitest-adapter": ["./test/setup/adapter.ts"]
|
||||
}
|
||||
},
|
||||
|
||||
@@ -12,6 +12,7 @@ export default defineProject({
|
||||
resolve: {
|
||||
alias: [
|
||||
{ find: "test-utils-rtl", replacement: resolve(__dirname, "./test/test-utils/jest-matrix-react") },
|
||||
{ find: "test-utils", replacement: resolve(__dirname, "./test/test-utils") },
|
||||
// Stub out workers as they do not play well under test
|
||||
{
|
||||
find: /.*workers\/(.+)Factory/,
|
||||
|
||||
Reference in New Issue
Block a user