Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
add tests for share call button
Browse files Browse the repository at this point in the history
Signed-off-by: Timo K <[email protected]>
  • Loading branch information
toger5 committed Feb 26, 2024
1 parent 18d7dc8 commit d4e1d86
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/hooks/room/useRoomCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export const useRoomCall = (
return [PlatformCallType.ElementCall];
}
if (hasGroupCall && WidgetType.CALL.matches(groupCall.widget.type)) {
// only allow joining joining the ongoing Element call if there is one.
// only allow joining the ongoing Element call if there is one.
return [PlatformCallType.ElementCall];
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -2897,7 +2897,7 @@
"permalink_message": "Link to selected message",
"permalink_most_recent": "Link to most recent message",
"share_call": "Conference invite link",
"share_call_subtitle": "Link for external users to join the call without matrix account:",
"share_call_subtitle": "Link for external users to join the call without a matrix account:",
"title_link": "Share Link",
"title_message": "Share Room Message",
"title_room": "Share Room",
Expand Down
60 changes: 59 additions & 1 deletion test/components/views/rooms/RoomHeader-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ import { _t } from "../../../../src/languageHandler";
import * as UseCall from "../../../../src/hooks/useCall";
import { SdkContextClass } from "../../../../src/contexts/SDKContext";
import WidgetStore, { IApp } from "../../../../src/stores/WidgetStore";
import ShareDialog from "../../../../src/components/views/dialogs/ShareDialog";
import Modal from "../../../../src/Modal";
jest.mock("../../../../src/utils/ShieldUtils");

function getWrapper(): RenderOptions {
Expand Down Expand Up @@ -493,10 +495,18 @@ describe("RoomHeader", () => {
});

describe("External conference", () => {
const oldGet = SdkConfig.get;
beforeEach(() => {
jest.spyOn(SdkConfig, "get").mockImplementation((key) => {
if (key === "element_call") {
return { guest_spa_url: "https://guest_spa_url.com", url: "https://spa_url.com" };
}
return oldGet(key);
});
mockRoomMembers(room, 3);
jest.spyOn(SdkContextClass.instance.roomViewStore, "isViewingCall").mockReturnValue(true);
});

it("shows the external conference if the room has public join rules", () => {
jest.spyOn(room, "getJoinRule").mockReturnValue(JoinRule.Public);

Expand All @@ -511,7 +521,7 @@ describe("RoomHeader", () => {
expect(getByLabelText(container, _t("voip|get_call_link"))).toBeInTheDocument();
});

it("don't show External conference if the call is not shown", () => {
it("don't show external conference button if the call is not shown", () => {
jest.spyOn(room, "getJoinRule").mockReturnValue(JoinRule.Public);
jest.spyOn(SdkContextClass.instance.roomViewStore, "isViewingCall").mockReturnValue(false);

Expand All @@ -524,6 +534,54 @@ describe("RoomHeader", () => {

expect(getByLabelText(container, _t("voip|get_call_link"))).toBeInTheDocument();
});

it("don't show external conference button if now guest spa link is configured", () => {
jest.spyOn(room, "getJoinRule").mockReturnValue(JoinRule.Public);
jest.spyOn(SdkContextClass.instance.roomViewStore, "isViewingCall").mockReturnValue(true);

jest.spyOn(SdkConfig, "get").mockImplementation((key) => {
if (key === "element_call") {
return { url: "https://example2.com" };
}
return oldGet(key);
});

render(<RoomHeader room={room} />, getWrapper());

// We only change the SdkConfig and show that this everything else is
// configured so that the call link button is shown.

jest.spyOn(SdkConfig, "get").mockImplementation((key) => {
if (key === "element_call") {
return { guest_spa_url: "https://guest_spa_url.com", url: "https://example2.com" };
}
return oldGet(key);
});

expect(screen.queryByLabelText(_t("voip|get_call_link"))).not.toBeInTheDocument();
const { container } = render(<RoomHeader room={room} />, getWrapper());
expect(getByLabelText(container, _t("voip|get_call_link"))).toBeInTheDocument();
});
it("opens the share dialog with the correct share link", () => {
jest.spyOn(room, "getJoinRule").mockReturnValue(JoinRule.Public);
jest.spyOn(SdkContextClass.instance.roomViewStore, "isViewingCall").mockReturnValue(true);

const { container } = render(<RoomHeader room={room} />, getWrapper());
const modalSpy = jest.spyOn(Modal, "createDialog");
fireEvent.click(getByLabelText(container, _t("voip|get_call_link")));
const target =
"https://guest_spa_url.com/room/#/!1:example.org?roomId=%211%3Aexample.org&perParticipantE2EE=true&viaServers=example.org";
expect(modalSpy).toHaveBeenCalled();
const arg0 = modalSpy.mock.calls[0][0];
const arg1 = modalSpy.mock.calls[0][1] as any;
expect(arg0).toEqual(ShareDialog);
const { customTitle, subtitle } = arg1;
expect({ customTitle, subtitle }).toEqual({
customTitle: "Conference invite link",
subtitle: _t("share|share_call_subtitle"),
});
expect(arg1.target.toString()).toEqual(target);
});
});

describe("public room", () => {
Expand Down

0 comments on commit d4e1d86

Please sign in to comment.