Skip to content

Commit

Permalink
chore: Add option to show/hide "Leave space" in context menu. created…
Browse files Browse the repository at this point in the history
… tests
  • Loading branch information
Reza Mohseni committed Jul 4, 2024
1 parent 9dca3a5 commit 80aa32f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/components/views/context_menus/SpaceContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import SettingsStore from "../../../settings/SettingsStore";
import { useFeatureEnabled } from "../../../hooks/useSettings";
import { Action } from "../../../dispatcher/actions";
import { shouldShowComponent } from "../../../customisations/helpers/UIComponents";
import { UIComponent } from "../../../settings/UIFeature";
import { UIComponent, UIFeature } from "../../../settings/UIFeature";
import PosthogTrackers from "../../../PosthogTrackers";
import { ViewRoomPayload } from "../../../dispatcher/payloads/ViewRoomPayload";

Expand Down Expand Up @@ -259,7 +259,7 @@ const SpaceContextMenu: React.FC<IProps> = ({ space, hideHeader, onFinished, ...
/>
{devtoolsOption}
{settingsOption}
{leaveOption}
{SettingsStore.getValue(UIFeature.ShowLeaveSpaceInContextMenu) && leaveOption}
{newRoomSection}
</IconizedContextMenuOptionList>
</IconizedContextMenu>
Expand Down
4 changes: 4 additions & 0 deletions src/settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,10 @@ export const SETTINGS: { [setting: string]: ISetting } = {
supportedLevels: LEVELS_UI_FEATURE,
default: true,
},
[UIFeature.ShowLeaveSpaceInContextMenu]: {
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.
Expand Down
1 change: 1 addition & 0 deletions src/settings/UIFeature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const enum UIFeature {
TimelineEnableRelativeDates = "UIFeature.timelineEnableRelativeDates",
BulkUnverifiedSessionsReminder = "UIFeature.BulkUnverifiedSessionsReminder",
ShowCreateSpaceButton = "UIFeature.showCreateSpaceButton",
ShowLeaveSpaceInContextMenu = "UIFeature.showLeaveSpaceInContextMenu",
}

export enum UIComponent {
Expand Down
25 changes: 24 additions & 1 deletion test/components/views/context_menus/SpaceContextMenu-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import {
} from "../../../../src/utils/space";
import { leaveSpace } from "../../../../src/utils/leave-behaviour";
import { shouldShowComponent } from "../../../../src/customisations/helpers/UIComponents";
import { UIComponent } from "../../../../src/settings/UIFeature";
import { UIComponent, UIFeature } from "../../../../src/settings/UIFeature";
import SettingsStore from "../../../../src/settings/SettingsStore";

jest.mock("../../../../src/customisations/helpers/UIComponents", () => ({
shouldShowComponent: jest.fn(),
Expand Down Expand Up @@ -223,4 +224,26 @@ describe("<SpaceContextMenu />", () => {
expect(onFinished).toHaveBeenCalled();
});
});

describe("UIFeature.ShowLeaveSpaceInContextMenu", () => {
it("ShowLeaveSpaceInContextMenu = true, renders 'leave space' option", () => {
mocked(shouldShowSpaceSettings).mockReturnValue(false);
jest.spyOn(SettingsStore, "getValue").mockImplementation((val) => {
return val === UIFeature.ShowLeaveSpaceInContextMenu ? true : "default";
});
renderComponent();

expect(screen.getByTestId("leave-option")).toBeInTheDocument();
});

it("ShowLeaveSpaceInContextMenu = false, does not render 'leave space' option", () => {
mocked(shouldShowSpaceSettings).mockReturnValue(false);
jest.spyOn(SettingsStore, "getValue").mockImplementation((val) => {
return val === UIFeature.ShowLeaveSpaceInContextMenu ? false : "default";
});
renderComponent();

expect(screen.queryByTestId("leave-option")).not.toBeInTheDocument();
});
});
});

0 comments on commit 80aa32f

Please sign in to comment.