Skip to content

Commit

Permalink
Merge pull request #1196 from tchapgouv/1187-copy-link-behavior
Browse files Browse the repository at this point in the history
TCHAP: add disabled behavior on copy room link when joinrule is invite
  • Loading branch information
MarcWadai authored Jan 7, 2025
2 parents db5a8ae + e5b4fc3 commit cd4646b
Show file tree
Hide file tree
Showing 7 changed files with 991 additions and 3 deletions.
8 changes: 7 additions & 1 deletion patches/tchap-modifications.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,17 @@
"src/LegacyCallHandler.tsx"
]
},
"copy-link-room-behavior": {
"issue": "https://github.com/tchapgouv/tchap-web-v4/issues/1187",
"files": [
"src/components/views/context_menus/RoomGeneralContextMenu.tsx",
"src/components/views/right_panel/RoomSummaryCard.tsx"
]
},
"default-language-french": {
"issue": "https://github.com/tchapgouv/tchap-web-v4/issues/1199",
"files": [
"src/vector/init.tsx"
]

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Please see LICENSE files in the repository root for full details.
*/

import { logger } from "matrix-js-sdk/src/logger";
import { Room } from "matrix-js-sdk/src/matrix";
import { JoinRule, Room } from "matrix-js-sdk/src/matrix"; // :tchap: copy-link-room-behavior
import React, { useContext } from "react";

import { KeyBindingAction } from "../../../accessibility/KeyboardShortcuts";
Expand Down Expand Up @@ -35,6 +35,8 @@ import { UIComponent } from "../../../settings/UIFeature";
import { DeveloperToolsOption } from "./DeveloperToolsOption";
import { useSettingValue } from "../../../hooks/useSettings";

import TchapRoomUtils from "~tchap-web/src/tchap/util/TchapRoomUtils"; // :tchap: copy-link-room-behavior

export interface RoomGeneralContextMenuProps extends IContextMenuProps {
room: Room;
/**
Expand Down Expand Up @@ -199,6 +201,9 @@ export const RoomGeneralContextMenu: React.FC<RoomGeneralContextMenuProps> = ({
)}
label={_t("room|context_menu|copy_link")}
iconClassName="mx_RoomGeneralContextMenu_iconCopyLink"
// :TCHAP: copy-link-room-behavior
disabled={TchapRoomUtils.getRoomJoinRule(room) === JoinRule.Invite}
// end :TCHAP:
/>
);
}
Expand Down
11 changes: 10 additions & 1 deletion src/components/views/right_panel/RoomSummaryCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ import { ReleaseAnnouncement } from "../../structures/ReleaseAnnouncement.tsx";

import DecoratedRoomAvatar from "../avatars/DecoratedRoomAvatar"; // :TCHAP: tchap-room-icons

import TchapRoomUtils from "~tchap-web/src/tchap/util/TchapRoomUtils.ts"; // :TCHAP: copy-link-room-behavior


interface IProps {
room: Room;
Expand Down Expand Up @@ -427,7 +429,14 @@ const RoomSummaryCard: React.FC<IProps> = ({

<Separator />

<MenuItem Icon={LinkIcon} label={_t("action|copy_link")} onSelect={onShareRoomClick} />
{/* :TCHAP: copy-link-room-behavior - <MenuItem Icon={LinkIcon} label={_t("action|copy_link")} onSelect={onShareRoomClick} /> */}
<MenuItem
Icon={LinkIcon}
label={_t("action|copy_link")}
onSelect={onShareRoomClick}
disabled={TchapRoomUtils.getRoomJoinRule(room) === JoinRule.Invite}
/>
{/* end :TCHAP: */}

{!isVideoRoom && (
<>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { logRoles, render, screen } from "jest-matrix-react";
import { mocked } from "jest-mock";
import { MatrixClient, PendingEventOrdering, Room, JoinRule, KnownMembership } from "matrix-js-sdk/src/matrix";
import React from "react";

import { stubClient } from "~tchap-web/test/test-utils/test-utils";
import { clearAllModals } from "~tchap-web/test/test-utils";
import { ChevronFace } from "~tchap-web/src/components/structures/ContextMenu";
import {
RoomGeneralContextMenu,
RoomGeneralContextMenuProps,
} from "~tchap-web/src/components/views/context_menus/RoomGeneralContextMenu";
import MatrixClientContext from "~tchap-web/src/contexts/MatrixClientContext";
import { MatrixClientPeg } from "~tchap-web/src/MatrixClientPeg";
import { DefaultTagID } from "~tchap-web/src/stores/room-list/models";
import RoomListStore from "~tchap-web/src/stores/room-list/RoomListStore";
import DMRoomMap from "~tchap-web/src/utils/DMRoomMap";
import TchapRoomUtils from "~tchap-web/src/tchap/util/TchapRoomUtils";

jest.mock("~tchap-web/src/tchap/util/TchapRoomUtils");

describe("RoomGeneralContextMenu", () => {
const ROOM_ID = "!123:matrix.org";

let room: Room;
let mockClient: MatrixClient;

let onFinished: () => void;

const mockedTchapRoomUtils = mocked(TchapRoomUtils);

function getComponent(props?: Partial<RoomGeneralContextMenuProps>) {
return render(
<MatrixClientContext.Provider value={mockClient}>
<RoomGeneralContextMenu
room={room}
onFinished={onFinished}
{...props}
managed={true}
mountAsChild={true}
left={1}
top={1}
chevronFace={ChevronFace.Left}
/>
</MatrixClientContext.Provider>,
);
}

beforeEach(() => {
jest.clearAllMocks();

stubClient();
mockClient = mocked(MatrixClientPeg.safeGet());

room = new Room(ROOM_ID, mockClient, mockClient.getUserId() ?? "", {
pendingEventOrdering: PendingEventOrdering.Detached,
});

const dmRoomMap = {
getUserIdForRoomId: jest.fn().mockReturnValue(null),
} as unknown as DMRoomMap;
DMRoomMap.setShared(dmRoomMap);

jest.spyOn(RoomListStore.instance, "getTagsForRoom").mockReturnValueOnce([
DefaultTagID.DM,
DefaultTagID.Favourite,
]);

room.updateMyMembership(KnownMembership.Join);
jest.spyOn(room, "canInvite").mockReturnValue(true);

onFinished = jest.fn();
});

afterEach(async () => {
await clearAllModals();
});

it("renders the default context menu", async () => {
const { container } = getComponent({});
expect(container).toMatchSnapshot();
});

it("able the copy link button when joinrule is public", () => {
mockedTchapRoomUtils.getRoomJoinRule.mockImplementation(() => JoinRule.Public);

const { container } = getComponent({});

logRoles(container);

const roomLinkButton = screen.getByRole("menuitem", { name: "Copy room link" });

expect(roomLinkButton).not.toHaveAttribute("aria-disabled");
});

it("disable the copy link button when joinrule is not public", () => {
mockedTchapRoomUtils.getRoomJoinRule.mockImplementation(() => JoinRule.Invite);

getComponent({});

const roomLinkButton = screen.getByRole("menuitem", { name: "Copy room link" });

expect(roomLinkButton).toHaveAttribute("aria-disabled", "true");
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`RoomGeneralContextMenu renders the default context menu 1`] = `
<div>
<div
class="mx_ContextualMenu_wrapper"
style="top: 1px; left: 1px;"
>
<div
class="mx_ContextualMenu_background"
/>
<div
class="mx_ContextualMenu mx_ContextualMenu_withChevron_left"
role="menu"
>
<div
class="mx_ContextualMenu_chevron_left"
/>
<ul
class="mx_IconizedContextMenu mx_RoomGeneralContextMenu mx_IconizedContextMenu_compact"
role="none"
>
<div
class="mx_IconizedContextMenu_optionList mx_IconizedContextMenu_optionList_notFirst"
>
<li
aria-label="Mark as unread"
class="mx_AccessibleButton mx_IconizedContextMenu_item"
role="menuitem"
tabindex="0"
>
<span
class="mx_IconizedContextMenu_icon mx_RoomGeneralContextMenu_iconMarkAsUnread"
/>
<span
class="mx_IconizedContextMenu_label"
>
Mark as unread
</span>
</li>
<div
aria-checked="false"
aria-label="Favourite"
class="mx_AccessibleButton mx_IconizedContextMenu_item"
role="menuitemcheckbox"
tabindex="-1"
>
<span
class="mx_IconizedContextMenu_icon mx_RoomGeneralContextMenu_iconStar"
/>
<span
class="mx_IconizedContextMenu_label"
>
Favourite
</span>
<span
class="mx_IconizedContextMenu_icon mx_IconizedContextMenu_unchecked"
/>
</div>
<div
aria-checked="false"
aria-label="Low Priority"
class="mx_AccessibleButton mx_IconizedContextMenu_item"
role="menuitemcheckbox"
tabindex="-1"
>
<span
class="mx_IconizedContextMenu_icon mx_RoomGeneralContextMenu_iconArrowDown"
/>
<span
class="mx_IconizedContextMenu_label"
>
Low Priority
</span>
<span
class="mx_IconizedContextMenu_icon mx_IconizedContextMenu_unchecked"
/>
</div>
<li
aria-label="Invite"
class="mx_AccessibleButton mx_IconizedContextMenu_item"
role="menuitem"
tabindex="-1"
>
<span
class="mx_IconizedContextMenu_icon mx_RoomGeneralContextMenu_iconInvite"
/>
<span
class="mx_IconizedContextMenu_label"
>
Invite
</span>
</li>
<li
aria-label="Copy room link"
class="mx_AccessibleButton mx_IconizedContextMenu_item"
role="menuitem"
tabindex="-1"
>
<span
class="mx_IconizedContextMenu_icon mx_RoomGeneralContextMenu_iconCopyLink"
/>
<span
class="mx_IconizedContextMenu_label"
>
Copy room link
</span>
</li>
<li
aria-label="Settings"
class="mx_AccessibleButton mx_IconizedContextMenu_item"
role="menuitem"
tabindex="-1"
>
<span
class="mx_IconizedContextMenu_icon mx_RoomGeneralContextMenu_iconSettings"
/>
<span
class="mx_IconizedContextMenu_label"
>
Settings
</span>
</li>
</div>
<div
class="mx_IconizedContextMenu_optionList mx_IconizedContextMenu_optionList_notFirst mx_IconizedContextMenu_optionList_red"
>
<li
aria-label="Leave"
class="mx_AccessibleButton mx_IconizedContextMenu_option_red mx_IconizedContextMenu_item"
role="menuitem"
tabindex="-1"
>
<span
class="mx_IconizedContextMenu_icon mx_RoomGeneralContextMenu_iconSignOut"
/>
<span
class="mx_IconizedContextMenu_label"
>
Leave
</span>
</li>
</div>
</ul>
</div>
</div>
</div>
`;
Loading

0 comments on commit cd4646b

Please sign in to comment.