Apply prettier formatting
This commit is contained in:
parent
1cac306093
commit
526645c791
1576 changed files with 65385 additions and 62478 deletions
|
@ -123,9 +123,12 @@ describe("MemberListStore", () => {
|
|||
addMember(room, doris, "join", "AAAAA");
|
||||
({ invited, joined } = await store.loadMemberList(roomId));
|
||||
expect(invited).toEqual([]);
|
||||
expect(joined).toEqual(
|
||||
[room.getMember(doris), room.getMember(alice), room.getMember(bob), room.getMember(charlie)],
|
||||
);
|
||||
expect(joined).toEqual([
|
||||
room.getMember(doris),
|
||||
room.getMember(alice),
|
||||
room.getMember(bob),
|
||||
room.getMember(charlie),
|
||||
]);
|
||||
});
|
||||
|
||||
it("filters based on a search query", async () => {
|
||||
|
@ -164,7 +167,7 @@ describe("MemberListStore", () => {
|
|||
|
||||
describe("sliding sync", () => {
|
||||
beforeEach(() => {
|
||||
jest.spyOn(SettingsStore, 'getValue').mockImplementation((settingName, roomId, value) => {
|
||||
jest.spyOn(SettingsStore, "getValue").mockImplementation((settingName, roomId, value) => {
|
||||
return settingName === "feature_sliding_sync"; // this is enabled, everything else is disabled.
|
||||
});
|
||||
client.members = jest.fn();
|
||||
|
@ -210,26 +213,32 @@ function addEventToRoom(room: Room, ev: MatrixEvent) {
|
|||
}
|
||||
|
||||
function setPowerLevels(room: Room, pl: IContent) {
|
||||
addEventToRoom(room, new MatrixEvent({
|
||||
type: EventType.RoomPowerLevels,
|
||||
state_key: "",
|
||||
content: pl,
|
||||
sender: room.getCreator()!,
|
||||
room_id: room.roomId,
|
||||
event_id: "$" + Math.random(),
|
||||
}));
|
||||
addEventToRoom(
|
||||
room,
|
||||
new MatrixEvent({
|
||||
type: EventType.RoomPowerLevels,
|
||||
state_key: "",
|
||||
content: pl,
|
||||
sender: room.getCreator()!,
|
||||
room_id: room.roomId,
|
||||
event_id: "$" + Math.random(),
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
function addMember(room: Room, userId: string, membership: string, displayName?: string) {
|
||||
addEventToRoom(room, new MatrixEvent({
|
||||
type: EventType.RoomMember,
|
||||
state_key: userId,
|
||||
content: {
|
||||
membership: membership,
|
||||
displayname: displayName,
|
||||
},
|
||||
sender: userId,
|
||||
room_id: room.roomId,
|
||||
event_id: "$" + Math.random(),
|
||||
}));
|
||||
addEventToRoom(
|
||||
room,
|
||||
new MatrixEvent({
|
||||
type: EventType.RoomMember,
|
||||
state_key: userId,
|
||||
content: {
|
||||
membership: membership,
|
||||
displayname: displayName,
|
||||
},
|
||||
sender: userId,
|
||||
room_id: room.roomId,
|
||||
event_id: "$" + Math.random(),
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -14,30 +14,30 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { Room } from 'matrix-js-sdk/src/matrix';
|
||||
import { Room } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { RoomViewStore } from '../../src/stores/RoomViewStore';
|
||||
import { Action } from '../../src/dispatcher/actions';
|
||||
import { getMockClientWithEventEmitter, untilDispatch, untilEmission } from '../test-utils';
|
||||
import SettingsStore from '../../src/settings/SettingsStore';
|
||||
import { SlidingSyncManager } from '../../src/SlidingSyncManager';
|
||||
import { PosthogAnalytics } from '../../src/PosthogAnalytics';
|
||||
import { TimelineRenderingType } from '../../src/contexts/RoomContext';
|
||||
import { MatrixDispatcher } from '../../src/dispatcher/dispatcher';
|
||||
import { UPDATE_EVENT } from '../../src/stores/AsyncStore';
|
||||
import { ActiveRoomChangedPayload } from '../../src/dispatcher/payloads/ActiveRoomChangedPayload';
|
||||
import { SpaceStoreClass } from '../../src/stores/spaces/SpaceStore';
|
||||
import { TestSdkContext } from '../TestSdkContext';
|
||||
import { RoomViewStore } from "../../src/stores/RoomViewStore";
|
||||
import { Action } from "../../src/dispatcher/actions";
|
||||
import { getMockClientWithEventEmitter, untilDispatch, untilEmission } from "../test-utils";
|
||||
import SettingsStore from "../../src/settings/SettingsStore";
|
||||
import { SlidingSyncManager } from "../../src/SlidingSyncManager";
|
||||
import { PosthogAnalytics } from "../../src/PosthogAnalytics";
|
||||
import { TimelineRenderingType } from "../../src/contexts/RoomContext";
|
||||
import { MatrixDispatcher } from "../../src/dispatcher/dispatcher";
|
||||
import { UPDATE_EVENT } from "../../src/stores/AsyncStore";
|
||||
import { ActiveRoomChangedPayload } from "../../src/dispatcher/payloads/ActiveRoomChangedPayload";
|
||||
import { SpaceStoreClass } from "../../src/stores/spaces/SpaceStore";
|
||||
import { TestSdkContext } from "../TestSdkContext";
|
||||
|
||||
// mock out the injected classes
|
||||
jest.mock('../../src/PosthogAnalytics');
|
||||
const MockPosthogAnalytics = <jest.Mock<PosthogAnalytics>><unknown>PosthogAnalytics;
|
||||
jest.mock('../../src/SlidingSyncManager');
|
||||
const MockSlidingSyncManager = <jest.Mock<SlidingSyncManager>><unknown>SlidingSyncManager;
|
||||
jest.mock('../../src/stores/spaces/SpaceStore');
|
||||
const MockSpaceStore = <jest.Mock<SpaceStoreClass>><unknown>SpaceStoreClass;
|
||||
jest.mock("../../src/PosthogAnalytics");
|
||||
const MockPosthogAnalytics = <jest.Mock<PosthogAnalytics>>(<unknown>PosthogAnalytics);
|
||||
jest.mock("../../src/SlidingSyncManager");
|
||||
const MockSlidingSyncManager = <jest.Mock<SlidingSyncManager>>(<unknown>SlidingSyncManager);
|
||||
jest.mock("../../src/stores/spaces/SpaceStore");
|
||||
const MockSpaceStore = <jest.Mock<SpaceStoreClass>>(<unknown>SpaceStoreClass);
|
||||
|
||||
jest.mock('../../src/utils/DMRoomMap', () => {
|
||||
jest.mock("../../src/utils/DMRoomMap", () => {
|
||||
const mock = {
|
||||
getUserIdForRoomId: jest.fn(),
|
||||
getDMRoomsForUserId: jest.fn(),
|
||||
|
@ -49,8 +49,8 @@ jest.mock('../../src/utils/DMRoomMap', () => {
|
|||
};
|
||||
});
|
||||
|
||||
describe('RoomViewStore', function() {
|
||||
const userId = '@alice:server';
|
||||
describe("RoomViewStore", function () {
|
||||
const userId = "@alice:server";
|
||||
const roomId = "!randomcharacters:aser.ver";
|
||||
// we need to change the alias to ensure cache misses as the cache exists
|
||||
// through all tests.
|
||||
|
@ -67,7 +67,7 @@ describe('RoomViewStore', function() {
|
|||
let slidingSyncManager: SlidingSyncManager;
|
||||
let dis: MatrixDispatcher;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
jest.clearAllMocks();
|
||||
mockClient.credentials = { userId: userId };
|
||||
mockClient.joinRoom.mockResolvedValue(room);
|
||||
|
@ -81,13 +81,11 @@ describe('RoomViewStore', function() {
|
|||
stores._SlidingSyncManager = slidingSyncManager;
|
||||
stores._PosthogAnalytics = new MockPosthogAnalytics();
|
||||
stores._SpaceStore = new MockSpaceStore();
|
||||
roomViewStore = new RoomViewStore(
|
||||
dis, stores,
|
||||
);
|
||||
roomViewStore = new RoomViewStore(dis, stores);
|
||||
stores._RoomViewStore = roomViewStore;
|
||||
});
|
||||
|
||||
it('can be used to view a room by ID and join', async () => {
|
||||
it("can be used to view a room by ID and join", async () => {
|
||||
dis.dispatch({ action: Action.ViewRoom, room_id: roomId });
|
||||
dis.dispatch({ action: Action.JoinRoom });
|
||||
await untilDispatch(Action.JoinRoomReady, dis);
|
||||
|
@ -95,44 +93,45 @@ describe('RoomViewStore', function() {
|
|||
expect(roomViewStore.isJoining()).toBe(true);
|
||||
});
|
||||
|
||||
it('can auto-join a room', async () => {
|
||||
it("can auto-join a room", async () => {
|
||||
dis.dispatch({ action: Action.ViewRoom, room_id: roomId, auto_join: true });
|
||||
await untilDispatch(Action.JoinRoomReady, dis);
|
||||
expect(mockClient.joinRoom).toHaveBeenCalledWith(roomId, { viaServers: [] });
|
||||
expect(roomViewStore.isJoining()).toBe(true);
|
||||
});
|
||||
|
||||
it('emits ActiveRoomChanged when the viewed room changes', async () => {
|
||||
it("emits ActiveRoomChanged when the viewed room changes", async () => {
|
||||
const roomId2 = "!roomid:2";
|
||||
dis.dispatch({ action: Action.ViewRoom, room_id: roomId });
|
||||
let payload = await untilDispatch(Action.ActiveRoomChanged, dis) as ActiveRoomChangedPayload;
|
||||
let payload = (await untilDispatch(Action.ActiveRoomChanged, dis)) as ActiveRoomChangedPayload;
|
||||
expect(payload.newRoomId).toEqual(roomId);
|
||||
expect(payload.oldRoomId).toEqual(null);
|
||||
|
||||
dis.dispatch({ action: Action.ViewRoom, room_id: roomId2 });
|
||||
payload = await untilDispatch(Action.ActiveRoomChanged, dis) as ActiveRoomChangedPayload;
|
||||
payload = (await untilDispatch(Action.ActiveRoomChanged, dis)) as ActiveRoomChangedPayload;
|
||||
expect(payload.newRoomId).toEqual(roomId2);
|
||||
expect(payload.oldRoomId).toEqual(roomId);
|
||||
});
|
||||
|
||||
it('invokes room activity listeners when the viewed room changes', async () => {
|
||||
it("invokes room activity listeners when the viewed room changes", async () => {
|
||||
const roomId2 = "!roomid:2";
|
||||
const callback = jest.fn();
|
||||
roomViewStore.addRoomListener(roomId, callback);
|
||||
dis.dispatch({ action: Action.ViewRoom, room_id: roomId });
|
||||
await untilDispatch(Action.ActiveRoomChanged, dis) as ActiveRoomChangedPayload;
|
||||
(await untilDispatch(Action.ActiveRoomChanged, dis)) as ActiveRoomChangedPayload;
|
||||
expect(callback).toHaveBeenCalledWith(true);
|
||||
expect(callback).not.toHaveBeenCalledWith(false);
|
||||
|
||||
dis.dispatch({ action: Action.ViewRoom, room_id: roomId2 });
|
||||
await untilDispatch(Action.ActiveRoomChanged, dis) as ActiveRoomChangedPayload;
|
||||
(await untilDispatch(Action.ActiveRoomChanged, dis)) as ActiveRoomChangedPayload;
|
||||
expect(callback).toHaveBeenCalledWith(false);
|
||||
});
|
||||
|
||||
it('can be used to view a room by alias and join', async () => {
|
||||
it("can be used to view a room by alias and join", async () => {
|
||||
mockClient.getRoomIdForAlias.mockResolvedValue({ room_id: roomId, servers: [] });
|
||||
dis.dispatch({ action: Action.ViewRoom, room_alias: alias });
|
||||
await untilDispatch((p) => { // wait for the re-dispatch with the room ID
|
||||
await untilDispatch((p) => {
|
||||
// wait for the re-dispatch with the room ID
|
||||
return p.action === Action.ViewRoom && p.room_id === roomId;
|
||||
}, dis);
|
||||
|
||||
|
@ -148,7 +147,7 @@ describe('RoomViewStore', function() {
|
|||
expect(mockClient.joinRoom).toHaveBeenCalledWith(alias, { viaServers: [] });
|
||||
});
|
||||
|
||||
it('emits ViewRoomError if the alias lookup fails', async () => {
|
||||
it("emits ViewRoomError if the alias lookup fails", async () => {
|
||||
alias = "#something-different:to-ensure-cache-miss";
|
||||
mockClient.getRoomIdForAlias.mockRejectedValue(new Error("network error or something"));
|
||||
dis.dispatch({ action: Action.ViewRoom, room_alias: alias });
|
||||
|
@ -158,7 +157,7 @@ describe('RoomViewStore', function() {
|
|||
expect(roomViewStore.getRoomAlias()).toEqual(alias);
|
||||
});
|
||||
|
||||
it('emits JoinRoomError if joining the room fails', async () => {
|
||||
it("emits JoinRoomError if joining the room fails", async () => {
|
||||
const joinErr = new Error("network error or something");
|
||||
mockClient.joinRoom.mockRejectedValue(joinErr);
|
||||
dis.dispatch({ action: Action.ViewRoom, room_id: roomId });
|
||||
|
@ -168,13 +167,13 @@ describe('RoomViewStore', function() {
|
|||
expect(roomViewStore.getJoinError()).toEqual(joinErr);
|
||||
});
|
||||
|
||||
it('remembers the event being replied to when swapping rooms', async () => {
|
||||
it("remembers the event being replied to when swapping rooms", async () => {
|
||||
dis.dispatch({ action: Action.ViewRoom, room_id: roomId });
|
||||
await untilDispatch(Action.ActiveRoomChanged, dis);
|
||||
const replyToEvent = {
|
||||
getRoomId: () => roomId,
|
||||
};
|
||||
dis.dispatch({ action: 'reply_to_event', event: replyToEvent, context: TimelineRenderingType.Room });
|
||||
dis.dispatch({ action: "reply_to_event", event: replyToEvent, context: TimelineRenderingType.Room });
|
||||
await untilEmission(roomViewStore, UPDATE_EVENT);
|
||||
expect(roomViewStore.getQuotingEvent()).toEqual(replyToEvent);
|
||||
// view the same room, should remember the event.
|
||||
|
@ -184,20 +183,20 @@ describe('RoomViewStore', function() {
|
|||
expect(roomViewStore.getQuotingEvent()).toEqual(replyToEvent);
|
||||
});
|
||||
|
||||
it('swaps to the replied event room if it is not the current room', async () => {
|
||||
it("swaps to the replied event room if it is not the current room", async () => {
|
||||
const roomId2 = "!room2:bar";
|
||||
dis.dispatch({ action: Action.ViewRoom, room_id: roomId });
|
||||
await untilDispatch(Action.ActiveRoomChanged, dis);
|
||||
const replyToEvent = {
|
||||
getRoomId: () => roomId2,
|
||||
};
|
||||
dis.dispatch({ action: 'reply_to_event', event: replyToEvent, context: TimelineRenderingType.Room });
|
||||
dis.dispatch({ action: "reply_to_event", event: replyToEvent, context: TimelineRenderingType.Room });
|
||||
await untilDispatch(Action.ViewRoom, dis);
|
||||
expect(roomViewStore.getQuotingEvent()).toEqual(replyToEvent);
|
||||
expect(roomViewStore.getRoomId()).toEqual(roomId2);
|
||||
});
|
||||
|
||||
it('removes the roomId on ViewHomePage', async () => {
|
||||
it("removes the roomId on ViewHomePage", async () => {
|
||||
dis.dispatch({ action: Action.ViewRoom, room_id: roomId });
|
||||
await untilDispatch(Action.ActiveRoomChanged, dis);
|
||||
expect(roomViewStore.getRoomId()).toEqual(roomId);
|
||||
|
@ -207,17 +206,17 @@ describe('RoomViewStore', function() {
|
|||
expect(roomViewStore.getRoomId()).toBeNull();
|
||||
});
|
||||
|
||||
describe('Sliding Sync', function() {
|
||||
describe("Sliding Sync", function () {
|
||||
beforeEach(() => {
|
||||
jest.spyOn(SettingsStore, 'getValue').mockImplementation((settingName, roomId, value) => {
|
||||
jest.spyOn(SettingsStore, "getValue").mockImplementation((settingName, roomId, value) => {
|
||||
return settingName === "feature_sliding_sync"; // this is enabled, everything else is disabled.
|
||||
});
|
||||
});
|
||||
|
||||
it("subscribes to the room", async () => {
|
||||
const setRoomVisible = jest.spyOn(slidingSyncManager, "setRoomVisible").mockReturnValue(
|
||||
Promise.resolve(""),
|
||||
);
|
||||
const setRoomVisible = jest
|
||||
.spyOn(slidingSyncManager, "setRoomVisible")
|
||||
.mockReturnValue(Promise.resolve(""));
|
||||
const subscribedRoomId = "!sub1:localhost";
|
||||
dis.dispatch({ action: Action.ViewRoom, room_id: subscribedRoomId });
|
||||
await untilDispatch(Action.ActiveRoomChanged, dis);
|
||||
|
@ -227,9 +226,9 @@ describe('RoomViewStore', function() {
|
|||
|
||||
// Regression test for an in-the-wild bug where rooms would rapidly switch forever in sliding sync mode
|
||||
it("doesn't get stuck in a loop if you view rooms quickly", async () => {
|
||||
const setRoomVisible = jest.spyOn(slidingSyncManager, "setRoomVisible").mockReturnValue(
|
||||
Promise.resolve(""),
|
||||
);
|
||||
const setRoomVisible = jest
|
||||
.spyOn(slidingSyncManager, "setRoomVisible")
|
||||
.mockReturnValue(Promise.resolve(""));
|
||||
const subscribedRoomId = "!sub1:localhost";
|
||||
const subscribedRoomId2 = "!sub2:localhost";
|
||||
dis.dispatch({ action: Action.ViewRoom, room_id: subscribedRoomId }, true);
|
||||
|
|
|
@ -15,12 +15,12 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import { EventEmitter } from "events";
|
||||
import { mocked } from 'jest-mock';
|
||||
import { mocked } from "jest-mock";
|
||||
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 } from 'matrix-js-sdk/src/matrix';
|
||||
import { ClientEvent, RoomEvent, MatrixEvent } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import SpaceStore from "../../src/stores/spaces/SpaceStore";
|
||||
import {
|
||||
|
@ -68,14 +68,14 @@ const space2 = "!space2:server";
|
|||
const space3 = "!space3:server";
|
||||
const space4 = "!space4:server";
|
||||
|
||||
const getUserIdForRoomId = jest.fn(roomId => {
|
||||
const getUserIdForRoomId = jest.fn((roomId) => {
|
||||
return {
|
||||
[dm1]: dm1Partner.userId,
|
||||
[dm2]: dm2Partner.userId,
|
||||
[dm3]: dm3Partner.userId,
|
||||
}[roomId];
|
||||
});
|
||||
const getDMRoomsForUserId = jest.fn(userId => {
|
||||
const getDMRoomsForUserId = jest.fn((userId) => {
|
||||
switch (userId) {
|
||||
case dm1Partner.userId:
|
||||
return [dm1];
|
||||
|
@ -100,11 +100,13 @@ describe("SpaceStore", () => {
|
|||
let rooms = [];
|
||||
const mkRoom = (roomId: string) => testUtils.mkRoom(client, roomId, rooms);
|
||||
const mkSpace = (spaceId: string, children: string[] = []) => testUtils.mkSpace(client, spaceId, rooms, children);
|
||||
const viewRoom = roomId => defaultDispatcher.dispatch({ action: Action.ViewRoom, room_id: roomId }, true);
|
||||
const viewRoom = (roomId) => defaultDispatcher.dispatch({ action: Action.ViewRoom, room_id: roomId }, true);
|
||||
|
||||
const run = async () => {
|
||||
mocked(client).getRoom.mockImplementation(roomId => rooms.find(room => room.roomId === roomId));
|
||||
mocked(client).getRoomUpgradeHistory.mockImplementation(roomId => [rooms.find(room => room.roomId === roomId)]);
|
||||
mocked(client).getRoom.mockImplementation((roomId) => rooms.find((room) => room.roomId === roomId));
|
||||
mocked(client).getRoomUpgradeHistory.mockImplementation((roomId) => [
|
||||
rooms.find((room) => room.roomId === roomId),
|
||||
]);
|
||||
await testUtils.setupAsyncStoreWithClient(store, client);
|
||||
jest.runOnlyPendingTimers();
|
||||
};
|
||||
|
@ -119,7 +121,7 @@ describe("SpaceStore", () => {
|
|||
|
||||
beforeEach(async () => {
|
||||
jest.runOnlyPendingTimers(); // run async dispatch
|
||||
mocked(client).getVisibleRooms.mockReturnValue(rooms = []);
|
||||
mocked(client).getVisibleRooms.mockReturnValue((rooms = []));
|
||||
|
||||
await SettingsStore.setValue("Spaces.enabledMetaSpaces", null, SettingLevel.DEVICE, {
|
||||
[MetaSpace.Home]: true,
|
||||
|
@ -157,18 +159,14 @@ describe("SpaceStore", () => {
|
|||
mkSpace("!space1:server");
|
||||
mkSpace("!space2:server");
|
||||
mkSpace("!company:server", [
|
||||
mkSpace("!company_dept1:server", [
|
||||
mkSpace("!company_dept1_group1:server").roomId,
|
||||
]).roomId,
|
||||
mkSpace("!company_dept1:server", [mkSpace("!company_dept1_group1:server").roomId]).roomId,
|
||||
mkSpace("!company_dept2:server").roomId,
|
||||
]);
|
||||
await run();
|
||||
|
||||
expect(store.spacePanelSpaces.map(r => r.roomId).sort()).toStrictEqual([
|
||||
"!space1:server",
|
||||
"!space2:server",
|
||||
"!company:server",
|
||||
].sort());
|
||||
expect(store.spacePanelSpaces.map((r) => r.roomId).sort()).toStrictEqual(
|
||||
["!space1:server", "!space2:server", "!company:server"].sort(),
|
||||
);
|
||||
expect(store.invitedSpaces).toStrictEqual([]);
|
||||
|
||||
expect(store.getChildRooms("!space1:server")).toStrictEqual([]);
|
||||
|
@ -195,19 +193,16 @@ describe("SpaceStore", () => {
|
|||
mkSpace("!space1:server");
|
||||
mkSpace("!space2:server");
|
||||
mkSpace("!company:server", [
|
||||
mkSpace("!company_dept1:server", [
|
||||
mkSpace("!company_dept1_group1:server", [subspace.roomId]).roomId,
|
||||
]).roomId,
|
||||
mkSpace("!company_dept1:server", [mkSpace("!company_dept1_group1:server", [subspace.roomId]).roomId])
|
||||
.roomId,
|
||||
mkSpace("!company_dept2:server", [subspace.roomId]).roomId,
|
||||
subspace.roomId,
|
||||
]);
|
||||
await run();
|
||||
|
||||
expect(store.spacePanelSpaces.map(r => r.roomId).sort()).toStrictEqual([
|
||||
"!space1:server",
|
||||
"!space2:server",
|
||||
"!company:server",
|
||||
].sort());
|
||||
expect(store.spacePanelSpaces.map((r) => r.roomId).sort()).toStrictEqual(
|
||||
["!space1:server", "!space2:server", "!company:server"].sort(),
|
||||
);
|
||||
expect(store.invitedSpaces).toStrictEqual([]);
|
||||
|
||||
expect(store.getChildRooms("!space1:server")).toStrictEqual([]);
|
||||
|
@ -231,16 +226,10 @@ describe("SpaceStore", () => {
|
|||
});
|
||||
|
||||
it("handles full cycles", async () => {
|
||||
mkSpace("!a:server", [
|
||||
mkSpace("!b:server", [
|
||||
mkSpace("!c:server", [
|
||||
"!a:server",
|
||||
]).roomId,
|
||||
]).roomId,
|
||||
]);
|
||||
mkSpace("!a:server", [mkSpace("!b:server", [mkSpace("!c:server", ["!a:server"]).roomId]).roomId]);
|
||||
await run();
|
||||
|
||||
expect(store.spacePanelSpaces.map(r => r.roomId)).toStrictEqual(["!a:server"]);
|
||||
expect(store.spacePanelSpaces.map((r) => r.roomId)).toStrictEqual(["!a:server"]);
|
||||
expect(store.invitedSpaces).toStrictEqual([]);
|
||||
|
||||
expect(store.getChildRooms("!a:server")).toStrictEqual([]);
|
||||
|
@ -252,16 +241,10 @@ describe("SpaceStore", () => {
|
|||
});
|
||||
|
||||
it("handles partial cycles", async () => {
|
||||
mkSpace("!b:server", [
|
||||
mkSpace("!a:server", [
|
||||
mkSpace("!c:server", [
|
||||
"!a:server",
|
||||
]).roomId,
|
||||
]).roomId,
|
||||
]);
|
||||
mkSpace("!b:server", [mkSpace("!a:server", [mkSpace("!c:server", ["!a:server"]).roomId]).roomId]);
|
||||
await run();
|
||||
|
||||
expect(store.spacePanelSpaces.map(r => r.roomId)).toStrictEqual(["!b:server"]);
|
||||
expect(store.spacePanelSpaces.map((r) => r.roomId)).toStrictEqual(["!b:server"]);
|
||||
expect(store.invitedSpaces).toStrictEqual([]);
|
||||
|
||||
expect(store.getChildRooms("!b:server")).toStrictEqual([]);
|
||||
|
@ -275,16 +258,11 @@ describe("SpaceStore", () => {
|
|||
it("handles partial cycles with additional spaces coming off them", async () => {
|
||||
// TODO this test should be failing right now
|
||||
mkSpace("!a:server", [
|
||||
mkSpace("!b:server", [
|
||||
mkSpace("!c:server", [
|
||||
"!a:server",
|
||||
mkSpace("!d:server").roomId,
|
||||
]).roomId,
|
||||
]).roomId,
|
||||
mkSpace("!b:server", [mkSpace("!c:server", ["!a:server", mkSpace("!d:server").roomId]).roomId]).roomId,
|
||||
]);
|
||||
await run();
|
||||
|
||||
expect(store.spacePanelSpaces.map(r => r.roomId)).toStrictEqual(["!a:server"]);
|
||||
expect(store.spacePanelSpaces.map((r) => r.roomId)).toStrictEqual(["!a:server"]);
|
||||
expect(store.invitedSpaces).toStrictEqual([]);
|
||||
|
||||
expect(store.getChildRooms("!a:server")).toStrictEqual([]);
|
||||
|
@ -313,16 +291,30 @@ describe("SpaceStore", () => {
|
|||
|
||||
describe("test fixture 1", () => {
|
||||
beforeEach(async () => {
|
||||
[fav1, fav2, fav3, dm1, dm2, dm3, orphan1, orphan2, invite1, invite2, room1, room2, room3, room4]
|
||||
.forEach(mkRoom);
|
||||
[
|
||||
fav1,
|
||||
fav2,
|
||||
fav3,
|
||||
dm1,
|
||||
dm2,
|
||||
dm3,
|
||||
orphan1,
|
||||
orphan2,
|
||||
invite1,
|
||||
invite2,
|
||||
room1,
|
||||
room2,
|
||||
room3,
|
||||
room4,
|
||||
].forEach(mkRoom);
|
||||
mkSpace(space1, [fav1, room1]);
|
||||
mkSpace(space2, [fav1, fav2, fav3, room1]);
|
||||
mkSpace(space3, [invite2]);
|
||||
mkSpace(space4, [room4, fav2, space2, space3]);
|
||||
|
||||
mocked(client).getRoom.mockImplementation(roomId => rooms.find(room => room.roomId === roomId));
|
||||
mocked(client).getRoom.mockImplementation((roomId) => rooms.find((room) => room.roomId === roomId));
|
||||
|
||||
[fav1, fav2, fav3].forEach(roomId => {
|
||||
[fav1, fav2, fav3].forEach((roomId) => {
|
||||
client.getRoom(roomId).tags = {
|
||||
"m.favourite": {
|
||||
order: 0.5,
|
||||
|
@ -330,21 +322,21 @@ describe("SpaceStore", () => {
|
|||
};
|
||||
});
|
||||
|
||||
[invite1, invite2].forEach(roomId => {
|
||||
[invite1, invite2].forEach((roomId) => {
|
||||
mocked(client.getRoom(roomId)).getMyMembership.mockReturnValue("invite");
|
||||
});
|
||||
|
||||
// have dmPartner1 be in space1 with you
|
||||
const mySpace1Member = new RoomMember(space1, testUserId);
|
||||
mySpace1Member.membership = "join";
|
||||
(rooms.find(r => r.roomId === space1).getMembers as jest.Mock).mockReturnValue([
|
||||
(rooms.find((r) => r.roomId === space1).getMembers as jest.Mock).mockReturnValue([
|
||||
mySpace1Member,
|
||||
dm1Partner,
|
||||
]);
|
||||
// have dmPartner2 be in space2 with you
|
||||
const mySpace2Member = new RoomMember(space2, testUserId);
|
||||
mySpace2Member.membership = "join";
|
||||
(rooms.find(r => r.roomId === space2).getMembers as jest.Mock).mockReturnValue([
|
||||
(rooms.find((r) => r.roomId === space2).getMembers as jest.Mock).mockReturnValue([
|
||||
mySpace2Member,
|
||||
dm2Partner,
|
||||
]);
|
||||
|
@ -371,7 +363,8 @@ describe("SpaceStore", () => {
|
|||
return userId === client.getUserId();
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
// room 3 claims to be a child of space3 but is not due to invalid m.space.parent (permissions)
|
||||
const cliRoom3 = client.getRoom(room3);
|
||||
|
@ -386,7 +379,8 @@ describe("SpaceStore", () => {
|
|||
content: { via: [], canonical: true },
|
||||
ts: Date.now(),
|
||||
}),
|
||||
]));
|
||||
]),
|
||||
);
|
||||
const cliSpace3 = client.getRoom(space3);
|
||||
mocked(cliSpace3.currentState).maySendStateEvent.mockImplementation(
|
||||
(evType: string, userId: string) => {
|
||||
|
@ -394,12 +388,13 @@ describe("SpaceStore", () => {
|
|||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
await run();
|
||||
});
|
||||
|
||||
describe('isRoomInSpace()', () => {
|
||||
describe("isRoomInSpace()", () => {
|
||||
it("home space contains orphaned rooms", () => {
|
||||
expect(store.isRoomInSpace(MetaSpace.Home, orphan1)).toBeTruthy();
|
||||
expect(store.isRoomInSpace(MetaSpace.Home, orphan2)).toBeTruthy();
|
||||
|
@ -425,12 +420,10 @@ describe("SpaceStore", () => {
|
|||
expect(store.isRoomInSpace(MetaSpace.Home, invite2)).toBeTruthy();
|
||||
});
|
||||
|
||||
it(
|
||||
"all rooms space does contain rooms/low priority even if they are also shown in a space",
|
||||
async () => {
|
||||
await setShowAllRooms(true);
|
||||
expect(store.isRoomInSpace(MetaSpace.Home, room1)).toBeTruthy();
|
||||
});
|
||||
it("all rooms space does contain rooms/low priority even if they are also shown in a space", async () => {
|
||||
await setShowAllRooms(true);
|
||||
expect(store.isRoomInSpace(MetaSpace.Home, room1)).toBeTruthy();
|
||||
});
|
||||
|
||||
it("favourites space does contain favourites even if they are also shown in a space", async () => {
|
||||
expect(store.isRoomInSpace(MetaSpace.Favourites, fav1)).toBeTruthy();
|
||||
|
@ -528,7 +521,7 @@ describe("SpaceStore", () => {
|
|||
expect(store.isRoomInSpace(space3, dm3)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('uses cached aggregated rooms', () => {
|
||||
it("uses cached aggregated rooms", () => {
|
||||
const rooms = store.getSpaceFilteredRoomIds(space4, true);
|
||||
expect(store.isRoomInSpace(space4, fav1)).toBeTruthy();
|
||||
expect(store.isRoomInSpace(space4, fav3)).toBeTruthy();
|
||||
|
@ -540,26 +533,44 @@ describe("SpaceStore", () => {
|
|||
});
|
||||
|
||||
it("dms are only added to Notification States for only the People Space", async () => {
|
||||
[dm1, dm2, dm3].forEach(d => {
|
||||
expect(store.getNotificationState(MetaSpace.People)
|
||||
.rooms.map(r => r.roomId).includes(d)).toBeTruthy();
|
||||
[dm1, dm2, dm3].forEach((d) => {
|
||||
expect(
|
||||
store
|
||||
.getNotificationState(MetaSpace.People)
|
||||
.rooms.map((r) => r.roomId)
|
||||
.includes(d),
|
||||
).toBeTruthy();
|
||||
});
|
||||
[space1, space2, space3, MetaSpace.Home, MetaSpace.Orphans, MetaSpace.Favourites].forEach(s => {
|
||||
[dm1, dm2, dm3].forEach(d => {
|
||||
expect(store.getNotificationState(s).rooms.map(r => r.roomId).includes(d)).toBeFalsy();
|
||||
[space1, space2, space3, MetaSpace.Home, MetaSpace.Orphans, MetaSpace.Favourites].forEach((s) => {
|
||||
[dm1, dm2, dm3].forEach((d) => {
|
||||
expect(
|
||||
store
|
||||
.getNotificationState(s)
|
||||
.rooms.map((r) => r.roomId)
|
||||
.includes(d),
|
||||
).toBeFalsy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("orphan rooms are added to Notification States for only the Home Space", async () => {
|
||||
await setShowAllRooms(false);
|
||||
[orphan1, orphan2].forEach(d => {
|
||||
expect(store.getNotificationState(MetaSpace.Home)
|
||||
.rooms.map(r => r.roomId).includes(d)).toBeTruthy();
|
||||
[orphan1, orphan2].forEach((d) => {
|
||||
expect(
|
||||
store
|
||||
.getNotificationState(MetaSpace.Home)
|
||||
.rooms.map((r) => r.roomId)
|
||||
.includes(d),
|
||||
).toBeTruthy();
|
||||
});
|
||||
[space1, space2, space3].forEach(s => {
|
||||
[orphan1, orphan2].forEach(d => {
|
||||
expect(store.getNotificationState(s).rooms.map(r => r.roomId).includes(d)).toBeFalsy();
|
||||
[space1, space2, space3].forEach((s) => {
|
||||
[orphan1, orphan2].forEach((d) => {
|
||||
expect(
|
||||
store
|
||||
.getNotificationState(s)
|
||||
.rooms.map((r) => r.roomId)
|
||||
.includes(d),
|
||||
).toBeFalsy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -569,23 +580,83 @@ describe("SpaceStore", () => {
|
|||
// [fav1, fav2, fav3].forEach(d => {
|
||||
// expect(store.getNotificationState(HOME_SPACE).rooms.map(r => r.roomId).includes(d)).toBeTruthy();
|
||||
// });
|
||||
expect(store.getNotificationState(space1).rooms.map(r => r.roomId).includes(fav1)).toBeTruthy();
|
||||
expect(store.getNotificationState(space1).rooms.map(r => r.roomId).includes(fav2)).toBeFalsy();
|
||||
expect(store.getNotificationState(space1).rooms.map(r => r.roomId).includes(fav3)).toBeFalsy();
|
||||
expect(store.getNotificationState(space2).rooms.map(r => r.roomId).includes(fav1)).toBeTruthy();
|
||||
expect(store.getNotificationState(space2).rooms.map(r => r.roomId).includes(fav2)).toBeTruthy();
|
||||
expect(store.getNotificationState(space2).rooms.map(r => r.roomId).includes(fav3)).toBeTruthy();
|
||||
expect(store.getNotificationState(space3).rooms.map(r => r.roomId).includes(fav1)).toBeFalsy();
|
||||
expect(store.getNotificationState(space3).rooms.map(r => r.roomId).includes(fav2)).toBeFalsy();
|
||||
expect(store.getNotificationState(space3).rooms.map(r => r.roomId).includes(fav3)).toBeFalsy();
|
||||
expect(
|
||||
store
|
||||
.getNotificationState(space1)
|
||||
.rooms.map((r) => r.roomId)
|
||||
.includes(fav1),
|
||||
).toBeTruthy();
|
||||
expect(
|
||||
store
|
||||
.getNotificationState(space1)
|
||||
.rooms.map((r) => r.roomId)
|
||||
.includes(fav2),
|
||||
).toBeFalsy();
|
||||
expect(
|
||||
store
|
||||
.getNotificationState(space1)
|
||||
.rooms.map((r) => r.roomId)
|
||||
.includes(fav3),
|
||||
).toBeFalsy();
|
||||
expect(
|
||||
store
|
||||
.getNotificationState(space2)
|
||||
.rooms.map((r) => r.roomId)
|
||||
.includes(fav1),
|
||||
).toBeTruthy();
|
||||
expect(
|
||||
store
|
||||
.getNotificationState(space2)
|
||||
.rooms.map((r) => r.roomId)
|
||||
.includes(fav2),
|
||||
).toBeTruthy();
|
||||
expect(
|
||||
store
|
||||
.getNotificationState(space2)
|
||||
.rooms.map((r) => r.roomId)
|
||||
.includes(fav3),
|
||||
).toBeTruthy();
|
||||
expect(
|
||||
store
|
||||
.getNotificationState(space3)
|
||||
.rooms.map((r) => r.roomId)
|
||||
.includes(fav1),
|
||||
).toBeFalsy();
|
||||
expect(
|
||||
store
|
||||
.getNotificationState(space3)
|
||||
.rooms.map((r) => r.roomId)
|
||||
.includes(fav2),
|
||||
).toBeFalsy();
|
||||
expect(
|
||||
store
|
||||
.getNotificationState(space3)
|
||||
.rooms.map((r) => r.roomId)
|
||||
.includes(fav3),
|
||||
).toBeFalsy();
|
||||
});
|
||||
|
||||
it("other rooms are added to Notification States for all spaces containing the room exc Home", () => {
|
||||
// XXX: All rooms space is forcibly enabled, as part of a future PR test Home space better
|
||||
// expect(store.getNotificationState(HOME_SPACE).rooms.map(r => r.roomId).includes(room1)).toBeFalsy();
|
||||
expect(store.getNotificationState(space1).rooms.map(r => r.roomId).includes(room1)).toBeTruthy();
|
||||
expect(store.getNotificationState(space2).rooms.map(r => r.roomId).includes(room1)).toBeTruthy();
|
||||
expect(store.getNotificationState(space3).rooms.map(r => r.roomId).includes(room1)).toBeFalsy();
|
||||
expect(
|
||||
store
|
||||
.getNotificationState(space1)
|
||||
.rooms.map((r) => r.roomId)
|
||||
.includes(room1),
|
||||
).toBeTruthy();
|
||||
expect(
|
||||
store
|
||||
.getNotificationState(space2)
|
||||
.rooms.map((r) => r.roomId)
|
||||
.includes(room1),
|
||||
).toBeTruthy();
|
||||
expect(
|
||||
store
|
||||
.getNotificationState(space3)
|
||||
.rooms.map((r) => r.roomId)
|
||||
.includes(room1),
|
||||
).toBeFalsy();
|
||||
});
|
||||
|
||||
it("honours m.space.parent if sender has permission in parent space", () => {
|
||||
|
@ -690,10 +761,24 @@ describe("SpaceStore", () => {
|
|||
expect(store.isRoomInSpace(MetaSpace.Home, invite1)).toBeTruthy();
|
||||
});
|
||||
|
||||
describe('onRoomsUpdate()', () => {
|
||||
describe("onRoomsUpdate()", () => {
|
||||
beforeEach(() => {
|
||||
[fav1, fav2, fav3, dm1, dm2, dm3, orphan1, orphan2, invite1, invite2, room1, room2, room3, room4]
|
||||
.forEach(mkRoom);
|
||||
[
|
||||
fav1,
|
||||
fav2,
|
||||
fav3,
|
||||
dm1,
|
||||
dm2,
|
||||
dm3,
|
||||
orphan1,
|
||||
orphan2,
|
||||
invite1,
|
||||
invite2,
|
||||
room1,
|
||||
room2,
|
||||
room3,
|
||||
room4,
|
||||
].forEach(mkRoom);
|
||||
mkSpace(space2, [fav1, fav2, fav3, room1]);
|
||||
mkSpace(space3, [invite2]);
|
||||
mkSpace(space4, [room4, fav2, space2, space3]);
|
||||
|
@ -725,7 +810,7 @@ describe("SpaceStore", () => {
|
|||
room: spaceId,
|
||||
user: client.getUserId(),
|
||||
skey: user.userId,
|
||||
content: { membership: 'join' },
|
||||
content: { membership: "join" },
|
||||
ts: Date.now(),
|
||||
});
|
||||
const spaceRoom = client.getRoom(spaceId);
|
||||
|
@ -737,11 +822,11 @@ describe("SpaceStore", () => {
|
|||
client.emit(RoomStateEvent.Members, memberEvent, spaceRoom.currentState, user);
|
||||
};
|
||||
|
||||
it('emits events for parent spaces when child room is added', async () => {
|
||||
it("emits events for parent spaces when child room is added", async () => {
|
||||
await run();
|
||||
|
||||
const room5 = mkRoom('!room5:server');
|
||||
const emitSpy = jest.spyOn(store, 'emit').mockClear();
|
||||
const room5 = mkRoom("!room5:server");
|
||||
const emitSpy = jest.spyOn(store, "emit").mockClear();
|
||||
// add room5 into space2
|
||||
addChildRoom(space2, room5.roomId);
|
||||
|
||||
|
@ -753,9 +838,9 @@ describe("SpaceStore", () => {
|
|||
expect(emitSpy).not.toHaveBeenCalledWith(space3);
|
||||
});
|
||||
|
||||
it('updates rooms state when a child room is added', async () => {
|
||||
it("updates rooms state when a child room is added", async () => {
|
||||
await run();
|
||||
const room5 = mkRoom('!room5:server');
|
||||
const room5 = mkRoom("!room5:server");
|
||||
|
||||
expect(store.isRoomInSpace(space2, room5.roomId)).toBeFalsy();
|
||||
expect(store.isRoomInSpace(space4, room5.roomId)).toBeFalsy();
|
||||
|
@ -770,10 +855,10 @@ describe("SpaceStore", () => {
|
|||
expect(store.isRoomInSpace(space1, room5.roomId)).toBeTruthy();
|
||||
});
|
||||
|
||||
it('emits events for parent spaces when a member is added', async () => {
|
||||
it("emits events for parent spaces when a member is added", async () => {
|
||||
await run();
|
||||
|
||||
const emitSpy = jest.spyOn(store, 'emit').mockClear();
|
||||
const emitSpy = jest.spyOn(store, "emit").mockClear();
|
||||
// add into space2
|
||||
addMember(space2, dm1Partner);
|
||||
|
||||
|
@ -785,7 +870,7 @@ describe("SpaceStore", () => {
|
|||
expect(emitSpy).not.toHaveBeenCalledWith(space3);
|
||||
});
|
||||
|
||||
it('updates users state when a member is added', async () => {
|
||||
it("updates users state when a member is added", async () => {
|
||||
await run();
|
||||
|
||||
expect(store.getSpaceFilteredUserIds(space2)).toEqual(new Set([]));
|
||||
|
@ -805,9 +890,7 @@ describe("SpaceStore", () => {
|
|||
|
||||
beforeEach(async () => {
|
||||
mkRoom(room1); // not a space
|
||||
mkSpace(space1, [
|
||||
mkSpace(space2).roomId,
|
||||
]);
|
||||
mkSpace(space1, [mkSpace(space2).roomId]);
|
||||
mkSpace(space3).getMyMembership.mockReturnValue("invite");
|
||||
await run();
|
||||
store.setActiveSpace(MetaSpace.Home);
|
||||
|
@ -873,7 +956,7 @@ describe("SpaceStore", () => {
|
|||
user: dm1Partner.userId,
|
||||
room: space1,
|
||||
});
|
||||
space.getMember.mockImplementation(userId => {
|
||||
space.getMember.mockImplementation((userId) => {
|
||||
if (userId === dm1Partner.userId) {
|
||||
const member = new RoomMember(space1, dm1Partner.userId);
|
||||
member.membership = "join";
|
||||
|
@ -924,7 +1007,7 @@ describe("SpaceStore", () => {
|
|||
mkSpace(space2, [room2]);
|
||||
await run();
|
||||
|
||||
dispatcherRef = defaultDispatcher.register(payload => {
|
||||
dispatcherRef = defaultDispatcher.register((payload) => {
|
||||
if (payload.action === Action.ViewRoom || payload.action === Action.ViewHomePage) {
|
||||
currentRoom = payload.room_id || null;
|
||||
}
|
||||
|
@ -1006,17 +1089,19 @@ describe("SpaceStore", () => {
|
|||
mkSpace(space2, [room1, room2]);
|
||||
|
||||
const cliRoom2 = client.getRoom(room2);
|
||||
mocked(cliRoom2.currentState).getStateEvents.mockImplementation(testUtils.mockStateEventImplementation([
|
||||
mkEvent({
|
||||
event: true,
|
||||
type: EventType.SpaceParent,
|
||||
room: room2,
|
||||
user: testUserId,
|
||||
skey: space2,
|
||||
content: { via: [], canonical: true },
|
||||
ts: Date.now(),
|
||||
}),
|
||||
]));
|
||||
mocked(cliRoom2.currentState).getStateEvents.mockImplementation(
|
||||
testUtils.mockStateEventImplementation([
|
||||
mkEvent({
|
||||
event: true,
|
||||
type: EventType.SpaceParent,
|
||||
room: room2,
|
||||
user: testUserId,
|
||||
skey: space2,
|
||||
content: { via: [], canonical: true },
|
||||
ts: Date.now(),
|
||||
}),
|
||||
]),
|
||||
);
|
||||
await run();
|
||||
});
|
||||
|
||||
|
@ -1174,11 +1259,8 @@ describe("SpaceStore", () => {
|
|||
myRootSpaceMember.membership = "join";
|
||||
const rootSpaceFriend = new RoomMember(space1, dm1Partner.userId);
|
||||
rootSpaceFriend.membership = "join";
|
||||
rootSpace.getMembers.mockReturnValue([
|
||||
myRootSpaceMember,
|
||||
rootSpaceFriend,
|
||||
]);
|
||||
rootSpace.getMember.mockImplementation(userId => {
|
||||
rootSpace.getMembers.mockReturnValue([myRootSpaceMember, rootSpaceFriend]);
|
||||
rootSpace.getMember.mockImplementation((userId) => {
|
||||
switch (userId) {
|
||||
case testUserId:
|
||||
return myRootSpaceMember;
|
||||
|
@ -1219,7 +1301,7 @@ describe("SpaceStore", () => {
|
|||
client.emit(ClientEvent.Room, subspace);
|
||||
jest.runOnlyPendingTimers();
|
||||
expect(SpaceStore.instance.invitedSpaces).toStrictEqual([]);
|
||||
expect(SpaceStore.instance.spacePanelSpaces.map(r => r.roomId)).toStrictEqual([rootSpace.roomId]);
|
||||
expect(SpaceStore.instance.spacePanelSpaces.map((r) => r.roomId)).toStrictEqual([rootSpace.roomId]);
|
||||
await prom;
|
||||
});
|
||||
|
||||
|
|
|
@ -32,8 +32,8 @@ describe("TypingStore", () => {
|
|||
let typingStore: TypingStore;
|
||||
let mockClient: MatrixClient;
|
||||
const settings = {
|
||||
"sendTypingNotifications": true,
|
||||
"feature_thread": false,
|
||||
sendTypingNotifications: true,
|
||||
feature_thread: false,
|
||||
};
|
||||
const roomId = "!test:example.com";
|
||||
const localRoomId = LOCAL_ROOM_ID_PREFIX + "test";
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
/*
|
||||
Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
|
||||
|
@ -17,18 +16,18 @@ limitations under the License.
|
|||
|
||||
import { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { VoiceRecordingStore } from '../../src/stores/VoiceRecordingStore';
|
||||
import { VoiceRecordingStore } from "../../src/stores/VoiceRecordingStore";
|
||||
import { MatrixClientPeg } from "../../src/MatrixClientPeg";
|
||||
import { flushPromises } from "../test-utils";
|
||||
import { VoiceMessageRecording } from "../../src/audio/VoiceMessageRecording";
|
||||
|
||||
const stubClient = {} as undefined as MatrixClient;
|
||||
jest.spyOn(MatrixClientPeg, 'get').mockReturnValue(stubClient);
|
||||
jest.spyOn(MatrixClientPeg, "get").mockReturnValue(stubClient);
|
||||
|
||||
describe('VoiceRecordingStore', () => {
|
||||
const room1Id = '!room1:server.org';
|
||||
const room2Id = '!room2:server.org';
|
||||
const room3Id = '!room3:server.org';
|
||||
describe("VoiceRecordingStore", () => {
|
||||
const room1Id = "!room1:server.org";
|
||||
const room2Id = "!room2:server.org";
|
||||
const room3Id = "!room3:server.org";
|
||||
const room1Recording = { destroy: jest.fn() } as unknown as VoiceMessageRecording;
|
||||
const room2Recording = { destroy: jest.fn() } as unknown as VoiceMessageRecording;
|
||||
|
||||
|
@ -44,20 +43,20 @@ describe('VoiceRecordingStore', () => {
|
|||
return store;
|
||||
};
|
||||
|
||||
describe('startRecording()', () => {
|
||||
it('throws when roomId is falsy', () => {
|
||||
describe("startRecording()", () => {
|
||||
it("throws when roomId is falsy", () => {
|
||||
const store = mkStore();
|
||||
expect(() => store.startRecording(undefined)).toThrow("Recording must be associated with a room");
|
||||
});
|
||||
|
||||
it('throws when room already has a recording', () => {
|
||||
it("throws when room already has a recording", () => {
|
||||
const store = mkStore();
|
||||
// @ts-ignore
|
||||
store.storeState = state;
|
||||
expect(() => store.startRecording(room2Id)).toThrow("A recording is already in progress");
|
||||
});
|
||||
|
||||
it('creates and adds recording to state', async () => {
|
||||
it("creates and adds recording to state", async () => {
|
||||
const store = mkStore();
|
||||
const result = store.startRecording(room2Id);
|
||||
|
||||
|
@ -68,8 +67,8 @@ describe('VoiceRecordingStore', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('disposeRecording()', () => {
|
||||
it('destroys recording for a room if it exists in state', async () => {
|
||||
describe("disposeRecording()", () => {
|
||||
it("destroys recording for a room if it exists in state", async () => {
|
||||
const store = mkStore();
|
||||
// @ts-ignore
|
||||
store.storeState = state;
|
||||
|
@ -79,7 +78,7 @@ describe('VoiceRecordingStore', () => {
|
|||
expect(room1Recording.destroy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('removes room from state when it has a recording', async () => {
|
||||
it("removes room from state when it has a recording", async () => {
|
||||
const store = mkStore();
|
||||
// @ts-ignore
|
||||
store.storeState = state;
|
||||
|
@ -89,7 +88,7 @@ describe('VoiceRecordingStore', () => {
|
|||
expect(store.getActiveRecording(room2Id)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('removes room from state when it has a falsy recording', async () => {
|
||||
it("removes room from state when it has a falsy recording", async () => {
|
||||
const store = mkStore();
|
||||
// @ts-ignore
|
||||
store.storeState = state;
|
||||
|
|
|
@ -31,17 +31,18 @@ const mockRoom = <Room>{
|
|||
getContent: () => null,
|
||||
};
|
||||
},
|
||||
} };
|
||||
},
|
||||
};
|
||||
|
||||
const mockApps = [
|
||||
<IApp> { roomId: roomId, id: "1" },
|
||||
<IApp> { roomId: roomId, id: "2" },
|
||||
<IApp> { roomId: roomId, id: "3" },
|
||||
<IApp> { roomId: roomId, id: "4" },
|
||||
<IApp>{ roomId: roomId, id: "1" },
|
||||
<IApp>{ roomId: roomId, id: "2" },
|
||||
<IApp>{ roomId: roomId, id: "3" },
|
||||
<IApp>{ roomId: roomId, id: "4" },
|
||||
];
|
||||
|
||||
// fake the WidgetStore.instance to just return an object with `getApps`
|
||||
jest.spyOn(WidgetStore, 'instance', 'get').mockReturnValue(<WidgetStore>{ getApps: (_room) => mockApps });
|
||||
jest.spyOn(WidgetStore, "instance", "get").mockReturnValue(<WidgetStore>{ getApps: (_room) => mockApps });
|
||||
|
||||
describe("WidgetLayoutStore", () => {
|
||||
// we need to init a client so it does not error, when asking for DeviceStorage handlers (SettingsStore.setValue("Widgets.layout"))
|
||||
|
@ -63,16 +64,16 @@ describe("WidgetLayoutStore", () => {
|
|||
store.moveToContainer(mockRoom, mockApps[0], Container.Top);
|
||||
store.moveToContainer(mockRoom, mockApps[1], Container.Top);
|
||||
store.moveToContainer(mockRoom, mockApps[2], Container.Top);
|
||||
expect(new Set(store.getContainerWidgets(mockRoom, Container.Top)))
|
||||
.toEqual(new Set([mockApps[0], mockApps[1], mockApps[2]]));
|
||||
expect(new Set(store.getContainerWidgets(mockRoom, Container.Top))).toEqual(
|
||||
new Set([mockApps[0], mockApps[1], mockApps[2]]),
|
||||
);
|
||||
});
|
||||
it("cannot add more than three widgets to top container", async () => {
|
||||
store.recalculateRoom(mockRoom);
|
||||
store.moveToContainer(mockRoom, mockApps[0], Container.Top);
|
||||
store.moveToContainer(mockRoom, mockApps[1], Container.Top);
|
||||
store.moveToContainer(mockRoom, mockApps[2], Container.Top);
|
||||
expect(store.canAddToContainer(mockRoom, Container.Top))
|
||||
.toEqual(false);
|
||||
expect(store.canAddToContainer(mockRoom, Container.Top)).toEqual(false);
|
||||
});
|
||||
it("remove pins when maximising (other widget)", async () => {
|
||||
store.recalculateRoom(mockRoom);
|
||||
|
@ -80,12 +81,11 @@ describe("WidgetLayoutStore", () => {
|
|||
store.moveToContainer(mockRoom, mockApps[1], Container.Top);
|
||||
store.moveToContainer(mockRoom, mockApps[2], Container.Top);
|
||||
store.moveToContainer(mockRoom, mockApps[3], Container.Center);
|
||||
expect(store.getContainerWidgets(mockRoom, Container.Top))
|
||||
.toEqual([]);
|
||||
expect(new Set(store.getContainerWidgets(mockRoom, Container.Right)))
|
||||
.toEqual(new Set([mockApps[0], mockApps[1], mockApps[2]]));
|
||||
expect(store.getContainerWidgets(mockRoom, Container.Center))
|
||||
.toEqual([mockApps[3]]);
|
||||
expect(store.getContainerWidgets(mockRoom, Container.Top)).toEqual([]);
|
||||
expect(new Set(store.getContainerWidgets(mockRoom, Container.Right))).toEqual(
|
||||
new Set([mockApps[0], mockApps[1], mockApps[2]]),
|
||||
);
|
||||
expect(store.getContainerWidgets(mockRoom, Container.Center)).toEqual([mockApps[3]]);
|
||||
});
|
||||
it("remove pins when maximising (one of the pinned widgets)", async () => {
|
||||
store.recalculateRoom(mockRoom);
|
||||
|
@ -93,33 +93,30 @@ describe("WidgetLayoutStore", () => {
|
|||
store.moveToContainer(mockRoom, mockApps[1], Container.Top);
|
||||
store.moveToContainer(mockRoom, mockApps[2], Container.Top);
|
||||
store.moveToContainer(mockRoom, mockApps[0], Container.Center);
|
||||
expect(store.getContainerWidgets(mockRoom, Container.Top))
|
||||
.toEqual([]);
|
||||
expect(store.getContainerWidgets(mockRoom, Container.Center))
|
||||
.toEqual([mockApps[0]]);
|
||||
expect(new Set(store.getContainerWidgets(mockRoom, Container.Right)))
|
||||
.toEqual(new Set([mockApps[1], mockApps[2], mockApps[3]]));
|
||||
expect(store.getContainerWidgets(mockRoom, Container.Top)).toEqual([]);
|
||||
expect(store.getContainerWidgets(mockRoom, Container.Center)).toEqual([mockApps[0]]);
|
||||
expect(new Set(store.getContainerWidgets(mockRoom, Container.Right))).toEqual(
|
||||
new Set([mockApps[1], mockApps[2], mockApps[3]]),
|
||||
);
|
||||
});
|
||||
it("remove maximised when pinning (other widget)", async () => {
|
||||
store.recalculateRoom(mockRoom);
|
||||
store.moveToContainer(mockRoom, mockApps[0], Container.Center);
|
||||
store.moveToContainer(mockRoom, mockApps[1], Container.Top);
|
||||
expect(store.getContainerWidgets(mockRoom, Container.Top))
|
||||
.toEqual([mockApps[1]]);
|
||||
expect(store.getContainerWidgets(mockRoom, Container.Center))
|
||||
.toEqual([]);
|
||||
expect(new Set(store.getContainerWidgets(mockRoom, Container.Right)))
|
||||
.toEqual(new Set([mockApps[2], mockApps[3], mockApps[0]]));
|
||||
expect(store.getContainerWidgets(mockRoom, Container.Top)).toEqual([mockApps[1]]);
|
||||
expect(store.getContainerWidgets(mockRoom, Container.Center)).toEqual([]);
|
||||
expect(new Set(store.getContainerWidgets(mockRoom, Container.Right))).toEqual(
|
||||
new Set([mockApps[2], mockApps[3], mockApps[0]]),
|
||||
);
|
||||
});
|
||||
it("remove maximised when pinning (same widget)", async () => {
|
||||
store.recalculateRoom(mockRoom);
|
||||
store.moveToContainer(mockRoom, mockApps[0], Container.Center);
|
||||
store.moveToContainer(mockRoom, mockApps[0], Container.Top);
|
||||
expect(store.getContainerWidgets(mockRoom, Container.Top))
|
||||
.toEqual([mockApps[0]]);
|
||||
expect(store.getContainerWidgets(mockRoom, Container.Center))
|
||||
.toEqual([]);
|
||||
expect(new Set(store.getContainerWidgets(mockRoom, Container.Right)))
|
||||
.toEqual(new Set([mockApps[2], mockApps[3], mockApps[1]]));
|
||||
expect(store.getContainerWidgets(mockRoom, Container.Top)).toEqual([mockApps[0]]);
|
||||
expect(store.getContainerWidgets(mockRoom, Container.Center)).toEqual([]);
|
||||
expect(new Set(store.getContainerWidgets(mockRoom, Container.Right))).toEqual(
|
||||
new Set([mockApps[2], mockApps[3], mockApps[1]]),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -45,8 +45,8 @@ describe("RightPanelStore", () => {
|
|||
});
|
||||
|
||||
const viewRoom = async (roomId: string) => {
|
||||
const roomChanged = new Promise<void>(resolve => {
|
||||
const ref = defaultDispatcher.register(payload => {
|
||||
const roomChanged = new Promise<void>((resolve) => {
|
||||
const ref = defaultDispatcher.register((payload) => {
|
||||
if (payload.action === Action.ActiveRoomChanged && payload.newRoomId === roomId) {
|
||||
defaultDispatcher.unregister(ref);
|
||||
resolve();
|
||||
|
@ -113,9 +113,7 @@ describe("RightPanelStore", () => {
|
|||
await viewRoom("!1:example.org");
|
||||
store.setCard({ phase: RightPanelPhases.RoomSummary }, true, "!1:example.org");
|
||||
store.setCard({ phase: RightPanelPhases.RoomSummary }, true, "!1:example.org");
|
||||
expect(store.roomPhaseHistory).toEqual([
|
||||
{ phase: RightPanelPhases.RoomSummary, state: {} },
|
||||
]);
|
||||
expect(store.roomPhaseHistory).toEqual([{ phase: RightPanelPhases.RoomSummary, state: {} }]);
|
||||
});
|
||||
it("opens the panel in the given room with the correct phase", () => {
|
||||
store.setCard({ phase: RightPanelPhases.RoomSummary }, true, "!1:example.org");
|
||||
|
@ -126,9 +124,7 @@ describe("RightPanelStore", () => {
|
|||
await viewRoom("!1:example.org");
|
||||
store.setCard({ phase: RightPanelPhases.RoomSummary }, true, "!1:example.org");
|
||||
store.setCard({ phase: RightPanelPhases.RoomMemberList }, true, "!1:example.org");
|
||||
expect(store.roomPhaseHistory).toEqual([
|
||||
{ phase: RightPanelPhases.RoomMemberList, state: {} },
|
||||
]);
|
||||
expect(store.roomPhaseHistory).toEqual([{ phase: RightPanelPhases.RoomMemberList, state: {} }]);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -136,10 +132,11 @@ describe("RightPanelStore", () => {
|
|||
it("overwrites history", async () => {
|
||||
await viewRoom("!1:example.org");
|
||||
store.setCard({ phase: RightPanelPhases.RoomMemberList }, true, "!1:example.org");
|
||||
store.setCards([
|
||||
{ phase: RightPanelPhases.RoomSummary },
|
||||
{ phase: RightPanelPhases.PinnedMessages },
|
||||
], true, "!1:example.org");
|
||||
store.setCards(
|
||||
[{ phase: RightPanelPhases.RoomSummary }, { phase: RightPanelPhases.PinnedMessages }],
|
||||
true,
|
||||
"!1:example.org",
|
||||
);
|
||||
expect(store.roomPhaseHistory).toEqual([
|
||||
{ phase: RightPanelPhases.RoomSummary, state: {} },
|
||||
{ phase: RightPanelPhases.PinnedMessages, state: {} },
|
||||
|
@ -171,10 +168,11 @@ describe("RightPanelStore", () => {
|
|||
|
||||
describe("popCard", () => {
|
||||
it("removes the most recent card", () => {
|
||||
store.setCards([
|
||||
{ phase: RightPanelPhases.RoomSummary },
|
||||
{ phase: RightPanelPhases.PinnedMessages },
|
||||
], true, "!1:example.org");
|
||||
store.setCards(
|
||||
[{ phase: RightPanelPhases.RoomSummary }, { phase: RightPanelPhases.PinnedMessages }],
|
||||
true,
|
||||
"!1:example.org",
|
||||
);
|
||||
expect(store.currentCardForRoom("!1:example.org").phase).toEqual(RightPanelPhases.PinnedMessages);
|
||||
store.popCard("!1:example.org");
|
||||
expect(store.currentCardForRoom("!1:example.org").phase).toEqual(RightPanelPhases.RoomSummary);
|
||||
|
@ -208,15 +206,19 @@ describe("RightPanelStore", () => {
|
|||
|
||||
it("doesn't restore member info cards when switching back to a room", async () => {
|
||||
await viewRoom("!1:example.org");
|
||||
store.setCards([
|
||||
{
|
||||
phase: RightPanelPhases.RoomMemberList,
|
||||
},
|
||||
{
|
||||
phase: RightPanelPhases.RoomMemberInfo,
|
||||
state: { member: new RoomMember("!1:example.org", "@alice:example.org") },
|
||||
},
|
||||
], true, "!1:example.org");
|
||||
store.setCards(
|
||||
[
|
||||
{
|
||||
phase: RightPanelPhases.RoomMemberList,
|
||||
},
|
||||
{
|
||||
phase: RightPanelPhases.RoomMemberInfo,
|
||||
state: { member: new RoomMember("!1:example.org", "@alice:example.org") },
|
||||
},
|
||||
],
|
||||
true,
|
||||
"!1:example.org",
|
||||
);
|
||||
expect(store.currentCardForRoom("!1:example.org").phase).toEqual(RightPanelPhases.RoomMemberInfo);
|
||||
|
||||
// Switch away and back
|
||||
|
|
|
@ -13,9 +13,9 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { mocked } from 'jest-mock';
|
||||
import { SlidingSync, SlidingSyncEvent } from 'matrix-js-sdk/src/sliding-sync';
|
||||
import { Room } from 'matrix-js-sdk/src/matrix';
|
||||
import { mocked } from "jest-mock";
|
||||
import { SlidingSync, SlidingSyncEvent } from "matrix-js-sdk/src/sliding-sync";
|
||||
import { Room } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import {
|
||||
LISTS_UPDATE_EVENT,
|
||||
|
@ -24,18 +24,18 @@ import {
|
|||
} from "../../../src/stores/room-list/SlidingRoomListStore";
|
||||
import { SpaceStoreClass } from "../../../src/stores/spaces/SpaceStore";
|
||||
import { MockEventEmitter, stubClient, untilEmission } from "../../test-utils";
|
||||
import { TestSdkContext } from '../../TestSdkContext';
|
||||
import { SlidingSyncManager } from '../../../src/SlidingSyncManager';
|
||||
import { RoomViewStore } from '../../../src/stores/RoomViewStore';
|
||||
import { MatrixDispatcher } from '../../../src/dispatcher/dispatcher';
|
||||
import { SortAlgorithm } from '../../../src/stores/room-list/algorithms/models';
|
||||
import { DefaultTagID, TagID } from '../../../src/stores/room-list/models';
|
||||
import { UPDATE_SELECTED_SPACE } from '../../../src/stores/spaces';
|
||||
import { LISTS_LOADING_EVENT } from '../../../src/stores/room-list/RoomListStore';
|
||||
import { UPDATE_EVENT } from '../../../src/stores/AsyncStore';
|
||||
import { TestSdkContext } from "../../TestSdkContext";
|
||||
import { SlidingSyncManager } from "../../../src/SlidingSyncManager";
|
||||
import { RoomViewStore } from "../../../src/stores/RoomViewStore";
|
||||
import { MatrixDispatcher } from "../../../src/dispatcher/dispatcher";
|
||||
import { SortAlgorithm } from "../../../src/stores/room-list/algorithms/models";
|
||||
import { DefaultTagID, TagID } from "../../../src/stores/room-list/models";
|
||||
import { UPDATE_SELECTED_SPACE } from "../../../src/stores/spaces";
|
||||
import { LISTS_LOADING_EVENT } from "../../../src/stores/room-list/RoomListStore";
|
||||
import { UPDATE_EVENT } from "../../../src/stores/AsyncStore";
|
||||
|
||||
jest.mock('../../../src/SlidingSyncManager');
|
||||
const MockSlidingSyncManager = <jest.Mock<SlidingSyncManager>><unknown>SlidingSyncManager;
|
||||
jest.mock("../../../src/SlidingSyncManager");
|
||||
const MockSlidingSyncManager = <jest.Mock<SlidingSyncManager>>(<unknown>SlidingSyncManager);
|
||||
|
||||
describe("SlidingRoomListStore", () => {
|
||||
let store: SlidingRoomListStoreClass;
|
||||
|
@ -54,12 +54,16 @@ describe("SlidingRoomListStore", () => {
|
|||
},
|
||||
}) as SpaceStoreClass;
|
||||
context._SlidingSyncManager = new MockSlidingSyncManager();
|
||||
context._SlidingSyncManager.slidingSync = mocked(new MockEventEmitter({
|
||||
getListData: jest.fn(),
|
||||
}) as unknown as SlidingSync);
|
||||
context._RoomViewStore = mocked(new MockEventEmitter({
|
||||
getRoomId: jest.fn(),
|
||||
}) as unknown as RoomViewStore);
|
||||
context._SlidingSyncManager.slidingSync = mocked(
|
||||
new MockEventEmitter({
|
||||
getListData: jest.fn(),
|
||||
}) as unknown as SlidingSync,
|
||||
);
|
||||
context._RoomViewStore = mocked(
|
||||
new MockEventEmitter({
|
||||
getRoomId: jest.fn(),
|
||||
}) as unknown as RoomViewStore,
|
||||
);
|
||||
|
||||
// mock implementations to allow the store to map tag IDs to sliding sync list indexes and vice versa
|
||||
let index = 0;
|
||||
|
@ -208,12 +212,13 @@ describe("SlidingRoomListStore", () => {
|
|||
return indexToListData[i] || null;
|
||||
});
|
||||
|
||||
expect(store.getTagsForRoom(new Room(roomA, context.client, context.client.getUserId()))).toEqual(
|
||||
[DefaultTagID.Untagged],
|
||||
);
|
||||
expect(store.getTagsForRoom(new Room(roomB, context.client, context.client.getUserId()))).toEqual(
|
||||
[DefaultTagID.Favourite, DefaultTagID.Untagged],
|
||||
);
|
||||
expect(store.getTagsForRoom(new Room(roomA, context.client, context.client.getUserId()))).toEqual([
|
||||
DefaultTagID.Untagged,
|
||||
]);
|
||||
expect(store.getTagsForRoom(new Room(roomB, context.client, context.client.getUserId()))).toEqual([
|
||||
DefaultTagID.Favourite,
|
||||
DefaultTagID.Untagged,
|
||||
]);
|
||||
});
|
||||
|
||||
it("emits LISTS_UPDATE_EVENT when slidingSync lists update", async () => {
|
||||
|
@ -224,7 +229,8 @@ describe("SlidingRoomListStore", () => {
|
|||
const tagId = DefaultTagID.Favourite;
|
||||
const listIndex = context.slidingSyncManager.getOrAllocateListIndex(tagId);
|
||||
const joinCount = 10;
|
||||
const roomIndexToRoomId = { // mixed to ensure we sort
|
||||
const roomIndexToRoomId = {
|
||||
// mixed to ensure we sort
|
||||
1: roomB,
|
||||
2: roomC,
|
||||
0: roomA,
|
||||
|
@ -261,7 +267,8 @@ describe("SlidingRoomListStore", () => {
|
|||
const tagId = DefaultTagID.Favourite;
|
||||
const listIndex = context.slidingSyncManager.getOrAllocateListIndex(tagId);
|
||||
const joinCount = 10;
|
||||
const roomIndexToRoomId = { // mixed to ensure we sort
|
||||
const roomIndexToRoomId = {
|
||||
// mixed to ensure we sort
|
||||
1: roomIdB,
|
||||
2: roomIdC,
|
||||
0: roomIdA,
|
||||
|
|
|
@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { mocked } from 'jest-mock';
|
||||
import { mocked } from "jest-mock";
|
||||
|
||||
import { SpaceWatcher } from "../../../src/stores/room-list/SpaceWatcher";
|
||||
import type { RoomListStoreClass } from "../../../src/stores/room-list/RoomListStore";
|
||||
|
@ -22,11 +22,7 @@ import SpaceStore from "../../../src/stores/spaces/SpaceStore";
|
|||
import { MetaSpace, UPDATE_HOME_BEHAVIOUR } from "../../../src/stores/spaces";
|
||||
import { stubClient } from "../../test-utils";
|
||||
import { SettingLevel } from "../../../src/settings/SettingLevel";
|
||||
import {
|
||||
mkSpace,
|
||||
emitPromise,
|
||||
setupAsyncStoreWithClient,
|
||||
} from "../../test-utils";
|
||||
import { mkSpace, emitPromise, setupAsyncStoreWithClient } from "../../test-utils";
|
||||
import { MatrixClientPeg } from "../../../src/MatrixClientPeg";
|
||||
import { SpaceFilterCondition } from "../../../src/stores/room-list/filters/SpaceFilterCondition";
|
||||
import DMRoomMap from "../../../src/utils/DMRoomMap";
|
||||
|
@ -34,8 +30,8 @@ import DMRoomMap from "../../../src/utils/DMRoomMap";
|
|||
let filter: SpaceFilterCondition = null;
|
||||
|
||||
const mockRoomListStore = {
|
||||
addFilter: f => filter = f,
|
||||
removeFilter: () => filter = null,
|
||||
addFilter: (f) => (filter = f),
|
||||
removeFilter: () => (filter = null),
|
||||
} as unknown as RoomListStoreClass;
|
||||
|
||||
const getUserIdForRoomId = jest.fn();
|
||||
|
@ -64,7 +60,7 @@ describe("SpaceWatcher", () => {
|
|||
filter = null;
|
||||
store.removeAllListeners();
|
||||
store.setActiveSpace(MetaSpace.Home);
|
||||
client.getVisibleRooms.mockReturnValue(rooms = []);
|
||||
client.getVisibleRooms.mockReturnValue((rooms = []));
|
||||
|
||||
mkSpaceForRooms(space1);
|
||||
mkSpaceForRooms(space2);
|
||||
|
@ -76,7 +72,7 @@ describe("SpaceWatcher", () => {
|
|||
[MetaSpace.Orphans]: true,
|
||||
});
|
||||
|
||||
client.getRoom.mockImplementation(roomId => rooms.find(room => room.roomId === roomId));
|
||||
client.getRoom.mockImplementation((roomId) => rooms.find((room) => room.roomId === roomId));
|
||||
await setupAsyncStoreWithClient(store, client);
|
||||
});
|
||||
|
||||
|
|
|
@ -63,11 +63,14 @@ describe("Algorithm", () => {
|
|||
pendingEventOrdering: PendingEventOrdering.Detached,
|
||||
});
|
||||
|
||||
client.getRoom.mockImplementation(roomId => {
|
||||
client.getRoom.mockImplementation((roomId) => {
|
||||
switch (roomId) {
|
||||
case room.roomId: return room;
|
||||
case roomWithCall.roomId: return roomWithCall;
|
||||
default: return null;
|
||||
case room.roomId:
|
||||
return room;
|
||||
case roomWithCall.roomId:
|
||||
return roomWithCall;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
});
|
||||
client.getRooms.mockReturnValue([room, roomWithCall]);
|
||||
|
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { mocked } from 'jest-mock';
|
||||
import { mocked } from "jest-mock";
|
||||
import { Room } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import SettingsStore from "../../../../src/settings/SettingsStore";
|
||||
|
@ -26,7 +26,7 @@ import SpaceStore from "../../../../src/stores/spaces/SpaceStore";
|
|||
jest.mock("../../../../src/settings/SettingsStore");
|
||||
jest.mock("../../../../src/stores/spaces/SpaceStore", () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const EventEmitter = require('events');
|
||||
const EventEmitter = require("events");
|
||||
class MockSpaceStore extends EventEmitter {
|
||||
isRoomInSpace = jest.fn();
|
||||
getSpaceFilteredUserIds = jest.fn().mockReturnValue(new Set<string>([]));
|
||||
|
@ -40,16 +40,19 @@ const SpaceStoreInstanceMock = mocked(SpaceStore.instance);
|
|||
|
||||
jest.useFakeTimers();
|
||||
|
||||
describe('SpaceFilterCondition', () => {
|
||||
const space1 = '!space1:server';
|
||||
const space2 = '!space2:server';
|
||||
const room1Id = '!r1:server';
|
||||
const room2Id = '!r2:server';
|
||||
const room3Id = '!r3:server';
|
||||
const user1Id = '@u1:server';
|
||||
const user2Id = '@u2:server';
|
||||
const user3Id = '@u3:server';
|
||||
const makeMockGetValue = (settings = {}) => (settingName, space) => settings[settingName]?.[space] || false;
|
||||
describe("SpaceFilterCondition", () => {
|
||||
const space1 = "!space1:server";
|
||||
const space2 = "!space2:server";
|
||||
const room1Id = "!r1:server";
|
||||
const room2Id = "!r2:server";
|
||||
const room3Id = "!r3:server";
|
||||
const user1Id = "@u1:server";
|
||||
const user2Id = "@u2:server";
|
||||
const user3Id = "@u3:server";
|
||||
const makeMockGetValue =
|
||||
(settings = {}) =>
|
||||
(settingName, space) =>
|
||||
settings[settingName]?.[space] || false;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
|
@ -65,9 +68,9 @@ describe('SpaceFilterCondition', () => {
|
|||
return filter;
|
||||
};
|
||||
|
||||
describe('isVisible', () => {
|
||||
describe("isVisible", () => {
|
||||
const room1 = { roomId: room1Id } as unknown as Room;
|
||||
it('calls isRoomInSpace correctly', () => {
|
||||
it("calls isRoomInSpace correctly", () => {
|
||||
const filter = initFilter(space1);
|
||||
|
||||
expect(filter.isVisible(room1)).toEqual(true);
|
||||
|
@ -75,40 +78,46 @@ describe('SpaceFilterCondition', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('onStoreUpdate', () => {
|
||||
it('emits filter changed event when updateSpace is called even without changes', async () => {
|
||||
describe("onStoreUpdate", () => {
|
||||
it("emits filter changed event when updateSpace is called even without changes", async () => {
|
||||
const filter = new SpaceFilterCondition();
|
||||
const emitSpy = jest.spyOn(filter, 'emit');
|
||||
const emitSpy = jest.spyOn(filter, "emit");
|
||||
filter.updateSpace(space1);
|
||||
jest.runOnlyPendingTimers();
|
||||
expect(emitSpy).toHaveBeenCalledWith(FILTER_CHANGED);
|
||||
});
|
||||
|
||||
describe('showPeopleInSpace setting', () => {
|
||||
it('emits filter changed event when setting changes', async () => {
|
||||
describe("showPeopleInSpace setting", () => {
|
||||
it("emits filter changed event when setting changes", async () => {
|
||||
// init filter with setting true for space1
|
||||
SettingsStoreMock.getValue.mockImplementation(makeMockGetValue({
|
||||
["Spaces.showPeopleInSpace"]: { [space1]: true },
|
||||
}));
|
||||
SettingsStoreMock.getValue.mockImplementation(
|
||||
makeMockGetValue({
|
||||
["Spaces.showPeopleInSpace"]: { [space1]: true },
|
||||
}),
|
||||
);
|
||||
const filter = initFilter(space1);
|
||||
const emitSpy = jest.spyOn(filter, 'emit');
|
||||
const emitSpy = jest.spyOn(filter, "emit");
|
||||
|
||||
SettingsStoreMock.getValue.mockClear().mockImplementation(makeMockGetValue({
|
||||
["Spaces.showPeopleInSpace"]: { [space1]: false },
|
||||
}));
|
||||
SettingsStoreMock.getValue.mockClear().mockImplementation(
|
||||
makeMockGetValue({
|
||||
["Spaces.showPeopleInSpace"]: { [space1]: false },
|
||||
}),
|
||||
);
|
||||
|
||||
SpaceStoreInstanceMock.emit(space1);
|
||||
jest.runOnlyPendingTimers();
|
||||
expect(emitSpy).toHaveBeenCalledWith(FILTER_CHANGED);
|
||||
});
|
||||
|
||||
it('emits filter changed event when setting is false and space changes to a meta space', async () => {
|
||||
it("emits filter changed event when setting is false and space changes to a meta space", async () => {
|
||||
// init filter with setting true for space1
|
||||
SettingsStoreMock.getValue.mockImplementation(makeMockGetValue({
|
||||
["Spaces.showPeopleInSpace"]: { [space1]: false },
|
||||
}));
|
||||
SettingsStoreMock.getValue.mockImplementation(
|
||||
makeMockGetValue({
|
||||
["Spaces.showPeopleInSpace"]: { [space1]: false },
|
||||
}),
|
||||
);
|
||||
const filter = initFilter(space1);
|
||||
const emitSpy = jest.spyOn(filter, 'emit');
|
||||
const emitSpy = jest.spyOn(filter, "emit");
|
||||
|
||||
filter.updateSpace(MetaSpace.Home);
|
||||
jest.runOnlyPendingTimers();
|
||||
|
@ -116,19 +125,19 @@ describe('SpaceFilterCondition', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('does not emit filter changed event on store update when nothing changed', async () => {
|
||||
it("does not emit filter changed event on store update when nothing changed", async () => {
|
||||
const filter = initFilter(space1);
|
||||
const emitSpy = jest.spyOn(filter, 'emit');
|
||||
const emitSpy = jest.spyOn(filter, "emit");
|
||||
SpaceStoreInstanceMock.emit(space1);
|
||||
jest.runOnlyPendingTimers();
|
||||
expect(emitSpy).not.toHaveBeenCalledWith(FILTER_CHANGED);
|
||||
});
|
||||
|
||||
it('removes listener when updateSpace is called', async () => {
|
||||
it("removes listener when updateSpace is called", async () => {
|
||||
const filter = initFilter(space1);
|
||||
filter.updateSpace(space2);
|
||||
jest.runOnlyPendingTimers();
|
||||
const emitSpy = jest.spyOn(filter, 'emit');
|
||||
const emitSpy = jest.spyOn(filter, "emit");
|
||||
|
||||
// update mock so filter would emit change if it was listening to space1
|
||||
SpaceStoreInstanceMock.getSpaceFilteredRoomIds.mockReturnValue(new Set([room1Id]));
|
||||
|
@ -138,11 +147,11 @@ describe('SpaceFilterCondition', () => {
|
|||
expect(emitSpy).not.toHaveBeenCalledWith(FILTER_CHANGED);
|
||||
});
|
||||
|
||||
it('removes listener when destroy is called', async () => {
|
||||
it("removes listener when destroy is called", async () => {
|
||||
const filter = initFilter(space1);
|
||||
filter.destroy();
|
||||
jest.runOnlyPendingTimers();
|
||||
const emitSpy = jest.spyOn(filter, 'emit');
|
||||
const emitSpy = jest.spyOn(filter, "emit");
|
||||
|
||||
// update mock so filter would emit change if it was listening to space1
|
||||
SpaceStoreInstanceMock.getSpaceFilteredRoomIds.mockReturnValue(new Set([room1Id]));
|
||||
|
@ -152,19 +161,19 @@ describe('SpaceFilterCondition', () => {
|
|||
expect(emitSpy).not.toHaveBeenCalledWith(FILTER_CHANGED);
|
||||
});
|
||||
|
||||
describe('when directChildRoomIds change', () => {
|
||||
describe("when directChildRoomIds change", () => {
|
||||
beforeEach(() => {
|
||||
SpaceStoreInstanceMock.getSpaceFilteredRoomIds.mockReturnValue(new Set([room1Id, room2Id]));
|
||||
});
|
||||
const filterChangedCases = [
|
||||
['room added', [room1Id, room2Id, room3Id]],
|
||||
['room removed', [room1Id]],
|
||||
['room swapped', [room1Id, room3Id]], // same number of rooms with changes
|
||||
["room added", [room1Id, room2Id, room3Id]],
|
||||
["room removed", [room1Id]],
|
||||
["room swapped", [room1Id, room3Id]], // same number of rooms with changes
|
||||
];
|
||||
|
||||
it.each(filterChangedCases)('%s', (_d, rooms) => {
|
||||
it.each(filterChangedCases)("%s", (_d, rooms) => {
|
||||
const filter = initFilter(space1);
|
||||
const emitSpy = jest.spyOn(filter, 'emit');
|
||||
const emitSpy = jest.spyOn(filter, "emit");
|
||||
|
||||
SpaceStoreInstanceMock.getSpaceFilteredRoomIds.mockReturnValue(new Set(rooms));
|
||||
SpaceStoreInstanceMock.emit(space1);
|
||||
|
@ -173,19 +182,19 @@ describe('SpaceFilterCondition', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('when user ids change', () => {
|
||||
describe("when user ids change", () => {
|
||||
beforeEach(() => {
|
||||
SpaceStoreInstanceMock.getSpaceFilteredUserIds.mockReturnValue(new Set([user1Id, user2Id]));
|
||||
});
|
||||
const filterChangedCases = [
|
||||
['user added', [user1Id, user2Id, user3Id]],
|
||||
['user removed', [user1Id]],
|
||||
['user swapped', [user1Id, user3Id]], // same number of rooms with changes
|
||||
["user added", [user1Id, user2Id, user3Id]],
|
||||
["user removed", [user1Id]],
|
||||
["user swapped", [user1Id, user3Id]], // same number of rooms with changes
|
||||
];
|
||||
|
||||
it.each(filterChangedCases)('%s', (_d, rooms) => {
|
||||
it.each(filterChangedCases)("%s", (_d, rooms) => {
|
||||
const filter = initFilter(space1);
|
||||
const emitSpy = jest.spyOn(filter, 'emit');
|
||||
const emitSpy = jest.spyOn(filter, "emit");
|
||||
|
||||
SpaceStoreInstanceMock.getSpaceFilteredUserIds.mockReturnValue(new Set(rooms));
|
||||
SpaceStoreInstanceMock.emit(space1);
|
||||
|
|
|
@ -43,7 +43,7 @@ jest.mock("../../../../src/customisations/RoomList", () => ({
|
|||
const createRoom = (isSpaceRoom = false): Room => {
|
||||
return {
|
||||
isSpaceRoom: () => isSpaceRoom,
|
||||
getType: () => isSpaceRoom ? RoomType.Space : undefined,
|
||||
getType: () => (isSpaceRoom ? RoomType.Space : undefined),
|
||||
} as unknown as Room;
|
||||
};
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ import { PollStartEventPreview } from "../../../../src/stores/room-list/previews
|
|||
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
||||
import { makePollStartEvent } from "../../../test-utils";
|
||||
|
||||
jest.spyOn(MatrixClientPeg, 'get').mockReturnValue({
|
||||
jest.spyOn(MatrixClientPeg, "get").mockReturnValue({
|
||||
getUserId: () => "@me:example.com",
|
||||
} as unknown as MatrixClient);
|
||||
|
||||
|
@ -37,4 +37,3 @@ describe("PollStartEventPreview", () => {
|
|||
expect(preview.getTextFor(pollStartEvent)).toBe("@yo:example.com: Your Question");
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -95,14 +95,12 @@ describe("StopGapWidget", () => {
|
|||
|
||||
describe(`and receiving a action:${ElementWidgetActions.JoinCall} message`, () => {
|
||||
beforeEach(async () => {
|
||||
messaging.on.mock.calls.find(
|
||||
([event, listener]) => {
|
||||
if (event === `action:${ElementWidgetActions.JoinCall}`) {
|
||||
listener();
|
||||
return true;
|
||||
}
|
||||
},
|
||||
);
|
||||
messaging.on.mock.calls.find(([event, listener]) => {
|
||||
if (event === `action:${ElementWidgetActions.JoinCall}`) {
|
||||
listener();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it("should pause the current voice broadcast recording", () => {
|
||||
|
|
|
@ -28,18 +28,19 @@ import { stubClient } from "../../test-utils";
|
|||
describe("StopGapWidgetDriver", () => {
|
||||
let client: MockedObject<MatrixClient>;
|
||||
|
||||
const mkDefaultDriver = (): WidgetDriver => new StopGapWidgetDriver(
|
||||
[],
|
||||
new Widget({
|
||||
id: "test",
|
||||
creatorUserId: "@alice:example.org",
|
||||
type: "example",
|
||||
url: "https://example.org",
|
||||
}),
|
||||
WidgetKind.Room,
|
||||
false,
|
||||
"!1:example.org",
|
||||
);
|
||||
const mkDefaultDriver = (): WidgetDriver =>
|
||||
new StopGapWidgetDriver(
|
||||
[],
|
||||
new Widget({
|
||||
id: "test",
|
||||
creatorUserId: "@alice:example.org",
|
||||
type: "example",
|
||||
url: "https://example.org",
|
||||
}),
|
||||
WidgetKind.Room,
|
||||
false,
|
||||
"!1:example.org",
|
||||
);
|
||||
|
||||
beforeEach(() => {
|
||||
stubClient();
|
||||
|
@ -107,7 +108,7 @@ describe("StopGapWidgetDriver", () => {
|
|||
},
|
||||
},
|
||||
"@bob:example.org": {
|
||||
"bobDesktop": {
|
||||
bobDesktop: {
|
||||
hello: "bob",
|
||||
},
|
||||
},
|
||||
|
@ -115,7 +116,9 @@ describe("StopGapWidgetDriver", () => {
|
|||
|
||||
let driver: WidgetDriver;
|
||||
|
||||
beforeEach(() => { driver = mkDefaultDriver(); });
|
||||
beforeEach(() => {
|
||||
driver = mkDefaultDriver();
|
||||
});
|
||||
|
||||
it("sends unencrypted messages", async () => {
|
||||
await driver.sendToDevice("org.example.foo", false, contentMap);
|
||||
|
@ -140,7 +143,9 @@ describe("StopGapWidgetDriver", () => {
|
|||
describe("getTurnServers", () => {
|
||||
let driver: WidgetDriver;
|
||||
|
||||
beforeEach(() => { driver = mkDefaultDriver(); });
|
||||
beforeEach(() => {
|
||||
driver = mkDefaultDriver();
|
||||
});
|
||||
|
||||
it("stops if VoIP isn't supported", async () => {
|
||||
jest.spyOn(client, "pollingTurnServers", "get").mockReturnValue(false);
|
||||
|
@ -199,77 +204,72 @@ describe("StopGapWidgetDriver", () => {
|
|||
describe("readEventRelations", () => {
|
||||
let driver: WidgetDriver;
|
||||
|
||||
beforeEach(() => { driver = mkDefaultDriver(); });
|
||||
beforeEach(() => {
|
||||
driver = mkDefaultDriver();
|
||||
});
|
||||
|
||||
it('reads related events from the current room', async () => {
|
||||
jest.spyOn(SdkContextClass.instance.roomViewStore, 'getRoomId').mockReturnValue('!this-room-id');
|
||||
it("reads related events from the current room", async () => {
|
||||
jest.spyOn(SdkContextClass.instance.roomViewStore, "getRoomId").mockReturnValue("!this-room-id");
|
||||
|
||||
client.relations.mockResolvedValue({
|
||||
originalEvent: new MatrixEvent(),
|
||||
events: [],
|
||||
});
|
||||
|
||||
await expect(driver.readEventRelations('$event')).resolves.toEqual({
|
||||
await expect(driver.readEventRelations("$event")).resolves.toEqual({
|
||||
chunk: [],
|
||||
nextBatch: undefined,
|
||||
prevBatch: undefined,
|
||||
});
|
||||
|
||||
expect(client.relations).toBeCalledWith('!this-room-id', '$event', null, null, {});
|
||||
expect(client.relations).toBeCalledWith("!this-room-id", "$event", null, null, {});
|
||||
});
|
||||
|
||||
it('reads related events from a selected room', async () => {
|
||||
it("reads related events from a selected room", async () => {
|
||||
client.relations.mockResolvedValue({
|
||||
originalEvent: new MatrixEvent(),
|
||||
events: [new MatrixEvent(), new MatrixEvent()],
|
||||
nextBatch: 'next-batch-token',
|
||||
nextBatch: "next-batch-token",
|
||||
});
|
||||
|
||||
await expect(driver.readEventRelations('$event', '!room-id')).resolves.toEqual({
|
||||
chunk: [
|
||||
expect.objectContaining({ content: {} }),
|
||||
expect.objectContaining({ content: {} }),
|
||||
],
|
||||
nextBatch: 'next-batch-token',
|
||||
await expect(driver.readEventRelations("$event", "!room-id")).resolves.toEqual({
|
||||
chunk: [expect.objectContaining({ content: {} }), expect.objectContaining({ content: {} })],
|
||||
nextBatch: "next-batch-token",
|
||||
prevBatch: undefined,
|
||||
});
|
||||
|
||||
expect(client.relations).toBeCalledWith('!room-id', '$event', null, null, {});
|
||||
expect(client.relations).toBeCalledWith("!room-id", "$event", null, null, {});
|
||||
});
|
||||
|
||||
it('reads related events with custom parameters', async () => {
|
||||
it("reads related events with custom parameters", async () => {
|
||||
client.relations.mockResolvedValue({
|
||||
originalEvent: new MatrixEvent(),
|
||||
events: [],
|
||||
});
|
||||
|
||||
await expect(driver.readEventRelations(
|
||||
'$event',
|
||||
'!room-id',
|
||||
'm.reference',
|
||||
'm.room.message',
|
||||
'from-token',
|
||||
'to-token',
|
||||
25,
|
||||
'f',
|
||||
)).resolves.toEqual({
|
||||
await expect(
|
||||
driver.readEventRelations(
|
||||
"$event",
|
||||
"!room-id",
|
||||
"m.reference",
|
||||
"m.room.message",
|
||||
"from-token",
|
||||
"to-token",
|
||||
25,
|
||||
"f",
|
||||
),
|
||||
).resolves.toEqual({
|
||||
chunk: [],
|
||||
nextBatch: undefined,
|
||||
prevBatch: undefined,
|
||||
});
|
||||
|
||||
expect(client.relations).toBeCalledWith(
|
||||
'!room-id',
|
||||
'$event',
|
||||
'm.reference',
|
||||
'm.room.message',
|
||||
{
|
||||
limit: 25,
|
||||
from: 'from-token',
|
||||
to: 'to-token',
|
||||
dir: Direction.Forward,
|
||||
},
|
||||
);
|
||||
expect(client.relations).toBeCalledWith("!room-id", "$event", "m.reference", "m.room.message", {
|
||||
limit: 25,
|
||||
from: "from-token",
|
||||
to: "to-token",
|
||||
dir: Direction.Forward,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -45,15 +45,13 @@ describe("WidgetPermissionStore", () => {
|
|||
mocked(SettingsStore.getValue).mockImplementation((setting: string) => {
|
||||
return settings[setting];
|
||||
});
|
||||
mocked(SettingsStore.setValue).mockImplementation((settingName: string,
|
||||
roomId: string | null,
|
||||
level: SettingLevel,
|
||||
value: any,
|
||||
): Promise<void> => {
|
||||
// the store doesn't use any specific level or room ID (room IDs are packed into keys in `value`)
|
||||
settings[settingName] = value;
|
||||
return Promise.resolve();
|
||||
});
|
||||
mocked(SettingsStore.setValue).mockImplementation(
|
||||
(settingName: string, roomId: string | null, level: SettingLevel, value: any): Promise<void> => {
|
||||
// the store doesn't use any specific level or room ID (room IDs are packed into keys in `value`)
|
||||
settings[settingName] = value;
|
||||
return Promise.resolve();
|
||||
},
|
||||
);
|
||||
mockClient = stubClient();
|
||||
const context = new TestSdkContext();
|
||||
context.client = mockClient;
|
||||
|
@ -63,39 +61,29 @@ describe("WidgetPermissionStore", () => {
|
|||
it("should persist OIDCState.Allowed for a widget", () => {
|
||||
widgetPermissionStore.setOIDCState(w, WidgetKind.Account, null, OIDCState.Allowed);
|
||||
// check it remembered the value
|
||||
expect(
|
||||
widgetPermissionStore.getOIDCState(w, WidgetKind.Account, null),
|
||||
).toEqual(OIDCState.Allowed);
|
||||
expect(widgetPermissionStore.getOIDCState(w, WidgetKind.Account, null)).toEqual(OIDCState.Allowed);
|
||||
});
|
||||
|
||||
it("should persist OIDCState.Denied for a widget", () => {
|
||||
widgetPermissionStore.setOIDCState(w, WidgetKind.Account, null, OIDCState.Denied);
|
||||
// check it remembered the value
|
||||
expect(
|
||||
widgetPermissionStore.getOIDCState(w, WidgetKind.Account, null),
|
||||
).toEqual(OIDCState.Denied);
|
||||
expect(widgetPermissionStore.getOIDCState(w, WidgetKind.Account, null)).toEqual(OIDCState.Denied);
|
||||
});
|
||||
|
||||
it("should update OIDCState for a widget", () => {
|
||||
widgetPermissionStore.setOIDCState(w, WidgetKind.Account, null, OIDCState.Allowed);
|
||||
widgetPermissionStore.setOIDCState(w, WidgetKind.Account, null, OIDCState.Denied);
|
||||
// check it remembered the latest value
|
||||
expect(
|
||||
widgetPermissionStore.getOIDCState(w, WidgetKind.Account, null),
|
||||
).toEqual(OIDCState.Denied);
|
||||
expect(widgetPermissionStore.getOIDCState(w, WidgetKind.Account, null)).toEqual(OIDCState.Denied);
|
||||
});
|
||||
|
||||
it("should scope the location for a widget when setting OIDC state", () => {
|
||||
// allow this widget for this room
|
||||
widgetPermissionStore.setOIDCState(w, WidgetKind.Room, roomId, OIDCState.Allowed);
|
||||
// check it remembered the value
|
||||
expect(
|
||||
widgetPermissionStore.getOIDCState(w, WidgetKind.Room, roomId),
|
||||
).toEqual(OIDCState.Allowed);
|
||||
expect(widgetPermissionStore.getOIDCState(w, WidgetKind.Room, roomId)).toEqual(OIDCState.Allowed);
|
||||
// check this is not the case for the entire account
|
||||
expect(
|
||||
widgetPermissionStore.getOIDCState(w, WidgetKind.Account, roomId),
|
||||
).toEqual(OIDCState.Unknown);
|
||||
expect(widgetPermissionStore.getOIDCState(w, WidgetKind.Account, roomId)).toEqual(OIDCState.Unknown);
|
||||
});
|
||||
it("is created once in SdkContextClass", () => {
|
||||
const context = new SdkContextClass();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue