Don't show feedback prompts when that UIFeature is disabled (#9305)

This commit is contained in:
Michael Telatynski 2022-09-22 15:08:14 +01:00 committed by GitHub
parent 88c12cdaa5
commit 56c95467de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 303 additions and 127 deletions

View file

@ -0,0 +1,80 @@
/*
Copyright 2022 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import React from "react";
import { mocked } from "jest-mock";
import { render, screen } from "@testing-library/react";
import { shouldShowFeedback } from "../../../../src/utils/Feedback";
import BetaCard from "../../../../src/components/views/beta/BetaCard";
import SettingsStore from "../../../../src/settings/SettingsStore";
jest.mock("../../../../src/utils/Feedback");
jest.mock("../../../../src/settings/SettingsStore");
describe('<BetaCard />', () => {
describe("Feedback prompt", () => {
const featureId = "featureId";
beforeEach(() => {
mocked(SettingsStore).getBetaInfo.mockReturnValue({
title: "title",
caption: () => "caption",
feedbackLabel: "feedbackLabel",
feedbackSubheading: "feedbackSubheading",
});
mocked(SettingsStore).getValue.mockReturnValue(true);
mocked(shouldShowFeedback).mockReturnValue(true);
});
it("should show feedback prompt", () => {
render(<BetaCard featureId={featureId} />);
expect(screen.queryByText("Feedback")).toBeTruthy();
});
it("should not show feedback prompt if beta is disabled", () => {
mocked(SettingsStore).getValue.mockReturnValue(false);
render(<BetaCard featureId={featureId} />);
expect(screen.queryByText("Feedback")).toBeFalsy();
});
it("should not show feedback prompt if label is unset", () => {
mocked(SettingsStore).getBetaInfo.mockReturnValue({
title: "title",
caption: () => "caption",
feedbackSubheading: "feedbackSubheading",
});
render(<BetaCard featureId={featureId} />);
expect(screen.queryByText("Feedback")).toBeFalsy();
});
it("should not show feedback prompt if subheading is unset", () => {
mocked(SettingsStore).getBetaInfo.mockReturnValue({
title: "title",
caption: () => "caption",
feedbackLabel: "feedbackLabel",
});
render(<BetaCard featureId={featureId} />);
expect(screen.queryByText("Feedback")).toBeFalsy();
});
it("should not show feedback prompt if feedback is disabled", () => {
mocked(shouldShowFeedback).mockReturnValue(false);
render(<BetaCard featureId={featureId} />);
expect(screen.queryByText("Feedback")).toBeFalsy();
});
});
});

View file

@ -29,6 +29,9 @@ import { LocalRoom, LOCAL_ROOM_ID_PREFIX } from "../../../../src/models/LocalRoo
import { DirectoryMember, startDmOnFirstMessage } from "../../../../src/utils/direct-messages";
import DMRoomMap from "../../../../src/utils/DMRoomMap";
import { mkRoom, stubClient } from "../../../test-utils";
import { shouldShowFeedback } from "../../../../src/utils/Feedback";
jest.mock("../../../../src/utils/Feedback");
jest.mock("../../../../src/utils/direct-messages", () => ({
// @ts-ignore
@ -138,6 +141,7 @@ describe("Spotlight Dialog", () => {
getUserIdForRoomId: jest.fn(),
} as unknown as DMRoomMap);
});
describe("should apply filters supplied via props", () => {
it("without filter", async () => {
const wrapper = mount(
@ -370,4 +374,32 @@ describe("Spotlight Dialog", () => {
wrapper.unmount();
});
describe("Feedback prompt", () => {
it("should show feedback prompt if feedback is enabled", async () => {
mocked(shouldShowFeedback).mockReturnValue(true);
const wrapper = mount(<SpotlightDialog initialText="test23" onFinished={() => null} />);
await act(async () => {
await sleep(200);
});
wrapper.update();
const content = wrapper.find(".mx_SpotlightDialog_footer");
expect(content.childAt(0).text()).toBe("Results not as expected? Please give feedback.");
});
it("should hide feedback prompt if feedback is disabled", async () => {
mocked(shouldShowFeedback).mockReturnValue(false);
const wrapper = mount(<SpotlightDialog initialText="test23" onFinished={() => null} />);
await act(async () => {
await sleep(200);
});
wrapper.update();
const content = wrapper.find(".mx_SpotlightDialog_footer");
expect(content.text()).toBeFalsy();
});
});
});