Skip to content

Commit b4d3c7c

Browse files
committed
fix tests
1 parent d18a145 commit b4d3c7c

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/components/views/rooms/RoomHeader/CallGuestLinkButton.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { calculateRoomVia } from "../../../../utils/permalinks/Permalinks";
1818
import BaseDialog from "../../dialogs/BaseDialog";
1919
import { useGuestAccessInformation } from "../../../../hooks/room/useGuestAccessInformation";
2020
import JoinRuleSettings from "../../settings/JoinRuleSettings";
21+
import SettingsStore from "../../../../settings/SettingsStore";
2122

2223
/**
2324
* Display a button to open a dialog to share a link to the call using a element call guest spa url (`element_call:guest_spa_url` in the EW config).
@@ -99,6 +100,7 @@ export const JoinRuleDialog: React.FC<{
99100
room: Room;
100101
canInvite: boolean;
101102
}> = ({ onFinished, room, canInvite }) => {
103+
const askToJoinEnabled = SettingsStore.getValue("feature_ask_to_join");
102104
const [isUpdating, setIsUpdating] = React.useState<undefined | JoinRule>(undefined);
103105
const changeJoinRule = useCallback(
104106
async (newRule: JoinRule) => {
@@ -127,7 +129,9 @@ export const JoinRuleDialog: React.FC<{
127129
recommendedOption={JoinRule.Knock}
128130
room={room}
129131
disabledOptions={new Set([JoinRule.Invite, JoinRule.Private, JoinRule.Restricted])}
130-
hiddenOptions={new Set([JoinRule.Restricted])}
132+
hiddenOptions={
133+
new Set([JoinRule.Restricted].concat(askToJoinEnabled && canInvite ? [] : [JoinRule.Knock]))
134+
}
131135
beforeChange={async (newRule) => {
132136
await changeJoinRule(newRule).catch(() => {
133137
return false;

test/unit-tests/components/views/rooms/RoomHeader/CallGuestLinkButton-test.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ describe("<CallGuestLinkButton />", () => {
4646
*/
4747
const makeRoom = (isVideoRoom = true): Room => {
4848
const room = new Room(roomId, sdkContext.client!, sdkContext.client!.getSafeUserId());
49+
sdkContext.client!.getRoomDirectoryVisibility = jest.fn().mockResolvedValue("public");
4950
jest.spyOn(room, "isElementVideoRoom").mockReturnValue(isVideoRoom);
5051
// stub
5152
jest.spyOn(room, "getPendingEvents").mockReturnValue([]);
53+
jest.spyOn(room, "getVersion").mockReturnValue("9");
5254
return room;
5355
};
5456
function mockRoomMembers(room: Room, count: number) {
@@ -221,32 +223,33 @@ describe("<CallGuestLinkButton />", () => {
221223
});
222224

223225
it("shows ask to join if feature is enabled", () => {
224-
const { container } = getComponent(room);
225-
expect(getByText(container, "Ask to join")).toBeInTheDocument();
226+
getComponent(room);
227+
expect(screen.getByRole("radio", { name: "Ask to join ( Recommended )" })).toBeInTheDocument();
226228
});
227-
it("font show ask to join if feature is enabled but cannot invite", () => {
229+
it("dont show ask to join if feature is enabled but cannot invite", () => {
228230
getComponent(room, false);
229-
expect(screen.queryByText("Ask to join")).not.toBeInTheDocument();
231+
expect(screen.queryByRole("radio", { name: "Ask to join ( Recommended )" })).not.toBeInTheDocument();
230232
});
231233
it("doesn't show ask to join if feature is disabled", () => {
232234
jest.spyOn(SettingsStore, "getValue").mockReturnValue(false);
233235
getComponent(room);
234-
expect(screen.queryByText("Ask to join")).not.toBeInTheDocument();
236+
expect(screen.queryByRole("radio", { name: "Ask to join ( Recommended )" })).not.toBeInTheDocument();
235237
});
236238

237239
it("sends correct state event on click", async () => {
238240
const sendStateSpy = jest.spyOn(sdkContext.client!, "sendStateEvent");
241+
239242
let container;
240243
container = getComponent(room).container;
241-
fireEvent.click(getByText(container, "Ask to join"));
244+
fireEvent.click(screen.getByRole("radio", { name: "Ask to join ( Recommended )" }));
242245
expect(sendStateSpy).toHaveBeenCalledWith(
243246
"!room:server.org",
244247
"m.room.join_rules",
245248
{ join_rule: "knock" },
246249
"",
247250
);
248251
expect(sendStateSpy).toHaveBeenCalledTimes(1);
249-
await waitFor(() => expect(onFinished).toHaveBeenCalledTimes(1));
252+
await waitFor(() => expect(onFinished).toHaveBeenCalledTimes(1), { timeout: 3000 });
250253
onFinished.mockClear();
251254
sendStateSpy.mockClear();
252255

@@ -260,7 +263,7 @@ describe("<CallGuestLinkButton />", () => {
260263
);
261264
expect(sendStateSpy).toHaveBeenCalledTimes(1);
262265
container = getComponent(room).container;
263-
await waitFor(() => expect(onFinished).toHaveBeenCalledTimes(1));
266+
await waitFor(() => expect(onFinished).toHaveBeenCalledTimes(1), { timeout: 1010 });
264267
onFinished.mockClear();
265268
sendStateSpy.mockClear();
266269

0 commit comments

Comments
 (0)