You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-07-31 13:44:28 +03:00
Show knock rooms in the list (#11573)
* Show knock rooms in the list Signed-off-by: Mikhail Aheichyk <mikhail.aheichyk@nordeck.net> * Pass userId to IndexedDBStore Signed-off-by: Mikhail Aheichyk <mikhail.aheichyk@nordeck.net> * Revert "Pass userId to IndexedDBStore" Signed-off-by: Mikhail Aheichyk <mikhail.aheichyk@nordeck.net> * Code review changes Signed-off-by: Mikhail Aheichyk <mikhail.aheichyk@nordeck.net> --------- Signed-off-by: Mikhail Aheichyk <mikhail.aheichyk@nordeck.net> Co-authored-by: Mikhail Aheichyk <mikhail.aheichyk@nordeck.net>
This commit is contained in:
@ -27,7 +27,7 @@ import {
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
import { mkEvent, mkRoom, muteRoom, stubClient, upsertRoomStateEvents } from "./test-utils";
|
||||
import { mkEvent, mkRoom, mkRoomMember, muteRoom, stubClient, upsertRoomStateEvents } from "./test-utils";
|
||||
import {
|
||||
getRoomNotifsState,
|
||||
RoomNotifState,
|
||||
@ -36,6 +36,7 @@ import {
|
||||
} from "../src/RoomNotifs";
|
||||
import { NotificationColor } from "../src/stores/notifications/NotificationColor";
|
||||
import SettingsStore from "../src/settings/SettingsStore";
|
||||
import { MatrixClientPeg } from "../src/MatrixClientPeg";
|
||||
|
||||
describe("RoomNotifs test", () => {
|
||||
let client: jest.Mocked<MatrixClient>;
|
||||
@ -285,6 +286,21 @@ describe("RoomNotifs test", () => {
|
||||
expect(count).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("indicates the user knock has been denied", async () => {
|
||||
jest.spyOn(SettingsStore, "getValue").mockImplementation((name) => {
|
||||
return name === "feature_ask_to_join";
|
||||
});
|
||||
const roomMember = mkRoomMember(room.roomId, MatrixClientPeg.get()!.getSafeUserId(), "leave", true, {
|
||||
membership: "knock",
|
||||
});
|
||||
jest.spyOn(room, "getMember").mockReturnValue(roomMember);
|
||||
const { color, symbol, count } = determineUnreadState(room);
|
||||
|
||||
expect(symbol).toBe("!");
|
||||
expect(color).toBe(NotificationColor.Red);
|
||||
expect(count).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("shows nothing for muted channels", async () => {
|
||||
room.setUnreadNotificationCount(NotificationCountType.Highlight, 99);
|
||||
room.setUnreadNotificationCount(NotificationCountType.Total, 99);
|
||||
|
@ -27,4 +27,12 @@ describe("StatelessNotificationBadge", () => {
|
||||
);
|
||||
expect(container.querySelector(".mx_NotificationBadge_highlighted")).not.toBe(null);
|
||||
});
|
||||
|
||||
it("has knock style", () => {
|
||||
const { container } = render(
|
||||
<StatelessNotificationBadge symbol="!" count={0} color={NotificationColor.Red} knocked={true} />,
|
||||
);
|
||||
expect(container.querySelector(".mx_NotificationBadge_dot")).not.toBeInTheDocument();
|
||||
expect(container.querySelector(".mx_NotificationBadge_knocked")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
@ -54,6 +54,8 @@ import { SDKContext } from "../../../../src/contexts/SDKContext";
|
||||
import { shouldShowComponent } from "../../../../src/customisations/helpers/UIComponents";
|
||||
import { UIComponent } from "../../../../src/settings/UIFeature";
|
||||
import { MessagePreviewStore } from "../../../../src/stores/room-list/MessagePreviewStore";
|
||||
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
||||
import SettingsStore from "../../../../src/settings/SettingsStore";
|
||||
|
||||
jest.mock("../../../../src/customisations/helpers/UIComponents", () => ({
|
||||
shouldShowComponent: jest.fn(),
|
||||
@ -160,8 +162,9 @@ describe("RoomTile", () => {
|
||||
describe("when message previews are not enabled", () => {
|
||||
it("should render the room", () => {
|
||||
mocked(shouldShowComponent).mockReturnValue(true);
|
||||
const renderResult = renderRoomTile();
|
||||
expect(renderResult.container).toMatchSnapshot();
|
||||
const { container } = renderRoomTile();
|
||||
expect(container).toMatchSnapshot();
|
||||
expect(container.querySelector(".mx_RoomTile_sticky")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("does not render the room options context menu when UIComponent customisations disable room options", () => {
|
||||
@ -178,6 +181,31 @@ describe("RoomTile", () => {
|
||||
expect(screen.queryByRole("button", { name: "Room options" })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("does not render the room options context menu when knocked to the room", () => {
|
||||
jest.spyOn(SettingsStore, "getValue").mockImplementation((name) => {
|
||||
return name === "feature_ask_to_join";
|
||||
});
|
||||
mocked(shouldShowComponent).mockReturnValue(true);
|
||||
jest.spyOn(room, "getMyMembership").mockReturnValue("knock");
|
||||
const { container } = renderRoomTile();
|
||||
expect(container.querySelector(".mx_RoomTile_sticky")).toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: "Room options" })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("does not render the room options context menu when knock has been denied", () => {
|
||||
jest.spyOn(SettingsStore, "getValue").mockImplementation((name) => {
|
||||
return name === "feature_ask_to_join";
|
||||
});
|
||||
mocked(shouldShowComponent).mockReturnValue(true);
|
||||
const roomMember = mkRoomMember(room.roomId, MatrixClientPeg.get()!.getSafeUserId(), "leave", true, {
|
||||
membership: "knock",
|
||||
});
|
||||
jest.spyOn(room, "getMember").mockReturnValue(roomMember);
|
||||
const { container } = renderRoomTile();
|
||||
expect(container.querySelector(".mx_RoomTile_sticky")).toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: "Room options" })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
describe("when a call starts", () => {
|
||||
let call: MockedCall;
|
||||
let widget: Widget;
|
||||
|
@ -464,14 +464,26 @@ export function mkMembership(
|
||||
return e;
|
||||
}
|
||||
|
||||
export function mkRoomMember(roomId: string, userId: string, membership = "join"): RoomMember {
|
||||
export function mkRoomMember(
|
||||
roomId: string,
|
||||
userId: string,
|
||||
membership = "join",
|
||||
isKicked = false,
|
||||
prevMemberContent: Partial<IContent> = {},
|
||||
): RoomMember {
|
||||
return {
|
||||
userId,
|
||||
membership,
|
||||
name: userId,
|
||||
rawDisplayName: userId,
|
||||
roomId,
|
||||
events: {},
|
||||
events: {
|
||||
member: {
|
||||
getSender: () => undefined,
|
||||
getPrevContent: () => prevMemberContent,
|
||||
},
|
||||
},
|
||||
isKicked: () => isKicked,
|
||||
getAvatarUrl: () => {},
|
||||
getMxcAvatarUrl: () => {},
|
||||
getDMInviter: () => {},
|
||||
@ -597,6 +609,8 @@ export function mkStubRoom(
|
||||
roomId: roomId,
|
||||
getAvatarUrl: () => "mxc://avatar.url/image.png",
|
||||
getMxcAvatarUrl: () => "mxc://avatar.url/image.png",
|
||||
events: {},
|
||||
isKicked: () => false,
|
||||
}),
|
||||
getMembers: jest.fn().mockReturnValue([]),
|
||||
getMembersWithMembership: jest.fn().mockReturnValue([]),
|
||||
|
@ -17,8 +17,36 @@ limitations under the License.
|
||||
import { MatrixClient, MatrixEvent, Room, RoomMember, RoomState, RoomStateEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { mocked } from "jest-mock";
|
||||
|
||||
import { waitForMember } from "../../src/utils/membership";
|
||||
import { createTestClient } from "../test-utils";
|
||||
import { isKnockDenied, waitForMember } from "../../src/utils/membership";
|
||||
import { createTestClient, mkRoomMember, stubClient } from "../test-utils";
|
||||
|
||||
describe("isKnockDenied", () => {
|
||||
const userId = "alice";
|
||||
let client: jest.Mocked<MatrixClient>;
|
||||
let room: Room;
|
||||
|
||||
beforeEach(() => {
|
||||
client = stubClient() as jest.Mocked<MatrixClient>;
|
||||
room = new Room("!room-id:example.com", client, "@user:example.com");
|
||||
});
|
||||
|
||||
it("checks that the user knock has been denied", () => {
|
||||
const roomMember = mkRoomMember(room.roomId, userId, "leave", true, { membership: "knock" });
|
||||
jest.spyOn(room, "getMember").mockReturnValue(roomMember);
|
||||
expect(isKnockDenied(room)).toBe(true);
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ membership: "leave", isKicked: false, prevMembership: "invite" },
|
||||
{ membership: "leave", isKicked: true, prevMembership: "invite" },
|
||||
{ membership: "leave", isKicked: false, prevMembership: "join" },
|
||||
{ membership: "leave", isKicked: true, prevMembership: "join" },
|
||||
])("checks that the user knock has been not denied", ({ membership, isKicked, prevMembership }) => {
|
||||
const roomMember = mkRoomMember(room.roomId, userId, membership, isKicked, { membership: prevMembership });
|
||||
jest.spyOn(room, "getMember").mockReturnValue(roomMember);
|
||||
expect(isKnockDenied(room)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
/* Shorter timeout, we've got tests to run */
|
||||
const timeout = 30;
|
||||
|
Reference in New Issue
Block a user