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

Commit 56c9546

Browse files
authored
Don't show feedback prompts when that UIFeature is disabled (#9305)
1 parent 88c12cd commit 56c9546

File tree

12 files changed

+303
-127
lines changed

12 files changed

+303
-127
lines changed

src/components/structures/ThreadPanel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ import Measured from '../views/elements/Measured';
3333
import PosthogTrackers from "../../PosthogTrackers";
3434
import AccessibleButton, { ButtonEvent } from "../views/elements/AccessibleButton";
3535
import { BetaPill } from '../views/beta/BetaCard';
36-
import SdkConfig from '../../SdkConfig';
3736
import Modal from '../../Modal';
3837
import BetaFeedbackDialog from '../views/dialogs/BetaFeedbackDialog';
3938
import { Action } from '../../dispatcher/actions';
4039
import { UserTab } from '../views/dialogs/UserTab';
4140
import dis from '../../dispatcher/dispatcher';
4241
import Spinner from "../views/elements/Spinner";
4342
import Heading from '../views/typography/Heading';
43+
import { shouldShowFeedback } from "../../utils/Feedback";
4444

4545
interface IProps {
4646
roomId: string;
@@ -234,7 +234,7 @@ const ThreadPanel: React.FC<IProps> = ({
234234
}
235235
}, [timelineSet, timelinePanel]);
236236

