Skip to content
This repository was archived by the owner on Oct 22, 2024. It is now read-only.

Commit 5f113c4

Browse files
authored
Fix bell icons on room list hover being black squares (#135)
* Fix bell icons on room list hover being black squares The EchoStore wasn't being set up and therefore missed the client being injected. Patch from @t3chguy. * Fix tests ...by mocking out createClient so it doesn't try to start a real client. * More mocks * Don't need this anymore either
1 parent a2cee6b commit 5f113c4

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

src/stores/ReadyWatchingStore.ts

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export abstract class ReadyWatchingStore extends EventEmitter implements IDestro
2929
super();
3030

3131
this.dispatcherRef = this.dispatcher.register(this.onAction);
32+
33+
ReadyWatchingStore.instances.push(this);
3234
}
3335

3436
public get matrixClient(): MatrixClient | null {

test/MatrixClientPeg-test.ts

+9-11
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
66
Please see LICENSE files in the repository root for full details.
77
*/
88

9+
import * as MatrixJs from "matrix-js-sdk/src/matrix";
910
import { logger } from "matrix-js-sdk/src/logger";
10-
import fetchMockJest from "fetch-mock-jest";
1111

1212
import { advanceDateAndTime, stubClient } from "./test-utils";
1313
import { IMatrixClientPeg, MatrixClientPeg as peg } from "../src/MatrixClientPeg";
@@ -19,9 +19,14 @@ jest.useFakeTimers();
1919
const PegClass = Object.getPrototypeOf(peg).constructor;
2020

2121
describe("MatrixClientPeg", () => {
22+
let mockClient: MatrixJs.MatrixClient;
23+
2224
beforeEach(() => {
2325
// stub out Logger.log which gets called a lot and clutters up the test output
2426
jest.spyOn(logger, "log").mockImplementation(() => {});
27+
28+
mockClient = stubClient();
29+
jest.spyOn(MatrixJs, "createClient").mockReturnValue(mockClient);
2530
});
2631

2732
afterEach(() => {
@@ -33,7 +38,6 @@ describe("MatrixClientPeg", () => {
3338
});
3439

3540
it("setJustRegisteredUserId", () => {
36-
stubClient();
3741
(peg as any).matrixClient = peg.get();
3842
peg.setJustRegisteredUserId("@userId:matrix.org");
3943
expect(peg.safeGet().credentials.userId).toBe("@userId:matrix.org");
@@ -52,7 +56,6 @@ describe("MatrixClientPeg", () => {
5256
});
5357

5458
it("setJustRegisteredUserId(null)", () => {
55-
stubClient();
5659
(peg as any).matrixClient = peg.get();
5760
peg.setJustRegisteredUserId(null);
5861
expect(peg.currentUserIsJustRegistered()).toBe(false);
@@ -71,7 +74,6 @@ describe("MatrixClientPeg", () => {
7174
beforeEach(() => {
7275
// instantiate a MatrixClientPegClass instance, with a new MatrixClient
7376
testPeg = new PegClass();
74-
fetchMockJest.get("http://example.com/_matrix/client/versions", {});
7577
testPeg.replaceUsingCreds({
7678
accessToken: "SEKRET",
7779
homeserverUrl: "http://example.com",
@@ -83,24 +85,20 @@ describe("MatrixClientPeg", () => {
8385
it("should initialise the rust crypto library by default", async () => {
8486
const mockSetValue = jest.spyOn(SettingsStore, "setValue").mockResolvedValue(undefined);
8587

86-
const mockInitCrypto = jest.spyOn(testPeg.safeGet(), "initCrypto").mockResolvedValue(undefined);
87-
const mockInitRustCrypto = jest.spyOn(testPeg.safeGet(), "initRustCrypto").mockResolvedValue(undefined);
88-
8988
const cryptoStoreKey = new Uint8Array([1, 2, 3, 4]);
9089
await testPeg.start({ rustCryptoStoreKey: cryptoStoreKey });
91-
expect(mockInitCrypto).not.toHaveBeenCalled();
92-
expect(mockInitRustCrypto).toHaveBeenCalledWith({ storageKey: cryptoStoreKey });
90+
expect(mockClient.initCrypto).not.toHaveBeenCalled();
91+
expect(mockClient.initRustCrypto).toHaveBeenCalledWith({ storageKey: cryptoStoreKey });
9392

9493
// we should have stashed the setting in the settings store
9594
expect(mockSetValue).toHaveBeenCalledWith("feature_rust_crypto", null, SettingLevel.DEVICE, true);
9695
});
9796

9897
it("Should migrate existing login", async () => {
9998
const mockSetValue = jest.spyOn(SettingsStore, "setValue").mockResolvedValue(undefined);
100-
const mockInitRustCrypto = jest.spyOn(testPeg.safeGet(), "initRustCrypto").mockResolvedValue(undefined);
10199

102100
await testPeg.start();
103-
expect(mockInitRustCrypto).toHaveBeenCalledTimes(1);
101+
expect(mockClient.initRustCrypto).toHaveBeenCalledTimes(1);
104102

105103
// we should have stashed the setting in the settings store
106104
expect(mockSetValue).toHaveBeenCalledWith("feature_rust_crypto", null, SettingLevel.DEVICE, true);

test/test-utils/test-utils.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,14 @@ export function createTestClient(): MatrixClient {
8686
let txnId = 1;
8787

8888
const client = {
89+
startClient: jest.fn(),
8990
getHomeserverUrl: jest.fn(),
9091
getIdentityServerUrl: jest.fn(),
9192
getDomain: jest.fn().mockReturnValue("matrix.org"),
9293
getUserId: jest.fn().mockReturnValue("@userId:matrix.org"),
9394
getSafeUserId: jest.fn().mockReturnValue("@userId:matrix.org"),
9495
getUserIdLocalpart: jest.fn().mockResolvedValue("userId"),
95-
getUser: jest.fn().mockReturnValue({ on: jest.fn(), off: jest.fn() }),
96+
getUser: jest.fn().mockReturnValue({ on: jest.fn(), off: jest.fn(), removeListener: jest.fn() }),
9697
getDevice: jest.fn(),
9798
getDeviceId: jest.fn().mockReturnValue("ABCDEFGHI"),
9899
getStoredCrossSigningForUser: jest.fn(),
@@ -133,6 +134,8 @@ export function createTestClient(): MatrixClient {
133134
getVerificationRequestsToDeviceInProgress: jest.fn().mockReturnValue([]),
134135
setDeviceIsolationMode: jest.fn(),
135136
}),
137+
initCrypto: jest.fn(),
138+
initRustCrypto: jest.fn(),
136139

137140
getPushActionsForEvent: jest.fn(),
138141
getRoom: jest.fn().mockImplementation((roomId) => mkStubRoom(roomId, "My room", client)),
@@ -180,6 +183,7 @@ export function createTestClient(): MatrixClient {
180183
getSyncState: jest.fn().mockReturnValue("SYNCING"),
181184
generateClientSecret: () => "t35tcl1Ent5ECr3T",
182185
isGuest: jest.fn().mockReturnValue(false),
186+
setGuest: jest.fn(),
183187
getRoomHierarchy: jest.fn().mockReturnValue({
184188
rooms: [],
185189
}),
@@ -277,6 +281,7 @@ export function createTestClient(): MatrixClient {
277281
isFallbackICEServerAllowed: jest.fn().mockReturnValue(false),
278282
getAuthIssuer: jest.fn(),
279283
getOrCreateFilter: jest.fn(),
284+
setNotifTimelineSet: jest.fn(),
280285
} as unknown as MatrixClient;
281286

282287
client.reEmitter = new ReEmitter(client);

0 commit comments

Comments
 (0)