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

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy committed Jul 28, 2023
1 parent 7a5ea86 commit 4456bdc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/stores/spaces/SpaceStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
const lists = RoomListStore.instance.orderedLists;
tagLoop: for (let i = 0; i < TAG_ORDER.length; i++) {
const t = TAG_ORDER[i];
if (!lists[t]) continue;
for (const room of lists[t]) {
const state = RoomNotificationStateStore.instance.getRoomState(room);
if (hasMentions ? state.hasMentions : state.isUnread) {
Expand Down
31 changes: 30 additions & 1 deletion test/stores/SpaceStore-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { EventType } from "matrix-js-sdk/src/@types/event";
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, Room } from "matrix-js-sdk/src/matrix";
import { ClientEvent, MatrixEvent, Room, RoomEvent } from "matrix-js-sdk/src/matrix";

import SpaceStore from "../../src/stores/spaces/SpaceStore";
import {
Expand All @@ -38,6 +38,10 @@ import SettingsStore from "../../src/settings/SettingsStore";
import { SettingLevel } from "../../src/settings/SettingLevel";
import { Action } from "../../src/dispatcher/actions";
import { MatrixClientPeg } from "../../src/MatrixClientPeg";
import RoomListStore from "../../src/stores/room-list/RoomListStore";
import { DefaultTagID } from "../../src/stores/room-list/models";
import { RoomNotificationStateStore } from "../../src/stores/notifications/RoomNotificationStateStore";
import { NotificationColor } from "../../src/stores/notifications/NotificationColor";

jest.useFakeTimers();

Expand Down Expand Up @@ -1452,4 +1456,29 @@ describe("SpaceStore", () => {
expect(client.getVisibleRooms).not.toHaveBeenCalledWith();
});
});

describe("setActiveRoomInSpace", () => {
it("should work with Home as all rooms space", async () => {
const room = mkRoom(room1);
const state = RoomNotificationStateStore.instance.getRoomState(room);
// @ts-ignore
state._color = NotificationColor.Grey;
jest.spyOn(RoomListStore.instance, "orderedLists", "get").mockReturnValue({
[DefaultTagID.Untagged]: [room],
});

// init the store
await run();
await setShowAllRooms(true);

store.setActiveRoomInSpace(MetaSpace.Home);

expect(spyDispatcher).toHaveBeenCalledWith(
expect.objectContaining({
action: "view_room",
room_id: room.roomId,
}),
);
});
});
});

0 comments on commit 4456bdc

Please sign in to comment.