1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-08-09 08:42:50 +03:00

Make existing and new issue URLs configurable (#10710)

* Make existing and new issue URLs configurable

* Apply a deep merge over sdk config to allow sane nested structures

* Defaultize

* Fix types

* Iterate

* Add FeedbackDialog snapshot test

* Add SdkConfig snapshot tests

* Iterate

* Fix tests

* Iterate types

* Fix test
This commit is contained in:
Michael Telatynski
2023-04-26 10:36:00 +01:00
committed by GitHub
parent e4610e4672
commit 6166dbb661
23 changed files with 259 additions and 78 deletions

View File

@@ -305,7 +305,7 @@ describe("LegacyCallHandler", () => {
MatrixClientPeg.unset();
document.body.removeChild(audioElement);
SdkConfig.unset();
SdkConfig.reset();
});
it("should look up the correct user and start a call in the room when a phone number is dialled", async () => {
@@ -516,7 +516,7 @@ describe("LegacyCallHandler without third party protocols", () => {
MatrixClientPeg.unset();
document.body.removeChild(audioElement);
SdkConfig.unset();
SdkConfig.reset();
});
it("should still start a native call", async () => {

View File

@@ -77,7 +77,7 @@ describe("PosthogAnalytics", () => {
Object.defineProperty(window, "crypto", {
value: null,
});
SdkConfig.unset(); // we touch the config, so clean up
SdkConfig.reset(); // we touch the config, so clean up
});
describe("Initialisation", () => {

View File

@@ -30,6 +30,9 @@ describe("SdkConfig", () => {
chunk_length: 42,
max_length: 1337,
},
feedback: {
existing_issues_url: "https://existing",
} as any,
});
});
@@ -37,7 +40,16 @@ describe("SdkConfig", () => {
const customConfig = JSON.parse(JSON.stringify(DEFAULTS));
customConfig.voice_broadcast.chunk_length = 42;
customConfig.voice_broadcast.max_length = 1337;
customConfig.feedback.existing_issues_url = "https://existing";
expect(SdkConfig.get()).toEqual(customConfig);
});
it("should allow overriding individual fields of sub-objects", () => {
const feedback = SdkConfig.getObject("feedback");
expect(feedback.get("existing_issues_url")).toMatchInlineSnapshot(`"https://existing"`);
expect(feedback.get("new_issue_url")).toMatchInlineSnapshot(
`"https://github.com/vector-im/element-web/issues/new/choose"`,
);
});
});
});

View File

@@ -61,7 +61,7 @@ describe("Login", function () {
afterEach(function () {
fetchMock.restore();
SdkConfig.unset(); // we touch the config, so clean up
SdkConfig.reset(); // we touch the config, so clean up
unmockPlatformPeg();
});

View File

@@ -66,7 +66,7 @@ describe("Registration", function () {
afterEach(function () {
fetchMock.restore();
SdkConfig.unset(); // we touch the config, so clean up
SdkConfig.reset(); // we touch the config, so clean up
unmockPlatformPeg();
});

View File

@@ -23,7 +23,7 @@ import SdkConfig from "../../../../src/SdkConfig";
describe("CountryDropdown", () => {
describe("default_country_code", () => {
afterEach(() => {
SdkConfig.unset();
SdkConfig.reset();
});
it.each([

View File

@@ -0,0 +1,35 @@
/*
Copyright 2023 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 { render } from "@testing-library/react";
import SdkConfig from "../../../../src/SdkConfig";
import FeedbackDialog from "../../../../src/components/views/dialogs/FeedbackDialog";
describe("FeedbackDialog", () => {
it("should respect feedback config", () => {
SdkConfig.put({
feedback: {
existing_issues_url: "http://existing?foo=bar",
new_issue_url: "https://new.issue.url?foo=bar",
},
});
const { asFragment } = render(<FeedbackDialog onFinished={jest.fn()} />);
expect(asFragment()).toMatchSnapshot();
});
});

View File

@@ -0,0 +1,82 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`FeedbackDialog should respect feedback config 1`] = `
<DocumentFragment>
<div
data-focus-guard="true"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="0"
/>
<div
aria-describedby="mx_Dialog_content"
aria-labelledby="mx_BaseDialog_title"
class="mx_QuestionDialog mx_FeedbackDialog mx_Dialog_fixedWidth"
data-focus-lock-disabled="false"
role="dialog"
>
<div
class="mx_Dialog_header"
>
<h2
class="mx_Heading_h2 mx_Dialog_title"
id="mx_BaseDialog_title"
>
Feedback
</h2>
</div>
<div
class="mx_Dialog_content"
id="mx_Dialog_content"
>
<div
class="mx_FeedbackDialog_section mx_FeedbackDialog_reportBug"
>
<h3>
Report a bug
</h3>
<p>
<span>
Please view
<a
href="http://existing?foo=bar"
rel="noreferrer noopener"
target="_blank"
>
existing bugs on Github
</a>
first. No match?
<a
href="https://new.issue.url?foo=bar"
rel="noreferrer noopener"
target="_blank"
>
Start a new one
</a>
.
</span>
</p>
</div>
</div>
<div
class="mx_Dialog_buttons"
>
<span
class="mx_Dialog_buttons_row"
>
<button
class="mx_Dialog_primary"
data-testid="dialog-primary-button"
type="button"
>
Go back
</button>
</span>
</div>
</div>
<div
data-focus-guard="true"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="0"
/>
</DocumentFragment>
`;

View File

@@ -120,7 +120,7 @@ describe("RoomHeader", () => {
await Promise.all([CallStore.instance, WidgetStore.instance].map(resetAsyncStoreWithClient));
client.reEmitter.stopReEmitting(room, [RoomStateEvent.Events]);
jest.restoreAllMocks();
SdkConfig.put({});
SdkConfig.reset();
});
const mockRoomType = (type: string) => {

View File

@@ -42,7 +42,7 @@ async function setupTranslationOverridesForTests(overrides: ICustomTranslations)
describe("languageHandler", () => {
afterEach(() => {
SdkConfig.unset();
SdkConfig.reset();
CustomTranslationOptions.lookupFn = undefined;
});

View File

@@ -20,6 +20,8 @@ import BasePlatform from "../../../src/BasePlatform";
import { IConfigOptions } from "../../../src/IConfigOptions";
import { getDeviceClientInformation, recordClientInformation } from "../../../src/utils/device/clientInformation";
import { getMockClientWithEventEmitter } from "../../test-utils";
import { DEFAULTS } from "../../../src/SdkConfig";
import { DeepReadonly } from "../../../src/@types/common";
describe("recordClientInformation()", () => {
const deviceId = "my-device-id";
@@ -31,7 +33,8 @@ describe("recordClientInformation()", () => {
setAccountData: jest.fn(),
});
const sdkConfig: IConfigOptions = {
const sdkConfig: DeepReadonly<IConfigOptions> = {
...DEFAULTS,
brand: "Test Brand",
element_call: { url: "", use_exclusively: false, brand: "Element Call" },
};

View File

@@ -14,24 +14,24 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { mocked } from "jest-mock";
import SdkConfig, { DEFAULTS } from "../../../src/SdkConfig";
import SdkConfig from "../../../src/SdkConfig";
import { SettingLevel } from "../../../src/settings/SettingLevel";
import { Features } from "../../../src/settings/Settings";
import SettingsStore from "../../../src/settings/SettingsStore";
import { getChunkLength } from "../../../src/voice-broadcast/utils/getChunkLength";
jest.mock("../../../src/SdkConfig");
describe("getChunkLength", () => {
afterEach(() => {
jest.resetAllMocks();
SdkConfig.reset();
});
describe("when there is a value provided by Sdk config", () => {
beforeEach(() => {
mocked(SdkConfig.get).mockReturnValue({ chunk_length: 42 });
SdkConfig.add({
voice_broadcast: {
chunk_length: 42,
},
});
});
it("should return this value", () => {
@@ -41,9 +41,11 @@ describe("getChunkLength", () => {
describe("when Sdk config does not provide a value", () => {
beforeEach(() => {
DEFAULTS.voice_broadcast = {
chunk_length: 23,
};
SdkConfig.add({
voice_broadcast: {
chunk_length: 23,
},
});
});
it("should return this value", () => {
@@ -52,10 +54,6 @@ describe("getChunkLength", () => {
});
describe("when there are no defaults", () => {
beforeEach(() => {
DEFAULTS.voice_broadcast = undefined;
});
it("should return the fallback value", () => {
expect(getChunkLength()).toBe(120);
});

View File

@@ -14,21 +14,21 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { mocked } from "jest-mock";
import SdkConfig, { DEFAULTS } from "../../../src/SdkConfig";
import { getMaxBroadcastLength } from "../../../src/voice-broadcast";
jest.mock("../../../src/SdkConfig");
describe("getMaxBroadcastLength", () => {
afterEach(() => {
jest.resetAllMocks();
SdkConfig.reset();
});
describe("when there is a value provided by Sdk config", () => {
beforeEach(() => {
mocked(SdkConfig.get).mockReturnValue({ max_length: 42 });
SdkConfig.put({
voice_broadcast: {
max_length: 42,
},
});
});
it("should return this value", () => {
@@ -37,23 +37,14 @@ describe("getMaxBroadcastLength", () => {
});
describe("when Sdk config does not provide a value", () => {
beforeEach(() => {
DEFAULTS.voice_broadcast = {
max_length: 23,
};
});
it("should return this value", () => {
expect(getMaxBroadcastLength()).toBe(23);
expect(getMaxBroadcastLength()).toBe(DEFAULTS.voice_broadcast!.max_length);
});
});
describe("if there are no defaults", () => {
beforeEach(() => {
DEFAULTS.voice_broadcast = undefined;
});
it("should return the fallback value", () => {
expect(DEFAULTS.voice_broadcast!.max_length).toBe(4 * 60 * 60);
expect(getMaxBroadcastLength()).toBe(4 * 60 * 60);
});
});