Refactor stores and their relationship to the MatrixClientPeg (#124)
* Refactor stores and their relationship to the MatrixClientPeg to avoid import cycles and webpack weirdness Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
31bd10e887
commit
197168b3ba
28 changed files with 71 additions and 66 deletions
|
@ -29,6 +29,9 @@ 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";
|
||||
|
@ -91,6 +94,10 @@ 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);
|
||||
});
|
||||
|
@ -102,11 +109,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 };
|
||||
}
|
||||
|
@ -157,7 +164,6 @@ 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]);
|
||||
|
||||
|
@ -269,7 +275,6 @@ 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([]);
|
||||
|
||||
|
@ -285,7 +290,7 @@ describe("RoomListStore", () => {
|
|||
describe("room updates", () => {
|
||||
const makeStore = async () => {
|
||||
const store = new RoomListStoreClass(defaultDispatcher);
|
||||
await store.start();
|
||||
await store.useUnitTestClient(client);
|
||||
return store;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue