RLS: Remove forgotten room from skiplist (#29933)
* Dispatch an action when room is forgotten * Dispatch an action when room is forgotten * Remove room on action * Add test * Write test for matrixchat * Add payload info to comment
This commit is contained in:
@@ -69,6 +69,7 @@ import { type ValidatedServerConfig } from "../../../../src/utils/ValidatedServe
|
||||
import Modal from "../../../../src/Modal.tsx";
|
||||
import { SetupEncryptionStore } from "../../../../src/stores/SetupEncryptionStore.ts";
|
||||
import { clearStorage } from "../../../../src/Lifecycle";
|
||||
import RoomListStore from "../../../../src/stores/room-list/RoomListStore.ts";
|
||||
|
||||
jest.mock("matrix-js-sdk/src/oidc/authorize", () => ({
|
||||
completeAuthorizationCodeGrant: jest.fn(),
|
||||
@@ -155,6 +156,7 @@ describe("<MatrixChat />", () => {
|
||||
whoami: jest.fn(),
|
||||
logout: jest.fn(),
|
||||
getDeviceId: jest.fn(),
|
||||
forget: () => Promise.resolve(),
|
||||
});
|
||||
let mockClient: Mocked<MatrixClient>;
|
||||
const serverConfig = {
|
||||
@@ -675,6 +677,34 @@ describe("<MatrixChat />", () => {
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
describe("forget_room", () => {
|
||||
it("should dispatch after_forget_room action on successful forget", async () => {
|
||||
await clearAllModals();
|
||||
await getComponentAndWaitForReady();
|
||||
|
||||
// Mock out the old room list store
|
||||
jest.spyOn(RoomListStore.instance, "manualRoomUpdate").mockImplementation(async () => {});
|
||||
|
||||
// Register a mock function to the dispatcher
|
||||
const fn = jest.fn();
|
||||
defaultDispatcher.register(fn);
|
||||
|
||||
// Forge the room
|
||||
defaultDispatcher.dispatch({
|
||||
action: "forget_room",
|
||||
room_id: roomId,
|
||||
});
|
||||
|
||||
// On success, we expect the following action to have been dispatched.
|
||||
await waitFor(() => {
|
||||
expect(fn).toHaveBeenCalledWith({
|
||||
action: Action.AfterForgetRoom,
|
||||
room: room,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("leave_room", () => {
|
||||
beforeEach(async () => {
|
||||
await clearAllModals();
|
||||
|
||||
@@ -27,6 +27,7 @@ import { SortingAlgorithm } from "../../../../src/stores/room-list-v3/skip-list/
|
||||
import SettingsStore from "../../../../src/settings/SettingsStore";
|
||||
import * as utils from "../../../../src/utils/notifications";
|
||||
import * as roomMute from "../../../../src/stores/room-list/utils/roomMute";
|
||||
import { Action } from "../../../../src/dispatcher/actions";
|
||||
|
||||
describe("RoomListStoreV3", () => {
|
||||
async function getRoomListStore() {
|
||||
@@ -121,6 +122,27 @@ describe("RoomListStoreV3", () => {
|
||||
expect(store.getSortedRooms()[0].roomId).toEqual(room.roomId);
|
||||
});
|
||||
|
||||
it("Forgotten room is removed", async () => {
|
||||
const { store, rooms, dispatcher } = await getRoomListStore();
|
||||
const room = rooms[37];
|
||||
|
||||
// Room at index 37 should be in the store now
|
||||
expect(store.getSortedRooms().map((r) => r.roomId)).toContain(room.roomId);
|
||||
|
||||
// Forget room at index 37
|
||||
const payload = {
|
||||
action: Action.AfterForgetRoom,
|
||||
room: room,
|
||||
};
|
||||
const fn = jest.fn();
|
||||
store.on(LISTS_UPDATE_EVENT, fn);
|
||||
dispatcher.dispatch(payload, true);
|
||||
|
||||
// Room at index 37 should no longer be in the store
|
||||
expect(fn).toHaveBeenCalled();
|
||||
expect(store.getSortedRooms().map((r) => r.roomId)).not.toContain(room.roomId);
|
||||
});
|
||||
|
||||
it.each([KnownMembership.Join, KnownMembership.Invite])(
|
||||
"Room is removed when membership changes to leave",
|
||||
async (membership) => {
|
||||
|
||||
Reference in New Issue
Block a user