237-
const openFeedback = SdkConfig.get().bug_report_endpoint_url ? () => {
237+
const openFeedback = shouldShowFeedback() ? () => {
238238
Modal.createDialog(BetaFeedbackDialog, {
239239
featureId: "feature_thread",
240240
});

src/components/views/beta/BetaCard.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import SettingsFlag from "../elements/SettingsFlag";
2828
import { useFeatureEnabled } from "../../../hooks/useSettings";
2929
import InlineSpinner from "../elements/InlineSpinner";
3030
import AccessibleTooltipButton from "../elements/AccessibleTooltipButton";
31+
import { shouldShowFeedback } from "../../../utils/Feedback";
3132

3233
// XXX: Keep this around for re-use in future Betas
3334

@@ -88,7 +89,7 @@ const BetaCard = ({ title: titleOverride, featureId }: IProps) => {
8889
} = info;
8990

9091
let feedbackButton;
91-
if (value && feedbackLabel && feedbackSubheading && SdkConfig.get().bug_report_endpoint_url) {
92+
if (value && feedbackLabel && feedbackSubheading && shouldShowFeedback()) {
9293
feedbackButton = <AccessibleButton
9394
onClick={() => {
9495
Modal.createDialog(BetaFeedbackDialog, { featureId });

src/components/views/dialogs/spotlight/SpotlightDialog.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ import Modal from "../../../../Modal";
6060
import { PosthogAnalytics } from "../../../../PosthogAnalytics";
6161
import { getCachedRoomIDForAlias } from "../../../../RoomAliasCache";
6262
import { showStartChatInviteDialog } from "../../../../RoomInvite";
63-
import SdkConfig from "../../../../SdkConfig";
6463
import { SettingLevel } from "../../../../settings/SettingLevel";
6564
import SettingsStore from "../../../../settings/SettingsStore";
6665
import { BreadcrumbsStore } from "../../../../stores/BreadcrumbsStore";
@@ -93,6 +92,7 @@ import { RoomContextDetails } from "../../rooms/RoomContextDetails";
9392
import { TooltipOption } from "./TooltipOption";
9493
import { isLocalRoom } from "../../../../utils/localRoom/isLocalRoom";
9594
import { useSlidingSyncRoomSearch } from "../../../../hooks/useSlidingSyncRoomSearch";
95+
import { shouldShowFeedback } from "../../../../utils/Feedback";
9696

9797
const MAX_RECENT_SEARCHES = 10;
9898
const SECTION_LIMIT = 50; // only show 50 results per section for performance reasons
@@ -1171,7 +1171,7 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
11711171
}
11721172
};
11731173

1174-
const openFeedback = SdkConfig.get().bug_report_endpoint_url ? () => {
1174+
const openFeedback = shouldShowFeedback() ? () => {
11751175
Modal.createDialog(FeedbackDialog, {
11761176
feature: "spotlight",
11771177
});

src/components/views/spaces/SpaceCreateMenu.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,13 @@ import AccessibleButton from "../elements/AccessibleButton";
3131
import Field from "../elements/Field";
3232
import withValidation from "../elements/Validation";
3333
import RoomAliasField from "../elements/RoomAliasField";
34-
import SdkConfig from "../../../SdkConfig";
3534
import Modal from "../../../Modal";
3635
import GenericFeatureFeedbackDialog from "../dialogs/GenericFeatureFeedbackDialog";
3736
import SettingsStore from "../../../settings/SettingsStore";
3837
import { getKeyBindingsManager } from "../../../KeyBindingsManager";
3938
import { KeyBindingAction } from "../../../accessibility/KeyboardShortcuts";
4039
import { MatrixClientPeg } from "../../../MatrixClientPeg";
41-
import { UIFeature } from "../../../settings/UIFeature";
40+
import { shouldShowFeedback } from "../../../utils/Feedback";
4241

4342
export const createSpace = async (
4443
name: string,
@@ -101,7 +100,7 @@ const nameToLocalpart = (name: string): string => {
101100

102101
// XXX: Temporary for the Spaces release only
103102
export const SpaceFeedbackPrompt = ({ onClick }: { onClick?: () => void }) => {
104-
if (!SdkConfig.get().bug_report_endpoint_url || !SettingsStore.getValue(UIFeature.Feedback)) return null;
103+
if (!shouldShowFeedback()) return null;
105104

106105
return <div className="mx_SpaceFeedbackPrompt">
107106
<span className="mx_SpaceFeedbackPrompt_text">{ _t("Spaces are a new feature.") }</span>

src/components/views/user-onboarding/UserOnboardingFeedback.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ import SdkConfig from "../../../SdkConfig";
2222
import AccessibleButton from "../../views/elements/AccessibleButton";
2323
import Heading from "../../views/typography/Heading";
2424
import FeedbackDialog from "../dialogs/FeedbackDialog";
25+
import { shouldShowFeedback } from "../../../utils/Feedback";
2526

2627
export function UserOnboardingFeedback() {
27-
if (!SdkConfig.get().bug_report_endpoint_url) {
28+
if (!shouldShowFeedback()) {
2829
return null;
2930
}
3031

src/utils/Feedback.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Copyright 2022 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import SdkConfig from "../SdkConfig";
18+
import SettingsStore from "../settings/SettingsStore";
19+
import { UIFeature } from "../settings/UIFeature";
20+
21+
export function shouldShowFeedback(): boolean {
22+
return SdkConfig.get().bug_report_endpoint_url && SettingsStore.getValue(UIFeature.Feedback);
23+
}

test/components/structures/ThreadPanel-test.tsx

Lines changed: 60 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,68 +15,102 @@ limitations under the License.
1515
*/
1616

1717
import React from 'react';
18-
// eslint-disable-next-line deprecate/import
19-
import { shallow, mount } from "enzyme";
18+
import { render, screen, fireEvent } from "@testing-library/react";
19+
import { mocked } from "jest-mock";
2020
import 'focus-visible'; // to fix context menus
2121

22-
import {
23-
ThreadFilterType,
24-
ThreadPanelHeader,
25-
ThreadPanelHeaderFilterOptionItem,
26-
} from '../../../src/components/structures/ThreadPanel';
27-
import { ContextMenuButton } from '../../../src/accessibility/context_menu/ContextMenuButton';
28-
import ContextMenu from '../../../src/components/structures/ContextMenu';
22+
import ThreadPanel, { ThreadFilterType, ThreadPanelHeader } from '../../../src/components/structures/ThreadPanel';
2923
import { _t } from '../../../src/languageHandler';
24+
import ResizeNotifier from '../../../src/utils/ResizeNotifier';
25+
import { RoomPermalinkCreator } from '../../../src/utils/permalinks/Permalinks';
26+
import { createTestClient, mkStubRoom } from '../../test-utils';
27+
import { shouldShowFeedback } from "../../../src/utils/Feedback";
28+
import MatrixClientContext from "../../../src/contexts/MatrixClientContext";
29+
30+
jest.mock("../../../src/utils/Feedback");
3031

3132
describe('ThreadPanel', () => {
33+
describe("Feedback prompt", () => {
34+
const cli = createTestClient();
35+
const room = mkStubRoom("!room:server", "room", cli);
36+
mocked(cli.getRoom).mockReturnValue(room);
37+
38+
it("should show feedback prompt if feedback is enabled", () => {
39+
mocked(shouldShowFeedback).mockReturnValue(true);
40+
41+
render(<MatrixClientContext.Provider value={cli}>
42+
<ThreadPanel
43+
roomId="!room:server"
44+
onClose={jest.fn()}
45+
resizeNotifier={new ResizeNotifier()}
46+
permalinkCreator={new RoomPermalinkCreator(room)}
47+
/>
48+
</MatrixClientContext.Provider>);
49+
expect(screen.queryByText("Give feedback")).toBeTruthy();
50+
});
51+
52+
it("should hide feedback prompt if feedback is disabled", () => {
53+
mocked(shouldShowFeedback).mockReturnValue(false);
54+
55+
render(<MatrixClientContext.Provider value={cli}>
56+
<ThreadPanel
57+
roomId="!room:server"
58+
onClose={jest.fn()}
59+
resizeNotifier={new ResizeNotifier()}
60+
permalinkCreator={new RoomPermalinkCreator(room)}
61+
/>
62+
</MatrixClientContext.Provider>);
63+
expect(screen.queryByText("Give feedback")).toBeFalsy();
64+
});
65+
});
66+
3267
describe('Header', () => {
3368
it('expect that All filter for ThreadPanelHeader properly renders Show: All threads', () => {
34-
const wrapper = shallow(
69+
const { asFragment } = render(
3570
<ThreadPanelHeader
3671
empty={false}
3772
filterOption={ThreadFilterType.All}
3873
setFilterOption={() => undefined} />,
3974
);
40-
expect(wrapper).toMatchSnapshot();
75+
expect(asFragment()).toMatchSnapshot();
4176
});
4277

4378
it('expect that My filter for ThreadPanelHeader properly renders Show: My threads', () => {
44-
const wrapper = shallow(
79+
const { asFragment } = render(
4580
<ThreadPanelHeader
4681
empty={false}
4782
filterOption={ThreadFilterType.My}
4883
setFilterOption={() => undefined} />,
4984
);
50-
expect(wrapper).toMatchSnapshot();
85+
expect(asFragment()).toMatchSnapshot();
5186
});
5287

5388
it('expect that ThreadPanelHeader properly opens a context menu when clicked on the button', () => {
54-
const wrapper = mount(
89+
const { container } = render(
5590
<ThreadPanelHeader
5691
empty={false}
5792
filterOption={ThreadFilterType.All}
5893
setFilterOption={() => undefined} />,
5994
);
60-
const found = wrapper.find(ContextMenuButton);
61-
expect(found).not.toBe(undefined);
62-
expect(found).not.toBe(null);
63-
expect(wrapper.exists(ContextMenu)).toEqual(false);
64-
found.simulate('click');
65-
expect(wrapper.exists(ContextMenu)).toEqual(true);
95+
const found = container.querySelector(".mx_ThreadPanel_dropdown");
96+
expect(found).toBeTruthy();
97+
expect(screen.queryByRole("menu")).toBeFalsy();
98+
fireEvent.click(found);
99+
expect(screen.queryByRole("menu")).toBeTruthy();
66100
});
67101

68102
it('expect that ThreadPanelHeader has the correct option selected in the context menu', () => {
69-
const wrapper = mount(
103+
const { container } = render(
70104
<ThreadPanelHeader
71105
empty={false}
72106
filterOption={ThreadFilterType.All}
73107
setFilterOption={() => undefined} />,
74108
);
75-
wrapper.find(ContextMenuButton).simulate('click');
76-
const found = wrapper.find(ThreadPanelHeaderFilterOptionItem);
77-
expect(found.length).toEqual(2);
78-
const foundButton = found.find('[aria-checked=true]').first();
79-
expect(foundButton.text()).toEqual(`${_t("All threads")}${_t('Shows all threads from current room')}`);
109+
fireEvent.click(container.querySelector(".mx_ThreadPanel_dropdown"));
110+
const found = screen.queryAllByRole("menuitemradio");
111+
expect(found).toHaveLength(2);
112+
const foundButton = screen.queryByRole("menuitemradio", { checked: true });
113+
expect(foundButton.textContent).toEqual(`${_t("All threads")}${_t('Shows all threads from current room')}`);
80114
expect(foundButton).toMatchSnapshot();
81115
});
82116
});

0 commit comments

Comments
 (0)