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

Fix bell icons on room list hover being black squares #135

Merged
merged 4 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/stores/ReadyWatchingStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export abstract class ReadyWatchingStore extends EventEmitter implements IDestro
super();

this.dispatcherRef = this.dispatcher.register(this.onAction);

ReadyWatchingStore.instances.push(this);
}

public get matrixClient(): MatrixClient | null {
Expand Down
20 changes: 9 additions & 11 deletions test/MatrixClientPeg-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
Please see LICENSE files in the repository root for full details.
*/

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

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

describe("MatrixClientPeg", () => {
let mockClient: MatrixJs.MatrixClient;

beforeEach(() => {
// stub out Logger.log which gets called a lot and clutters up the test output
jest.spyOn(logger, "log").mockImplementation(() => {});

mockClient = stubClient();
jest.spyOn(MatrixJs, "createClient").mockReturnValue(mockClient);
});

afterEach(() => {
Expand All @@ -33,7 +38,6 @@ describe("MatrixClientPeg", () => {
});

it("setJustRegisteredUserId", () => {
stubClient();
(peg as any).matrixClient = peg.get();
peg.setJustRegisteredUserId("@userId:matrix.org");
expect(peg.safeGet().credentials.userId).toBe("@userId:matrix.org");
Expand All @@ -52,7 +56,6 @@ describe("MatrixClientPeg", () => {
});

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

const mockInitCrypto = jest.spyOn(testPeg.safeGet(), "initCrypto").mockResolvedValue(undefined);
const mockInitRustCrypto = jest.spyOn(testPeg.safeGet(), "initRustCrypto").mockResolvedValue(undefined);

const cryptoStoreKey = new Uint8Array([1, 2, 3, 4]);
await testPeg.start({ rustCryptoStoreKey: cryptoStoreKey });
expect(mockInitCrypto).not.toHaveBeenCalled();
expect(mockInitRustCrypto).toHaveBeenCalledWith({ storageKey: cryptoStoreKey });
expect(mockClient.initCrypto).not.toHaveBeenCalled();
expect(mockClient.initRustCrypto).toHaveBeenCalledWith({ storageKey: cryptoStoreKey });

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

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

await testPeg.start();
expect(mockInitRustCrypto).toHaveBeenCalledTimes(1);
expect(mockClient.initRustCrypto).toHaveBeenCalledTimes(1);

// we should have stashed the setting in the settings store
expect(mockSetValue).toHaveBeenCalledWith("feature_rust_crypto", null, SettingLevel.DEVICE, true);
Expand Down
7 changes: 6 additions & 1 deletion test/test-utils/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,14 @@ export function createTestClient(): MatrixClient {
let txnId = 1;

const client = {
startClient: jest.fn(),
getHomeserverUrl: jest.fn(),
getIdentityServerUrl: jest.fn(),
getDomain: jest.fn().mockReturnValue("matrix.org"),
getUserId: jest.fn().mockReturnValue("@userId:matrix.org"),
getSafeUserId: jest.fn().mockReturnValue("@userId:matrix.org"),
getUserIdLocalpart: jest.fn().mockResolvedValue("userId"),
getUser: jest.fn().mockReturnValue({ on: jest.fn(), off: jest.fn() }),
getUser: jest.fn().mockReturnValue({ on: jest.fn(), off: jest.fn(), removeListener: jest.fn() }),
getDevice: jest.fn(),
getDeviceId: jest.fn().mockReturnValue("ABCDEFGHI"),
getStoredCrossSigningForUser: jest.fn(),
Expand Down Expand Up @@ -133,6 +134,8 @@ export function createTestClient(): MatrixClient {
getVerificationRequestsToDeviceInProgress: jest.fn().mockReturnValue([]),
setDeviceIsolationMode: jest.fn(),
}),
initCrypto: jest.fn(),
initRustCrypto: jest.fn(),

getPushActionsForEvent: jest.fn(),
getRoom: jest.fn().mockImplementation((roomId) => mkStubRoom(roomId, "My room", client)),
Expand Down Expand Up @@ -180,6 +183,7 @@ export function createTestClient(): MatrixClient {
getSyncState: jest.fn().mockReturnValue("SYNCING"),
generateClientSecret: () => "t35tcl1Ent5ECr3T",
isGuest: jest.fn().mockReturnValue(false),
setGuest: jest.fn(),
getRoomHierarchy: jest.fn().mockReturnValue({
rooms: [],
}),
Expand Down Expand Up @@ -277,6 +281,7 @@ export function createTestClient(): MatrixClient {
isFallbackICEServerAllowed: jest.fn().mockReturnValue(false),
getAuthIssuer: jest.fn(),
getOrCreateFilter: jest.fn(),
setNotifTimelineSet: jest.fn(),
} as unknown as MatrixClient;

client.reEmitter = new ReEmitter(client);
Expand Down
Loading