Add MatrixClientPeg::safeGet and use it in tests (#10985)
This commit is contained in:
parent
c47b587225
commit
6b46d6e4f8
88 changed files with 290 additions and 226 deletions
|
@ -30,7 +30,7 @@ let client: MatrixClient;
|
|||
describe("LegacyCallEventGrouper", () => {
|
||||
beforeEach(() => {
|
||||
stubClient();
|
||||
client = MatrixClientPeg.get();
|
||||
client = MatrixClientPeg.safeGet();
|
||||
client.getUserId = () => {
|
||||
return MY_USER_ID;
|
||||
};
|
||||
|
|
|
@ -90,7 +90,7 @@ describe("PipContainer", () => {
|
|||
user = userEvent.setup();
|
||||
|
||||
stubClient();
|
||||
client = mocked(MatrixClientPeg.get());
|
||||
client = mocked(MatrixClientPeg.safeGet());
|
||||
DMRoomMap.makeShared(client);
|
||||
|
||||
room = new Room("!1:example.org", client, "@alice:example.org", {
|
||||
|
|
|
@ -47,7 +47,7 @@ describe("RightPanel", () => {
|
|||
let RightPanel: React.ComponentType<React.ComponentProps<typeof RightPanelBase>>;
|
||||
beforeEach(() => {
|
||||
stubClient();
|
||||
cli = mocked(MatrixClientPeg.get());
|
||||
cli = mocked(MatrixClientPeg.safeGet());
|
||||
DMRoomMap.makeShared(cli);
|
||||
context = new SdkContextClass();
|
||||
context.client = cli;
|
||||
|
|
|
@ -45,7 +45,7 @@ describe("<RoomSearchView/>", () => {
|
|||
|
||||
beforeEach(async () => {
|
||||
stubClient();
|
||||
client = MatrixClientPeg.get();
|
||||
client = MatrixClientPeg.safeGet();
|
||||
client.supportsThreads = jest.fn().mockReturnValue(true);
|
||||
room = new Room("!room:server", client, client.getSafeUserId());
|
||||
mocked(client.getRoom).mockReturnValue(room);
|
||||
|
|
|
@ -37,7 +37,7 @@ describe("RoomStatusBar", () => {
|
|||
jest.clearAllMocks();
|
||||
|
||||
stubClient();
|
||||
client = MatrixClientPeg.get();
|
||||
client = MatrixClientPeg.safeGet();
|
||||
client.getSyncStateData = jest.fn().mockReturnValue({});
|
||||
room = new Room(ROOM_ID, client, client.getUserId()!, {
|
||||
pendingEventOrdering: PendingEventOrdering.Detached,
|
||||
|
|
|
@ -76,7 +76,7 @@ describe("RoomView", () => {
|
|||
beforeEach(() => {
|
||||
mockPlatformPeg({ reload: () => {} });
|
||||
stubClient();
|
||||
cli = mocked(MatrixClientPeg.get());
|
||||
cli = mocked(MatrixClientPeg.safeGet());
|
||||
|
||||
room = new Room(`!${roomCount++}:example.org`, cli, "@alice:example.org");
|
||||
jest.spyOn(room, "findPredecessor");
|
||||
|
|
|
@ -43,7 +43,7 @@ describe("SpaceHierarchy", () => {
|
|||
let room: Room;
|
||||
beforeEach(() => {
|
||||
stubClient();
|
||||
client = MatrixClientPeg.get();
|
||||
client = MatrixClientPeg.safeGet();
|
||||
room = new Room("room-id", client, "@alice:example.com");
|
||||
hierarchy = new RoomHierarchy(room);
|
||||
|
||||
|
@ -82,7 +82,7 @@ describe("SpaceHierarchy", () => {
|
|||
|
||||
describe("toLocalRoom", () => {
|
||||
stubClient();
|
||||
const client = MatrixClientPeg.get();
|
||||
const client = MatrixClientPeg.safeGet();
|
||||
const roomV1 = mkStubRoom("room-id-1", "Room V1", client);
|
||||
const roomV2 = mkStubRoom("room-id-2", "Room V2", client);
|
||||
const roomV3 = mkStubRoom("room-id-3", "Room V3", client);
|
||||
|
@ -171,7 +171,7 @@ describe("SpaceHierarchy", () => {
|
|||
});
|
||||
|
||||
stubClient();
|
||||
const client = MatrixClientPeg.get();
|
||||
const client = MatrixClientPeg.safeGet();
|
||||
|
||||
const dmRoomMap = {
|
||||
getUserIdForRoomId: jest.fn(),
|
||||
|
|
|
@ -120,7 +120,7 @@ describe("ThreadPanel", () => {
|
|||
|
||||
stubClient();
|
||||
mockPlatformPeg();
|
||||
mockClient = mocked(MatrixClientPeg.get());
|
||||
mockClient = mocked(MatrixClientPeg.safeGet());
|
||||
Thread.setServerSideSupport(FeatureSupport.Stable);
|
||||
Thread.setServerSideListSupport(FeatureSupport.Stable);
|
||||
Thread.setServerSideFwdPaginationSupport(FeatureSupport.Stable);
|
||||
|
|
|
@ -115,7 +115,7 @@ describe("ThreadView", () => {
|
|||
|
||||
stubClient();
|
||||
mockPlatformPeg();
|
||||
mockClient = mocked(MatrixClientPeg.get());
|
||||
mockClient = mocked(MatrixClientPeg.safeGet());
|
||||
jest.spyOn(mockClient, "supportsThreads").mockReturnValue(true);
|
||||
|
||||
room = new Room(ROOM_ID, mockClient, mockClient.getUserId() ?? "", {
|
||||
|
|
|
@ -106,7 +106,7 @@ const mockEvents = (room: Room, count = 2): MatrixEvent[] => {
|
|||
};
|
||||
|
||||
const setupTestData = (): [MatrixClient, Room, MatrixEvent[]] => {
|
||||
const client = MatrixClientPeg.get();
|
||||
const client = MatrixClientPeg.safeGet();
|
||||
const room = mkRoom(client, "roomId");
|
||||
const events = mockEvents(room);
|
||||
return [client, room, events];
|
||||
|
@ -377,7 +377,7 @@ describe("TimelinePanel", () => {
|
|||
});
|
||||
|
||||
it("should scroll event into view when props.eventId changes", () => {
|
||||
const client = MatrixClientPeg.get();
|
||||
const client = MatrixClientPeg.safeGet();
|
||||
const room = mkRoom(client, "roomId");
|
||||
const events = mockEvents(room);
|
||||
|
||||
|
@ -798,7 +798,7 @@ describe("TimelinePanel", () => {
|
|||
let reply2: MatrixEvent;
|
||||
|
||||
beforeEach(() => {
|
||||
client = MatrixClientPeg.get();
|
||||
client = MatrixClientPeg.safeGet();
|
||||
|
||||
Thread.hasServerSideSupport = FeatureSupport.Stable;
|
||||
room = new Room("roomId", client, "userId");
|
||||
|
@ -952,7 +952,7 @@ describe("TimelinePanel", () => {
|
|||
});
|
||||
|
||||
it("renders when the last message is an undecryptable thread root", async () => {
|
||||
const client = MatrixClientPeg.get();
|
||||
const client = MatrixClientPeg.safeGet();
|
||||
client.isRoomEncrypted = () => true;
|
||||
client.supportsThreads = () => true;
|
||||
client.decryptEventIfNeeded = () => Promise.resolve();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue