From a3aab294bd82ab31a9bcf912f3ccb5b09ec40eae Mon Sep 17 00:00:00 2001 From: Janne Mareike Koschinski Date: Wed, 18 May 2022 12:20:13 +0200 Subject: [PATCH] test: verify we actually send events for enabledMetaSpaces --- test/stores/SpaceStore-test.ts | 41 ++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/test/stores/SpaceStore-test.ts b/test/stores/SpaceStore-test.ts index 47c3f974b232..b8f54d238227 100644 --- a/test/stores/SpaceStore-test.ts +++ b/test/stores/SpaceStore-test.ts @@ -14,14 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. */ +import { EventEmitter } from "events"; import { mocked } from 'jest-mock'; import { EventType } from "matrix-js-sdk/src/@types/event"; +import { ClientEvent, MatrixEvent, RoomEvent } from 'matrix-js-sdk/src/matrix'; import { RoomMember } from "matrix-js-sdk/src/models/room-member"; import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state"; import { defer } from "matrix-js-sdk/src/utils"; -import { ClientEvent, RoomEvent, MatrixEvent } from 'matrix-js-sdk/src/matrix'; - -import SpaceStore from "../../src/stores/spaces/SpaceStore"; +import { Action } from "../../src/dispatcher/actions"; +import defaultDispatcher from "../../src/dispatcher/dispatcher"; +import { MatrixClientPeg } from "../../src/MatrixClientPeg"; +import { SettingLevel } from "../../src/settings/SettingLevel"; +import SettingsStore from "../../src/settings/SettingsStore"; import { MetaSpace, UPDATE_HOME_BEHAVIOUR, @@ -29,14 +33,11 @@ import { UPDATE_SELECTED_SPACE, UPDATE_TOP_LEVEL_SPACES, } from "../../src/stores/spaces"; + +import SpaceStore from "../../src/stores/spaces/SpaceStore"; +import DMRoomMap from "../../src/utils/DMRoomMap"; import * as testUtils from "../test-utils"; import { mkEvent, stubClient } from "../test-utils"; -import DMRoomMap from "../../src/utils/DMRoomMap"; -import defaultDispatcher from "../../src/dispatcher/dispatcher"; -import SettingsStore from "../../src/settings/SettingsStore"; -import { SettingLevel } from "../../src/settings/SettingLevel"; -import { Action } from "../../src/dispatcher/actions"; -import { MatrixClientPeg } from "../../src/MatrixClientPeg"; jest.useFakeTimers(); @@ -1221,4 +1222,26 @@ describe("SpaceStore", () => { expect(SpaceStore.instance.spacePanelSpaces.map(r => r.roomId)).toStrictEqual([rootSpace.roomId]); await prom; }); + + it("correctly emits events for metaspace changes during onReady", async () => { + // similar to useEventEmitterState, but for use inside of tests + function testEventEmitterState( + emitter: EventEmitter | undefined, + eventName: string | symbol, + callback: (...args: any[]) => void, + ): () => void { + callback(); + emitter.addListener(eventName, callback); + return () => emitter.removeListener(eventName, callback); + } + + let metaSpaces; + const removeListener = testEventEmitterState(store, UPDATE_TOP_LEVEL_SPACES, () => { + metaSpaces = store.enabledMetaSpaces; + }); + expect(metaSpaces).toEqual(store.enabledMetaSpaces); + await run(); + expect(metaSpaces).toEqual(store.enabledMetaSpaces); + removeListener(); + }); });