From 017fc1feeb989a46740b9722d451e7d6be434954 Mon Sep 17 00:00:00 2001 From: John Tore Simonsen Date: Thu, 29 Aug 2024 16:10:43 +0200 Subject: [PATCH] Feature flag for "inviteToSpace"-button with tests --- src/components/views/rooms/RoomList.tsx | 3 +- src/settings/Settings.tsx | 4 ++ src/settings/UIFeature.ts | 1 + test/components/views/rooms/RoomList-test.tsx | 66 ++++++++++++++++++- 4 files changed, 71 insertions(+), 3 deletions(-) diff --git a/src/components/views/rooms/RoomList.tsx b/src/components/views/rooms/RoomList.tsx index cf1b99a7178..5df43fb556f 100644 --- a/src/components/views/rooms/RoomList.tsx +++ b/src/components/views/rooms/RoomList.tsx @@ -163,7 +163,7 @@ const DmAuxButton: React.FC = ({ tabIndex, dispatcher = default }} /> )} - {showInviteUsers && ( + {showInviteUsers && SettingsStore.getValue(UIFeature.ShowInviteToSpaceFromPeoplePlus) && ( = ({ tabIndex, dispatcher = default isExpanded={menuDisplayed} ref={handle} /> - {contextMenu} ); diff --git a/src/settings/Settings.tsx b/src/settings/Settings.tsx index b62a212a723..64acbec2950 100644 --- a/src/settings/Settings.tsx +++ b/src/settings/Settings.tsx @@ -1503,6 +1503,10 @@ export const SETTINGS: { [setting: string]: ISetting } = { supportedLevels: LEVELS_UI_FEATURE, default: true, }, + [UIFeature.ShowInviteToSpaceFromPeoplePlus]: { + supportedLevels: LEVELS_UI_FEATURE, + default: true, + }, // Electron-specific settings, they are stored by Electron and set/read over an IPC. // We store them over there are they are necessary to know before the renderer process launches. diff --git a/src/settings/UIFeature.ts b/src/settings/UIFeature.ts index 30530cf5986..72dbea1dfe3 100644 --- a/src/settings/UIFeature.ts +++ b/src/settings/UIFeature.ts @@ -100,6 +100,7 @@ export const enum UIFeature { ShowSendMessageToUserLink = "UIFeature.showSendMessageToUserLink", SendInviteLinkPrompt = "UIFeature.sendInviteLinkPrompt", HelpShowMatrixDisclosurePolicyAndLinks = "UIFeature.helpShowMatrixDisclosurePolicyAndLinks", + ShowInviteToSpaceFromPeoplePlus = "UIFeature.showInviteToSpaceFromPeoplePlus", } export enum UIComponent { diff --git a/test/components/views/rooms/RoomList-test.tsx b/test/components/views/rooms/RoomList-test.tsx index 499414edd62..82b4a200d0f 100644 --- a/test/components/views/rooms/RoomList-test.tsx +++ b/test/components/views/rooms/RoomList-test.tsx @@ -51,7 +51,6 @@ DMRoomMap.sharedInstance = { getUserIdForRoomId, getDMRoomsForUserId }; describe("UIFeature tests", () => { stubClient(); - //const client = MatrixClientPeg.safeGet(); const store = SpaceStore.instance; function getComponent(props: Partial> = {}): JSX.Element { @@ -383,3 +382,68 @@ describe("RoomList", () => { }); }); }); + +describe("UIFeature tests part 2", () => { + stubClient(); + const store = SpaceStore.instance; + + function getComponent(props: Partial> = {}): JSX.Element { + return ( + + ); + } + beforeEach(() => { + store.setActiveSpace(MetaSpace.Home); + mocked(shouldShowComponent).mockImplementation((feature) => true); + }); + describe("UIFeature.showInviteToSpaceFromPeoplePlus", () => { + stubClient(); + const client = MatrixClientPeg.safeGet(); + const store = SpaceStore.instance; + let rooms: Room[]; + const mkSpaceForRooms = (spaceId: string, children: string[] = []) => mkSpace(client, spaceId, rooms, children); + + const space1 = "!verjispace1:server"; + + beforeEach(async () => { + rooms = []; + mkSpaceForRooms(space1); + mocked(client).getRoom.mockImplementation((roomId) => rooms.find((room) => room.roomId === roomId) || null); + await testUtils.setupAsyncStoreWithClient(store, client); + + store.setActiveSpace(space1); + }); + it("UIFeature.showInviteToSpaceFromPeoplePlus = true: renders 'Invite to space'-button", async () => { + jest.spyOn(SettingsStore, "getValue").mockImplementation((name: string) => { + if (name == UIFeature.ShowInviteToSpaceFromPeoplePlus) return true; + return false; + }); + render(getComponent()); + const peoplePlusButton = screen.getByLabelText("Add people"); + await userEvent.click(peoplePlusButton); + + expect(screen.getByLabelText("Invite to space")).toBeInTheDocument(); + }); + + it("UIFeature.showInviteToSpaceFromPeoplePlus = false: does not render 'Invite to space'-button", async () => { + jest.spyOn(SettingsStore, "getValue").mockImplementation((name: string) => { + if (name == UIFeature.ShowInviteToSpaceFromPeoplePlus) return false; + return false; + }); + render(getComponent()); + const peoplePlusButton = screen.getByLabelText("Add people"); + await userEvent.click(peoplePlusButton); + + expect(screen.queryByLabelText("Invite to space")).not.toBeInTheDocument(); + }); + }); +});