This seems to be causing a lot of weirdness, presumably because there's another missing thing like in #135, but I don't know what it might be and it feels like it might take a while to find. Backing these changes out to fix develop while we sort it out. Fixes https://github.com/element-hq/element-web/issues/28179
This commit is contained in:
parent
4e5cf1b720
commit
3a59556749
30 changed files with 78 additions and 88 deletions
|
@ -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";
|
||||
|
@ -19,14 +19,9 @@ 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(() => {
|
||||
|
@ -38,6 +33,7 @@ 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");
|
||||
|
@ -56,6 +52,7 @@ describe("MatrixClientPeg", () => {
|
|||
});
|
||||
|
||||
it("setJustRegisteredUserId(null)", () => {
|
||||
stubClient();
|
||||
(peg as any).matrixClient = peg.get();
|
||||
peg.setJustRegisteredUserId(null);
|
||||
expect(peg.currentUserIsJustRegistered()).toBe(false);
|
||||
|
@ -74,6 +71,7 @@ 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",
|
||||
|
@ -85,10 +83,13 @@ 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(mockClient.initCrypto).not.toHaveBeenCalled();
|
||||
expect(mockClient.initRustCrypto).toHaveBeenCalledWith({ storageKey: cryptoStoreKey });
|
||||
expect(mockInitCrypto).not.toHaveBeenCalled();
|
||||
expect(mockInitRustCrypto).toHaveBeenCalledWith({ storageKey: cryptoStoreKey });
|
||||
|
||||
// we should have stashed the setting in the settings store
|
||||
expect(mockSetValue).toHaveBeenCalledWith("feature_rust_crypto", null, SettingLevel.DEVICE, true);
|
||||
|
@ -96,9 +97,10 @@ describe("MatrixClientPeg", () => {
|
|||
|
||||
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(mockClient.initRustCrypto).toHaveBeenCalledTimes(1);
|
||||
expect(mockInitRustCrypto).toHaveBeenCalledTimes(1);
|
||||
|
||||
// we should have stashed the setting in the settings store
|
||||
expect(mockSetValue).toHaveBeenCalledWith("feature_rust_crypto", null, SettingLevel.DEVICE, true);
|
||||
|
|
|
@ -47,7 +47,7 @@ describe("AutoRageshakeStore", () => {
|
|||
|
||||
// @ts-ignore bypass private ctor for tests
|
||||
autoRageshakeStore = new AutoRageshakeStore();
|
||||
autoRageshakeStore.useUnitTestClient(client);
|
||||
autoRageshakeStore.start();
|
||||
|
||||
utdEvent = mkEvent({
|
||||
event: true,
|
||||
|
|
|
@ -40,7 +40,7 @@ describe("OwnProfileStore", () => {
|
|||
displayname: "Display Name",
|
||||
avatar_url: "mxc://example.com/abc123",
|
||||
});
|
||||
await ownProfileStore.useUnitTestClient(client);
|
||||
await ownProfileStore.start();
|
||||
|
||||
expect(onUpdate).toHaveBeenCalled();
|
||||
expect(ownProfileStore.displayName).toBe("Display Name");
|
||||
|
@ -54,7 +54,7 @@ describe("OwnProfileStore", () => {
|
|||
errcode: "M_NOT_FOUND",
|
||||
}),
|
||||
);
|
||||
await ownProfileStore.useUnitTestClient(client);
|
||||
await ownProfileStore.start();
|
||||
|
||||
expect(onUpdate).toHaveBeenCalled();
|
||||
expect(ownProfileStore.displayName).toBe(client.getSafeUserId());
|
||||
|
@ -69,7 +69,7 @@ describe("OwnProfileStore", () => {
|
|||
}),
|
||||
);
|
||||
try {
|
||||
await ownProfileStore.useUnitTestClient(client);
|
||||
await ownProfileStore.start();
|
||||
} catch (ignore) {}
|
||||
|
||||
expect(onUpdate).not.toHaveBeenCalled();
|
||||
|
|
|
@ -1428,7 +1428,7 @@ describe("SpaceStore", () => {
|
|||
|
||||
it("passes that value in calls to getVisibleRooms during getSpaceFilteredRoomIds", () => {
|
||||
// Given a store
|
||||
const store = SpaceStore.testInstance(client);
|
||||
const store = SpaceStore.testInstance();
|
||||
|
||||
// When we ask for filtered room ids
|
||||
store.getSpaceFilteredRoomIds(MetaSpace.Home);
|
||||
|
@ -1478,7 +1478,7 @@ describe("SpaceStore", () => {
|
|||
|
||||
it("passes that value in calls to getVisibleRooms during getSpaceFilteredRoomIds", () => {
|
||||
// Given a store
|
||||
const store = SpaceStore.testInstance(client);
|
||||
const store = SpaceStore.testInstance();
|
||||
// When we ask for filtered room ids
|
||||
store.getSpaceFilteredRoomIds(MetaSpace.Home);
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ describe("VoiceRecordingStore", () => {
|
|||
|
||||
const mkStore = (): VoiceRecordingStore => {
|
||||
const store = new VoiceRecordingStore();
|
||||
store.useUnitTestClient(stubClient);
|
||||
store.start();
|
||||
return store;
|
||||
};
|
||||
|
||||
|
|
|
@ -167,7 +167,7 @@ describe("WidgetLayoutStore", () => {
|
|||
|
||||
it("should recalculate all rooms when the client is ready", async () => {
|
||||
mocked(client.getVisibleRooms).mockReturnValue([mockRoom]);
|
||||
await store.start(client);
|
||||
await store.start();
|
||||
|
||||
expect(roomUpdateListener).toHaveBeenCalled();
|
||||
expect(store.getContainerWidgets(mockRoom, Container.Top)).toEqual([]);
|
||||
|
@ -243,7 +243,7 @@ describe("WidgetLayoutStore", () => {
|
|||
});
|
||||
|
||||
it("should copy the layout to the room", async () => {
|
||||
await store.start(client);
|
||||
await store.start();
|
||||
store.recalculateRoom(mockRoom);
|
||||
store.moveToContainer(mockRoom, mockApps[0], Container.Top);
|
||||
store.copyLayoutToRoom(mockRoom);
|
||||
|
@ -297,7 +297,7 @@ describe("WidgetLayoutStore", () => {
|
|||
mocked(client.getVisibleRooms).mockReturnValue([]);
|
||||
// @ts-ignore bypass private ctor for tests
|
||||
const store = new WidgetLayoutStore();
|
||||
await store.start(client);
|
||||
await store.start();
|
||||
expect(client.getVisibleRooms).toHaveBeenCalledWith(false);
|
||||
});
|
||||
});
|
||||
|
@ -314,7 +314,7 @@ describe("WidgetLayoutStore", () => {
|
|||
mocked(client.getVisibleRooms).mockReturnValue([]);
|
||||
// @ts-ignore bypass private ctor for tests
|
||||
const store = new WidgetLayoutStore();
|
||||
await store.start(client);
|
||||
await store.start();
|
||||
expect(client.getVisibleRooms).toHaveBeenCalledWith(true);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -80,7 +80,7 @@ describe("MessagePreviewStore", () => {
|
|||
mocked(client.getRoom).mockReturnValue(room);
|
||||
|
||||
store = MessagePreviewStore.testInstance();
|
||||
await store.useUnitTestClient(client);
|
||||
await store.start();
|
||||
await setupAsyncStoreWithClient(store, client);
|
||||
});
|
||||
|
||||
|
|
|
@ -29,9 +29,6 @@ import DMRoomMap from "../../../src/utils/DMRoomMap";
|
|||
import { flushPromises, stubClient, upsertRoomStateEvents, mkRoom } from "../../test-utils";
|
||||
import { DEFAULT_PUSH_RULES, makePushRule } from "../../test-utils/pushRules";
|
||||
|
||||
// Mock out the SpaceWatcher as it messes with the prefilterConditions
|
||||
jest.mock("../../../src/stores/room-list/SpaceWatcher.ts");
|
||||
|
||||
describe("RoomListStore", () => {
|
||||
const client = stubClient();
|
||||
const newRoomId = "!roomid:example.com";
|
||||
|
@ -94,10 +91,6 @@ describe("RoomListStore", () => {
|
|||
await (RoomListStore.instance as RoomListStoreClass).makeReady(client);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
DMRoomMap.makeShared(client);
|
||||
});
|
||||
|
||||
it.each(OrderedDefaultTagIDs)("defaults to importance ordering for %s=", (tagId) => {
|
||||
expect(RoomListStore.instance.getTagSorting(tagId)).toBe(SortAlgorithm.Recent);
|
||||
});
|
||||
|
@ -109,11 +102,11 @@ describe("RoomListStore", () => {
|
|||
function createStore(): { store: RoomListStoreClass; handleRoomUpdate: jest.Mock<any, any> } {
|
||||
const fakeDispatcher = { register: jest.fn() } as unknown as MatrixDispatcher;
|
||||
const store = new RoomListStoreClass(fakeDispatcher);
|
||||
// @ts-ignore accessing private member to set client
|
||||
store.readyStore.matrixClient = client;
|
||||
const handleRoomUpdate = jest.fn();
|
||||
// @ts-ignore accessing private member to mock it
|
||||
store.algorithm.handleRoomUpdate = handleRoomUpdate;
|
||||
// @ts-ignore accessing private member to set client
|
||||
store.readyStore.useUnitTestClient(client);
|
||||
|
||||
return { store, handleRoomUpdate };
|
||||
}
|
||||
|
@ -164,6 +157,7 @@ describe("RoomListStore", () => {
|
|||
room1.updateMyMembership(KnownMembership.Join);
|
||||
room2.updateMyMembership(KnownMembership.Join);
|
||||
room3.updateMyMembership(KnownMembership.Join);
|
||||
DMRoomMap.makeShared(client);
|
||||
const { store } = createStore();
|
||||
client.getVisibleRooms = jest.fn().mockReturnValue([room1, room2, room3]);
|
||||
|
||||
|
@ -275,6 +269,7 @@ describe("RoomListStore", () => {
|
|||
|
||||
it("Passes the feature flag on to the client when asking for visible rooms", () => {
|
||||
// Given a store that we can ask for a room list
|
||||
DMRoomMap.makeShared(client);
|
||||
const { store } = createStore();
|
||||
client.getVisibleRooms = jest.fn().mockReturnValue([]);
|
||||
|
||||
|
@ -290,7 +285,7 @@ describe("RoomListStore", () => {
|
|||
describe("room updates", () => {
|
||||
const makeStore = async () => {
|
||||
const store = new RoomListStoreClass(defaultDispatcher);
|
||||
await store.useUnitTestClient(client);
|
||||
await store.start();
|
||||
return store;
|
||||
};
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ describe("SlidingRoomListStore", () => {
|
|||
|
||||
describe("spaces", () => {
|
||||
it("alters 'filters.spaces' on the DefaultTagID.Untagged list when the selected space changes", async () => {
|
||||
await store.useUnitTestClient(context.client!); // call onReady
|
||||
await store.start(); // call onReady
|
||||
const spaceRoomId = "!foo:bar";
|
||||
|
||||
const p = untilEmission(store, LISTS_LOADING_EVENT, (listName, isLoading) => {
|
||||
|
@ -92,7 +92,7 @@ describe("SlidingRoomListStore", () => {
|
|||
},
|
||||
);
|
||||
activeSpace = MetaSpace.Home;
|
||||
await store.useUnitTestClient(context.client!); // call onReady
|
||||
await store.start(); // call onReady
|
||||
|
||||
expect(context._SlidingSyncManager!.ensureListRegistered).toHaveBeenCalledWith(DefaultTagID.Untagged, {
|
||||
filters: expect.objectContaining({
|
||||
|
@ -108,7 +108,7 @@ describe("SlidingRoomListStore", () => {
|
|||
const p = untilEmission(store, LISTS_LOADING_EVENT, (listName, isLoading) => {
|
||||
return listName === DefaultTagID.Untagged && !isLoading;
|
||||
});
|
||||
await store.useUnitTestClient(context.client!); // call onReady
|
||||
await store.start(); // call onReady
|
||||
await p;
|
||||
expect(context._SlidingSyncManager!.ensureListRegistered).toHaveBeenCalledWith(
|
||||
DefaultTagID.Untagged,
|
||||
|
@ -121,7 +121,7 @@ describe("SlidingRoomListStore", () => {
|
|||
});
|
||||
|
||||
it("includes subspaces in 'filters.spaces' when the selected space has subspaces", async () => {
|
||||
await store.useUnitTestClient(context.client!); // call onReady
|
||||
await store.start(); // call onReady
|
||||
const spaceRoomId = "!foo:bar";
|
||||
const subSpace1 = "!ss1:bar";
|
||||
const subSpace2 = "!ss2:bar";
|
||||
|
@ -168,7 +168,7 @@ describe("SlidingRoomListStore", () => {
|
|||
});
|
||||
|
||||
it("getTagsForRoom gets the tags for the room", async () => {
|
||||
await store.useUnitTestClient(context.client!);
|
||||
await store.start();
|
||||
const roomA = "!a:localhost";
|
||||
const roomB = "!b:localhost";
|
||||
const keyToListData: Record<string, { joinedCount: number; roomIndexToRoomId: Record<number, string> }> = {
|
||||
|
@ -200,7 +200,7 @@ describe("SlidingRoomListStore", () => {
|
|||
});
|
||||
|
||||
it("emits LISTS_UPDATE_EVENT when slidingSync lists update", async () => {
|
||||
await store.useUnitTestClient(context.client!);
|
||||
await store.start();
|
||||
const roomA = "!a:localhost";
|
||||
const roomB = "!b:localhost";
|
||||
const roomC = "!c:localhost";
|
||||
|
@ -236,7 +236,7 @@ describe("SlidingRoomListStore", () => {
|
|||
});
|
||||
|
||||
it("sets the sticky room on the basis of the viewed room in RoomViewStore", async () => {
|
||||
await store.useUnitTestClient(context.client!);
|
||||
await store.start();
|
||||
// seed the store with 3 rooms
|
||||
const roomIdA = "!a:localhost";
|
||||
const roomIdB = "!b:localhost";
|
||||
|
@ -301,7 +301,7 @@ describe("SlidingRoomListStore", () => {
|
|||
});
|
||||
|
||||
it("gracefully handles unknown room IDs", async () => {
|
||||
await store.useUnitTestClient(context.client!);
|
||||
await store.start();
|
||||
const roomIdA = "!a:localhost";
|
||||
const roomIdB = "!b:localhost"; // does not exist
|
||||
const roomIdC = "!c:localhost";
|
||||
|
|
|
@ -86,14 +86,13 @@ 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(), removeListener: jest.fn() }),
|
||||
getUser: jest.fn().mockReturnValue({ on: jest.fn(), off: jest.fn() }),
|
||||
getDevice: jest.fn(),
|
||||
getDeviceId: jest.fn().mockReturnValue("ABCDEFGHI"),
|
||||
getStoredCrossSigningForUser: jest.fn(),
|
||||
|
@ -134,8 +133,6 @@ 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)),
|
||||
|
@ -183,7 +180,6 @@ export function createTestClient(): MatrixClient {
|
|||
getSyncState: jest.fn().mockReturnValue("SYNCING"),
|
||||
generateClientSecret: () => "t35tcl1Ent5ECr3T",
|
||||
isGuest: jest.fn().mockReturnValue(false),
|
||||
setGuest: jest.fn(),
|
||||
getRoomHierarchy: jest.fn().mockReturnValue({
|
||||
rooms: [],
|
||||
}),
|
||||
|
@ -281,7 +277,6 @@ 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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue