2022-09-22 15:08:14 +01:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2022-09-22 15:08:14 +01:00
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
2025-01-06 11:18:54 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-09 14:57:16 +01:00
|
|
|
Please see LICENSE files in the repository root for full details.
|
2022-09-22 15:08:14 +01:00
|
|
|
*/
|
|
|
|
|
|
2024-10-15 14:57:26 +01:00
|
|
|
import SdkConfig from "../../../src/SdkConfig";
|
|
|
|
|
import { shouldShowFeedback } from "../../../src/utils/Feedback";
|
|
|
|
|
import SettingsStore from "../../../src/settings/SettingsStore";
|
2026-01-20 12:29:18 +00:00
|
|
|
import { UIFeature } from "../../../src/settings/UIFeature";
|
|
|
|
|
import { BugReportEndpointURLLocal } from "../../../src/IConfigOptions";
|
2022-09-22 15:08:14 +01:00
|
|
|
|
2026-01-20 12:29:18 +00:00
|
|
|
const realGetValue = SettingsStore.getValue;
|
2022-09-22 15:08:14 +01:00
|
|
|
|
|
|
|
|
describe("shouldShowFeedback", () => {
|
2026-01-20 12:29:18 +00:00
|
|
|
afterEach(() => {
|
|
|
|
|
SdkConfig.reset();
|
|
|
|
|
jest.restoreAllMocks();
|
|
|
|
|
});
|
|
|
|
|
|
2022-09-22 15:08:14 +01:00
|
|
|
it("should return false if bug_report_endpoint_url is falsey", () => {
|
2026-01-20 12:29:18 +00:00
|
|
|
SdkConfig.put({
|
|
|
|
|
bug_report_endpoint_url: undefined,
|
2022-09-22 15:08:14 +01:00
|
|
|
});
|
2026-01-20 12:29:18 +00:00
|
|
|
expect(shouldShowFeedback()).toEqual(false);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should return false if bug_report_endpoint_url is 'test'", () => {
|
|
|
|
|
SdkConfig.put({
|
|
|
|
|
bug_report_endpoint_url: BugReportEndpointURLLocal,
|
|
|
|
|
});
|
|
|
|
|
expect(shouldShowFeedback()).toEqual(false);
|
2022-09-22 15:08:14 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should return false if UIFeature.Feedback is disabled", () => {
|
2026-01-20 12:29:18 +00:00
|
|
|
jest.spyOn(SettingsStore, "getValue").mockImplementation((key, ...params) => {
|
|
|
|
|
if (key === UIFeature.Feedback) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return realGetValue(key, ...params);
|
|
|
|
|
});
|
|
|
|
|
expect(shouldShowFeedback()).toEqual(false);
|
2022-09-22 15:08:14 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should return true if bug_report_endpoint_url is set and UIFeature.Feedback is true", () => {
|
2026-01-20 12:29:18 +00:00
|
|
|
SdkConfig.put({
|
2022-09-22 15:08:14 +01:00
|
|
|
bug_report_endpoint_url: "https://rageshake.server",
|
|
|
|
|
});
|
2026-01-20 12:29:18 +00:00
|
|
|
jest.spyOn(SettingsStore, "getValue").mockImplementation((key, ...params) => {
|
|
|
|
|
if (key === UIFeature.Feedback) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return realGetValue(key, ...params);
|
|
|
|
|
});
|
|
|
|
|
expect(shouldShowFeedback()).toEqual(true);
|
2022-09-22 15:08:14 +01:00
|
|
|
});
|
|
|
|
|
});
|