Allow setting knock room directory visibility (#11529)
* Allow setting knock room directory visibility Signed-off-by: Charly Nguyen <charly.nguyen@nordeck.net> * Apply PR feedback Signed-off-by: Charly Nguyen <charly.nguyen@nordeck.net> --------- Signed-off-by: Charly Nguyen <charly.nguyen@nordeck.net>
This commit is contained in:
parent
77b681eed9
commit
0059c7c1ee
4 changed files with 122 additions and 6 deletions
|
@ -15,7 +15,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import React from "react";
|
||||
import { fireEvent, render, screen, within } from "@testing-library/react";
|
||||
import { act, fireEvent, render, screen, within } from "@testing-library/react";
|
||||
import {
|
||||
EventType,
|
||||
GuestAccess,
|
||||
|
@ -25,6 +25,8 @@ import {
|
|||
Room,
|
||||
ClientEvent,
|
||||
RoomMember,
|
||||
MatrixError,
|
||||
Visibility,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { defer, IDeferred } from "matrix-js-sdk/src/utils";
|
||||
|
||||
|
@ -51,6 +53,8 @@ describe("<JoinRuleSettings />", () => {
|
|||
getProfileInfo: jest.fn(),
|
||||
invite: jest.fn().mockResolvedValue(undefined),
|
||||
isRoomEncrypted: jest.fn().mockReturnValue(false),
|
||||
getRoomDirectoryVisibility: jest.fn(),
|
||||
setRoomDirectoryVisibility: jest.fn(),
|
||||
});
|
||||
const roomId = "!room:server.org";
|
||||
const newRoomId = "!roomUpgraded:server.org";
|
||||
|
@ -270,10 +274,77 @@ describe("<JoinRuleSettings />", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("knock rooms directory visibility", () => {
|
||||
const getCheckbox = () => screen.getByRole("checkbox");
|
||||
let room: Room;
|
||||
|
||||
beforeEach(() => (room = new Room(roomId, client, userId)));
|
||||
|
||||
describe("when join rule is knock", () => {
|
||||
beforeEach(() => setRoomStateEvents(room, PreferredRoomVersions.KnockRooms, JoinRule.Knock));
|
||||
|
||||
it("should set the visibility to public", async () => {
|
||||
jest.spyOn(client, "getRoomDirectoryVisibility").mockResolvedValue({ visibility: Visibility.Private });
|
||||
jest.spyOn(client, "setRoomDirectoryVisibility").mockResolvedValue({});
|
||||
getComponent({ room });
|
||||
fireEvent.click(getCheckbox());
|
||||
await act(async () => await flushPromises());
|
||||
expect(client.setRoomDirectoryVisibility).toHaveBeenCalledWith(roomId, Visibility.Public);
|
||||
expect(getCheckbox()).toBeChecked();
|
||||
});
|
||||
|
||||
it("should set the visibility to private", async () => {
|
||||
jest.spyOn(client, "getRoomDirectoryVisibility").mockResolvedValue({ visibility: Visibility.Public });
|
||||
jest.spyOn(client, "setRoomDirectoryVisibility").mockResolvedValue({});
|
||||
getComponent({ room });
|
||||
await act(async () => await flushPromises());
|
||||
fireEvent.click(getCheckbox());
|
||||
await act(async () => await flushPromises());
|
||||
expect(client.setRoomDirectoryVisibility).toHaveBeenCalledWith(roomId, Visibility.Private);
|
||||
expect(getCheckbox()).not.toBeChecked();
|
||||
});
|
||||
|
||||
it("should call onError if setting visibility fails", async () => {
|
||||
const error = new MatrixError();
|
||||
jest.spyOn(client, "getRoomDirectoryVisibility").mockResolvedValue({ visibility: Visibility.Private });
|
||||
jest.spyOn(client, "setRoomDirectoryVisibility").mockRejectedValue(error);
|
||||
getComponent({ room });
|
||||
fireEvent.click(getCheckbox());
|
||||
await act(async () => await flushPromises());
|
||||
expect(getCheckbox()).not.toBeChecked();
|
||||
expect(defaultProps.onError).toHaveBeenCalledWith(error);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when the room version is unsupported and upgrade is enabled", () => {
|
||||
it("should disable the checkbox", () => {
|
||||
setRoomStateEvents(room, "6", JoinRule.Invite);
|
||||
getComponent({ promptUpgrade: true, room });
|
||||
expect(getCheckbox()).toBeDisabled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("when join rule is not knock", () => {
|
||||
beforeEach(() => {
|
||||
setRoomStateEvents(room, PreferredRoomVersions.KnockRooms, JoinRule.Invite);
|
||||
getComponent({ room });
|
||||
});
|
||||
|
||||
it("should disable the checkbox", () => {
|
||||
expect(getCheckbox()).toBeDisabled();
|
||||
});
|
||||
|
||||
it("should set the visibility to private by default", () => {
|
||||
expect(getCheckbox()).not.toBeChecked();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("should not show knock room join rule", async () => {
|
||||
jest.spyOn(SettingsStore, "getValue").mockReturnValue(false);
|
||||
const room = new Room(newRoomId, client, userId);
|
||||
getComponent({ room: room });
|
||||
setRoomStateEvents(room, PreferredRoomVersions.KnockRooms);
|
||||
getComponent({ room });
|
||||
expect(screen.queryByText("Ask to join")).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue