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