Apply prettier formatting
This commit is contained in:
parent
1cac306093
commit
526645c791
1576 changed files with 65385 additions and 62478 deletions
|
@ -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");
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue