Tests for AdvancedRoomSettingsTab (#9994)
* Sort the methods in mkStubRoom * Tests for AdvancedRoomSettingsTab
This commit is contained in:
parent
b3586cf194
commit
32bd350b7e
3 changed files with 215 additions and 53 deletions
|
@ -40,6 +40,7 @@ import { MediaHandler } from "matrix-js-sdk/src/webrtc/mediaHandler";
|
|||
import { Feature, ServerSupport } from "matrix-js-sdk/src/feature";
|
||||
import { CryptoBackend } from "matrix-js-sdk/src/common-crypto/CryptoBackend";
|
||||
import { IEventDecryptionResult } from "matrix-js-sdk/src/@types/crypto";
|
||||
import { MapperOpts } from "matrix-js-sdk/src/event-mapper";
|
||||
|
||||
import type { GroupCall } from "matrix-js-sdk/src/webrtc/groupCall";
|
||||
import { MatrixClientPeg as peg } from "../../src/MatrixClientPeg";
|
||||
|
@ -145,7 +146,7 @@ export function createTestClient(): MatrixClient {
|
|||
content: {},
|
||||
});
|
||||
}),
|
||||
mxcUrlToHttp: (mxc) => `http://this.is.a.url/${mxc.substring(6)}`,
|
||||
mxcUrlToHttp: (mxc: string) => `http://this.is.a.url/${mxc.substring(6)}`,
|
||||
setAccountData: jest.fn(),
|
||||
setRoomAccountData: jest.fn(),
|
||||
setRoomTopic: jest.fn(),
|
||||
|
@ -200,7 +201,7 @@ export function createTestClient(): MatrixClient {
|
|||
stopAllStreams: jest.fn(),
|
||||
} as unknown as MediaHandler),
|
||||
uploadContent: jest.fn(),
|
||||
getEventMapper: () => (opts) => new MatrixEvent(opts),
|
||||
getEventMapper: (_options?: MapperOpts) => (event: Partial<IEvent>) => new MatrixEvent(event),
|
||||
leaveRoomChain: jest.fn((roomId) => ({ [roomId]: null })),
|
||||
doesServerSupportLogoutDevices: jest.fn().mockReturnValue(true),
|
||||
requestPasswordEmailToken: jest.fn().mockRejectedValue({}),
|
||||
|
@ -476,34 +477,11 @@ export function mkMessage({
|
|||
}
|
||||
|
||||
export function mkStubRoom(roomId: string = null, name: string, client: MatrixClient): Room {
|
||||
const stubTimeline = { getEvents: () => [] } as unknown as EventTimeline;
|
||||
const stubTimeline = { getEvents: () => [] as MatrixEvent[] } as unknown as EventTimeline;
|
||||
return {
|
||||
roomId,
|
||||
getReceiptsForEvent: jest.fn().mockReturnValue([]),
|
||||
getMember: jest.fn().mockReturnValue({
|
||||
userId: "@member:domain.bla",
|
||||
name: "Member",
|
||||
rawDisplayName: "Member",
|
||||
roomId: roomId,
|
||||
getAvatarUrl: () => "mxc://avatar.url/image.png",
|
||||
getMxcAvatarUrl: () => "mxc://avatar.url/image.png",
|
||||
}),
|
||||
getMembersWithMembership: jest.fn().mockReturnValue([]),
|
||||
getJoinedMembers: jest.fn().mockReturnValue([]),
|
||||
getJoinedMemberCount: jest.fn().mockReturnValue(1),
|
||||
getInvitedAndJoinedMemberCount: jest.fn().mockReturnValue(1),
|
||||
setUnreadNotificationCount: jest.fn(),
|
||||
getMembers: jest.fn().mockReturnValue([]),
|
||||
getPendingEvents: () => [],
|
||||
getLiveTimeline: jest.fn().mockReturnValue(stubTimeline),
|
||||
getUnfilteredTimelineSet: jest.fn(),
|
||||
findEventById: () => null,
|
||||
getAccountData: () => null,
|
||||
hasMembershipState: () => null,
|
||||
getVersion: () => "1",
|
||||
shouldUpgradeToVersion: () => null,
|
||||
getMyMembership: jest.fn().mockReturnValue("join"),
|
||||
maySendMessage: jest.fn().mockReturnValue(true),
|
||||
canInvite: jest.fn(),
|
||||
client,
|
||||
createThreadsTimelineSets: jest.fn().mockReturnValue(new Promise(() => {})),
|
||||
currentState: {
|
||||
getStateEvents: jest.fn((_type, key) => (key === undefined ? [] : null)),
|
||||
getMember: jest.fn(),
|
||||
|
@ -516,37 +494,62 @@ export function mkStubRoom(roomId: string = null, name: string, client: MatrixCl
|
|||
on: jest.fn(),
|
||||
off: jest.fn(),
|
||||
} as unknown as RoomState,
|
||||
tags: {},
|
||||
setBlacklistUnverifiedDevices: jest.fn(),
|
||||
on: jest.fn(),
|
||||
off: jest.fn(),
|
||||
removeListener: jest.fn(),
|
||||
eventShouldLiveIn: jest.fn().mockReturnValue({}),
|
||||
fetchRoomThreads: jest.fn().mockReturnValue(Promise.resolve()),
|
||||
findEventById: (_: string) => undefined as MatrixEvent | undefined,
|
||||
findPredecessor: jest.fn().mockReturnValue({ roomId: "", eventId: null }),
|
||||
getAccountData: (_: EventType | string) => undefined as MatrixEvent | undefined,
|
||||
getAltAliases: jest.fn().mockReturnValue([]),
|
||||
getAvatarUrl: () => "mxc://avatar.url/room.png",
|
||||
getCanonicalAlias: jest.fn(),
|
||||
getDMInviter: jest.fn(),
|
||||
getEventReadUpTo: jest.fn(() => null),
|
||||
getInvitedAndJoinedMemberCount: jest.fn().mockReturnValue(1),
|
||||
getJoinRule: jest.fn().mockReturnValue("invite"),
|
||||
getJoinedMemberCount: jest.fn().mockReturnValue(1),
|
||||
getJoinedMembers: jest.fn().mockReturnValue([]),
|
||||
getLiveTimeline: jest.fn().mockReturnValue(stubTimeline),
|
||||
getMember: jest.fn().mockReturnValue({
|
||||
userId: "@member:domain.bla",
|
||||
name: "Member",
|
||||
rawDisplayName: "Member",
|
||||
roomId: roomId,
|
||||
getAvatarUrl: () => "mxc://avatar.url/image.png",
|
||||
getMxcAvatarUrl: () => "mxc://avatar.url/image.png",
|
||||
}),
|
||||
getMembers: jest.fn().mockReturnValue([]),
|
||||
getMembersWithMembership: jest.fn().mockReturnValue([]),
|
||||
getMxcAvatarUrl: () => "mxc://avatar.url/room.png",
|
||||
getMyMembership: jest.fn().mockReturnValue("join"),
|
||||
getPendingEvents: () => [] as MatrixEvent[],
|
||||
getReceiptsForEvent: jest.fn().mockReturnValue([]),
|
||||
getRecommendedVersion: jest.fn().mockReturnValue(Promise.resolve("")),
|
||||
getThreads: jest.fn().mockReturnValue([]),
|
||||
getType: jest.fn().mockReturnValue(undefined),
|
||||
getUnfilteredTimelineSet: jest.fn(),
|
||||
getUnreadNotificationCount: jest.fn(() => 0),
|
||||
getVersion: jest.fn().mockReturnValue("1"),
|
||||
hasMembershipState: () => false,
|
||||
isElementVideoRoom: jest.fn().mockReturnValue(false),
|
||||
isSpaceRoom: jest.fn().mockReturnValue(false),
|
||||
loadMembersIfNeeded: jest.fn(),
|
||||
maySendMessage: jest.fn().mockReturnValue(true),
|
||||
myUserId: client?.getUserId(),
|
||||
name,
|
||||
normalizedName: normalize(name || ""),
|
||||
getAvatarUrl: () => "mxc://avatar.url/room.png",
|
||||
getMxcAvatarUrl: () => "mxc://avatar.url/room.png",
|
||||
isSpaceRoom: jest.fn().mockReturnValue(false),
|
||||
getType: jest.fn().mockReturnValue(undefined),
|
||||
isElementVideoRoom: jest.fn().mockReturnValue(false),
|
||||
getUnreadNotificationCount: jest.fn(() => 0),
|
||||
getEventReadUpTo: jest.fn(() => null),
|
||||
getCanonicalAlias: jest.fn(),
|
||||
getAltAliases: jest.fn().mockReturnValue([]),
|
||||
off: jest.fn(),
|
||||
on: jest.fn(),
|
||||
removeListener: jest.fn(),
|
||||
roomId,
|
||||
setBlacklistUnverifiedDevices: jest.fn(),
|
||||
setUnreadNotificationCount: jest.fn(),
|
||||
shouldUpgradeToVersion: (() => null) as () => string | null,
|
||||
tags: {},
|
||||
timeline: [],
|
||||
getJoinRule: jest.fn().mockReturnValue("invite"),
|
||||
loadMembersIfNeeded: jest.fn(),
|
||||
client,
|
||||
myUserId: client?.getUserId(),
|
||||
canInvite: jest.fn(),
|
||||
getThreads: jest.fn().mockReturnValue([]),
|
||||
eventShouldLiveIn: jest.fn().mockReturnValue({}),
|
||||
createThreadsTimelineSets: jest.fn().mockReturnValue(new Promise(() => {})),
|
||||
fetchRoomThreads: jest.fn().mockReturnValue(new Promise(() => {})),
|
||||
} as unknown as Room;
|
||||
}
|
||||
|
||||
export function mkServerConfig(hsUrl, isUrl) {
|
||||
export function mkServerConfig(hsUrl: string, isUrl: string) {
|
||||
return makeType(ValidatedServerConfig, {
|
||||
hsUrl,
|
||||
hsName: "TEST_ENVIRONMENT",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue