mirror of https://github.com/vector-im/riot-web
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 eitherpull/28192/head
parent
a2cee6bbb4
commit
5f113c4db0
|
@ -29,6 +29,8 @@ export abstract class ReadyWatchingStore extends EventEmitter implements IDestro
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.dispatcherRef = this.dispatcher.register(this.onAction);
|
this.dispatcherRef = this.dispatcher.register(this.onAction);
|
||||||
|
|
||||||
|
ReadyWatchingStore.instances.push(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public get matrixClient(): MatrixClient | null {
|
public get matrixClient(): MatrixClient | null {
|
||||||
|
|
|
@ -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.
|
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 { logger } from "matrix-js-sdk/src/logger";
|
||||||
import fetchMockJest from "fetch-mock-jest";
|
|
||||||
|
|
||||||
import { advanceDateAndTime, stubClient } from "./test-utils";
|
import { advanceDateAndTime, stubClient } from "./test-utils";
|
||||||
import { IMatrixClientPeg, MatrixClientPeg as peg } from "../src/MatrixClientPeg";
|
import { IMatrixClientPeg, MatrixClientPeg as peg } from "../src/MatrixClientPeg";
|
||||||
|
@ -19,9 +19,14 @@ jest.useFakeTimers();
|
||||||
const PegClass = Object.getPrototypeOf(peg).constructor;
|
const PegClass = Object.getPrototypeOf(peg).constructor;
|
||||||
|
|
||||||
describe("MatrixClientPeg", () => {
|
describe("MatrixClientPeg", () => {
|
||||||
|
let mockClient: MatrixJs.MatrixClient;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// stub out Logger.log which gets called a lot and clutters up the test output
|
// stub out Logger.log which gets called a lot and clutters up the test output
|
||||||
jest.spyOn(logger, "log").mockImplementation(() => {});
|
jest.spyOn(logger, "log").mockImplementation(() => {});
|
||||||
|
|
||||||
|
mockClient = stubClient();
|
||||||
|
jest.spyOn(MatrixJs, "createClient").mockReturnValue(mockClient);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
@ -33,7 +38,6 @@ describe("MatrixClientPeg", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("setJustRegisteredUserId", () => {
|
it("setJustRegisteredUserId", () => {
|
||||||
stubClient();
|
|
||||||
(peg as any).matrixClient = peg.get();
|
(peg as any).matrixClient = peg.get();
|
||||||
peg.setJustRegisteredUserId("@userId:matrix.org");
|
peg.setJustRegisteredUserId("@userId:matrix.org");
|
||||||
expect(peg.safeGet().credentials.userId).toBe("@userId:matrix.org");
|
expect(peg.safeGet().credentials.userId).toBe("@userId:matrix.org");
|
||||||
|
@ -52,7 +56,6 @@ describe("MatrixClientPeg", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("setJustRegisteredUserId(null)", () => {
|
it("setJustRegisteredUserId(null)", () => {
|
||||||
stubClient();
|
|
||||||
(peg as any).matrixClient = peg.get();
|
(peg as any).matrixClient = peg.get();
|
||||||
peg.setJustRegisteredUserId(null);
|
peg.setJustRegisteredUserId(null);
|
||||||
expect(peg.currentUserIsJustRegistered()).toBe(false);
|
expect(peg.currentUserIsJustRegistered()).toBe(false);
|
||||||
|
@ -71,7 +74,6 @@ describe("MatrixClientPeg", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// instantiate a MatrixClientPegClass instance, with a new MatrixClient
|
// instantiate a MatrixClientPegClass instance, with a new MatrixClient
|
||||||
testPeg = new PegClass();
|
testPeg = new PegClass();
|
||||||
fetchMockJest.get("http://example.com/_matrix/client/versions", {});
|
|
||||||
testPeg.replaceUsingCreds({
|
testPeg.replaceUsingCreds({
|
||||||
accessToken: "SEKRET",
|
accessToken: "SEKRET",
|
||||||
homeserverUrl: "http://example.com",
|
homeserverUrl: "http://example.com",
|
||||||
|
@ -83,13 +85,10 @@ describe("MatrixClientPeg", () => {
|
||||||
it("should initialise the rust crypto library by default", async () => {
|
it("should initialise the rust crypto library by default", async () => {
|
||||||
const mockSetValue = jest.spyOn(SettingsStore, "setValue").mockResolvedValue(undefined);
|
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]);
|
const cryptoStoreKey = new Uint8Array([1, 2, 3, 4]);
|
||||||
await testPeg.start({ rustCryptoStoreKey: cryptoStoreKey });
|
await testPeg.start({ rustCryptoStoreKey: cryptoStoreKey });
|
||||||
expect(mockInitCrypto).not.toHaveBeenCalled();
|
expect(mockClient.initCrypto).not.toHaveBeenCalled();
|
||||||
expect(mockInitRustCrypto).toHaveBeenCalledWith({ storageKey: cryptoStoreKey });
|
expect(mockClient.initRustCrypto).toHaveBeenCalledWith({ storageKey: cryptoStoreKey });
|
||||||
|
|
||||||
// we should have stashed the setting in the settings store
|
// we should have stashed the setting in the settings store
|
||||||
expect(mockSetValue).toHaveBeenCalledWith("feature_rust_crypto", null, SettingLevel.DEVICE, true);
|
expect(mockSetValue).toHaveBeenCalledWith("feature_rust_crypto", null, SettingLevel.DEVICE, true);
|
||||||
|
@ -97,10 +96,9 @@ describe("MatrixClientPeg", () => {
|
||||||
|
|
||||||
it("Should migrate existing login", async () => {
|
it("Should migrate existing login", async () => {
|
||||||
const mockSetValue = jest.spyOn(SettingsStore, "setValue").mockResolvedValue(undefined);
|
const mockSetValue = jest.spyOn(SettingsStore, "setValue").mockResolvedValue(undefined);
|
||||||
const mockInitRustCrypto = jest.spyOn(testPeg.safeGet(), "initRustCrypto").mockResolvedValue(undefined);
|
|
||||||
|
|
||||||
await testPeg.start();
|
await testPeg.start();
|
||||||
expect(mockInitRustCrypto).toHaveBeenCalledTimes(1);
|
expect(mockClient.initRustCrypto).toHaveBeenCalledTimes(1);
|
||||||
|
|
||||||
// we should have stashed the setting in the settings store
|
// we should have stashed the setting in the settings store
|
||||||
expect(mockSetValue).toHaveBeenCalledWith("feature_rust_crypto", null, SettingLevel.DEVICE, true);
|
expect(mockSetValue).toHaveBeenCalledWith("feature_rust_crypto", null, SettingLevel.DEVICE, true);
|
||||||
|
|
|
@ -86,13 +86,14 @@ export function createTestClient(): MatrixClient {
|
||||||
let txnId = 1;
|
let txnId = 1;
|
||||||
|
|
||||||
const client = {
|
const client = {
|
||||||
|
startClient: jest.fn(),
|
||||||
getHomeserverUrl: jest.fn(),
|
getHomeserverUrl: jest.fn(),
|
||||||
getIdentityServerUrl: jest.fn(),
|
getIdentityServerUrl: jest.fn(),
|
||||||
getDomain: jest.fn().mockReturnValue("matrix.org"),
|
getDomain: jest.fn().mockReturnValue("matrix.org"),
|
||||||
getUserId: jest.fn().mockReturnValue("@userId:matrix.org"),
|
getUserId: jest.fn().mockReturnValue("@userId:matrix.org"),
|
||||||
getSafeUserId: jest.fn().mockReturnValue("@userId:matrix.org"),
|
getSafeUserId: jest.fn().mockReturnValue("@userId:matrix.org"),
|
||||||
getUserIdLocalpart: jest.fn().mockResolvedValue("userId"),
|
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(),
|
getDevice: jest.fn(),
|
||||||
getDeviceId: jest.fn().mockReturnValue("ABCDEFGHI"),
|
getDeviceId: jest.fn().mockReturnValue("ABCDEFGHI"),
|
||||||
getStoredCrossSigningForUser: jest.fn(),
|
getStoredCrossSigningForUser: jest.fn(),
|
||||||
|
@ -133,6 +134,8 @@ export function createTestClient(): MatrixClient {
|
||||||
getVerificationRequestsToDeviceInProgress: jest.fn().mockReturnValue([]),
|
getVerificationRequestsToDeviceInProgress: jest.fn().mockReturnValue([]),
|
||||||
setDeviceIsolationMode: jest.fn(),
|
setDeviceIsolationMode: jest.fn(),
|
||||||
}),
|
}),
|
||||||
|
initCrypto: jest.fn(),
|
||||||
|
initRustCrypto: jest.fn(),
|
||||||
|
|
||||||
getPushActionsForEvent: jest.fn(),
|
getPushActionsForEvent: jest.fn(),
|
||||||
getRoom: jest.fn().mockImplementation((roomId) => mkStubRoom(roomId, "My room", client)),
|
getRoom: jest.fn().mockImplementation((roomId) => mkStubRoom(roomId, "My room", client)),
|
||||||
|
@ -180,6 +183,7 @@ export function createTestClient(): MatrixClient {
|
||||||
getSyncState: jest.fn().mockReturnValue("SYNCING"),
|
getSyncState: jest.fn().mockReturnValue("SYNCING"),
|
||||||
generateClientSecret: () => "t35tcl1Ent5ECr3T",
|
generateClientSecret: () => "t35tcl1Ent5ECr3T",
|
||||||
isGuest: jest.fn().mockReturnValue(false),
|
isGuest: jest.fn().mockReturnValue(false),
|
||||||
|
setGuest: jest.fn(),
|
||||||
getRoomHierarchy: jest.fn().mockReturnValue({
|
getRoomHierarchy: jest.fn().mockReturnValue({
|
||||||
rooms: [],
|
rooms: [],
|
||||||
}),
|
}),
|
||||||
|
@ -277,6 +281,7 @@ export function createTestClient(): MatrixClient {
|
||||||
isFallbackICEServerAllowed: jest.fn().mockReturnValue(false),
|
isFallbackICEServerAllowed: jest.fn().mockReturnValue(false),
|
||||||
getAuthIssuer: jest.fn(),
|
getAuthIssuer: jest.fn(),
|
||||||
getOrCreateFilter: jest.fn(),
|
getOrCreateFilter: jest.fn(),
|
||||||
|
setNotifTimelineSet: jest.fn(),
|
||||||
} as unknown as MatrixClient;
|
} as unknown as MatrixClient;
|
||||||
|
|
||||||
client.reEmitter = new ReEmitter(client);
|
client.reEmitter = new ReEmitter(client);
|
||||||
|
|
Loading…
Reference in New Issue