Disable URL Preview setting if disabled on the homeserver (#33279)
* Disallow URL Previews if disabled by homeserver. * Cleanup nonsense * cleanup * cleanup * fixes * Remove import * Add an error handler * cleanup
This commit is contained in:
@@ -71,6 +71,7 @@ import ErrorDialog from "../../../../src/components/views/dialogs/ErrorDialog.ts
|
||||
import * as pinnedEventHooks from "../../../../src/hooks/usePinnedEvents";
|
||||
import { TimelineRenderingType } from "../../../../src/contexts/RoomContext";
|
||||
import { ModuleApi } from "../../../../src/modules/Api";
|
||||
import MatrixClientBackedController from "../../../../src/settings/controllers/MatrixClientBackedController.ts";
|
||||
import { type ComposerInsertPayload, ComposerType } from "../../../../src/dispatcher/payloads/ComposerInsertPayload.ts";
|
||||
|
||||
// Used by group calls
|
||||
@@ -93,6 +94,7 @@ describe("RoomView", () => {
|
||||
beforeEach(() => {
|
||||
mockPlatformPeg({ reload: () => {} });
|
||||
cli = mocked(stubClient());
|
||||
MatrixClientBackedController.matrixClient = cli;
|
||||
|
||||
const roomName = (expect.getState().currentTestName ?? "").replace(/[^a-zA-Z0-9]/g, "").toLowerCase();
|
||||
|
||||
|
||||
+11
-1
@@ -12,7 +12,13 @@ import userEvent from "@testing-library/user-event";
|
||||
|
||||
import PreferencesUserSettingsTab from "../../../../../../../src/components/views/settings/tabs/user/PreferencesUserSettingsTab";
|
||||
import { MatrixClientPeg } from "../../../../../../../src/MatrixClientPeg";
|
||||
import { mockPlatformPeg, stubClient } from "../../../../../../test-utils";
|
||||
import {
|
||||
getMockClientWithEventEmitter,
|
||||
mockClientMethodsServer,
|
||||
mockClientMethodsUser,
|
||||
mockPlatformPeg,
|
||||
stubClient,
|
||||
} from "../../../../../../test-utils";
|
||||
import SettingsStore from "../../../../../../../src/settings/SettingsStore";
|
||||
import { SettingLevel } from "../../../../../../../src/settings/SettingLevel";
|
||||
import MatrixClientBackedController from "../../../../../../../src/settings/controllers/MatrixClientBackedController";
|
||||
@@ -29,6 +35,10 @@ describe("PreferencesUserSettingsTab", () => {
|
||||
};
|
||||
|
||||
it("should render", () => {
|
||||
MatrixClientBackedController.matrixClient = getMockClientWithEventEmitter({
|
||||
...mockClientMethodsServer(),
|
||||
...mockClientMethodsUser(),
|
||||
});
|
||||
const { asFragment } = renderTab();
|
||||
expect(asFragment()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
@@ -5,9 +5,12 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import type { Capabilities } from "matrix-js-sdk/src/matrix";
|
||||
import RequiresSettingsController from "../../../../src/settings/controllers/RequiresSettingsController";
|
||||
import { SettingLevel } from "../../../../src/settings/SettingLevel";
|
||||
import SettingsStore from "../../../../src/settings/SettingsStore";
|
||||
import MatrixClientBackedController from "../../../../src/settings/controllers/MatrixClientBackedController";
|
||||
import { getMockClientWithEventEmitter, mockClientMethodsServer } from "../../../test-utils";
|
||||
|
||||
describe("RequiresSettingsController", () => {
|
||||
afterEach(() => {
|
||||
@@ -30,4 +33,107 @@ describe("RequiresSettingsController", () => {
|
||||
expect(controller.settingDisabled).toEqual(false);
|
||||
expect(controller.getValueOverride()).toEqual(null);
|
||||
});
|
||||
|
||||
describe("with capabilites", () => {
|
||||
let client: ReturnType<typeof getMockClientWithEventEmitter>;
|
||||
beforeEach(() => {
|
||||
client = getMockClientWithEventEmitter({
|
||||
...mockClientMethodsServer(),
|
||||
getCachedCapabilities: jest.fn().mockImplementation(() => {}),
|
||||
getCapabilities: jest.fn().mockRejectedValue({}),
|
||||
});
|
||||
MatrixClientBackedController["_matrixClient"] = client;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
it("will disable setting if capability check is true", async () => {
|
||||
const caps = {
|
||||
"m.change_password": {
|
||||
enabled: false,
|
||||
},
|
||||
};
|
||||
client.getCachedCapabilities.mockImplementation(() => caps);
|
||||
const controller = new RequiresSettingsController([], false, (c: Capabilities) => {
|
||||
expect(c).toEqual(caps);
|
||||
return !c["m.change_password"]?.enabled;
|
||||
});
|
||||
|
||||
// Test that we fetch caps
|
||||
controller["initMatrixClient"]();
|
||||
expect(client.getCapabilities).toHaveBeenCalled();
|
||||
|
||||
// Test that we check caps.
|
||||
expect(controller.settingDisabled).toEqual(true);
|
||||
expect(controller.getValueOverride()).toEqual(false);
|
||||
expect(client.getCachedCapabilities).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("will not disable setting if capability check is false", async () => {
|
||||
const caps = {
|
||||
"m.change_password": {
|
||||
enabled: true,
|
||||
},
|
||||
};
|
||||
client.getCachedCapabilities.mockImplementation(() => caps);
|
||||
const controller = new RequiresSettingsController([], false, (c: Capabilities) => {
|
||||
expect(c).toEqual(caps);
|
||||
return !c["m.change_password"]?.enabled;
|
||||
});
|
||||
|
||||
// Test that we fetch caps
|
||||
controller["initMatrixClient"]();
|
||||
expect(client.getCapabilities).toHaveBeenCalled();
|
||||
|
||||
// Test that we check caps.
|
||||
expect(controller.settingDisabled).toEqual(false);
|
||||
expect(controller.getValueOverride()).toEqual(null);
|
||||
expect(client.getCachedCapabilities).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("will check dependency settings before checking capabilites", async () => {
|
||||
const caps = {
|
||||
"m.change_password": {
|
||||
enabled: false,
|
||||
},
|
||||
};
|
||||
client.getCachedCapabilities.mockImplementation(() => caps);
|
||||
await SettingsStore.setValue("useCompactLayout", null, SettingLevel.DEVICE, false);
|
||||
const controller = new RequiresSettingsController(["useCompactLayout"], false, (c: Capabilities) => false);
|
||||
|
||||
// Test that we fetch caps
|
||||
controller["initMatrixClient"]();
|
||||
expect(client.getCapabilities).toHaveBeenCalled();
|
||||
|
||||
// Test that we check caps.
|
||||
expect(controller.settingDisabled).toEqual(true);
|
||||
expect(controller.getValueOverride()).toEqual(false);
|
||||
expect(client.getCachedCapabilities).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("will disable setting if capability check is true and dependency settings are true", async () => {
|
||||
const caps = {
|
||||
"m.change_password": {
|
||||
enabled: false,
|
||||
},
|
||||
};
|
||||
client.getCachedCapabilities.mockImplementation(() => caps);
|
||||
await SettingsStore.setValue("useCompactLayout", null, SettingLevel.DEVICE, true);
|
||||
const controller = new RequiresSettingsController(["useCompactLayout"], false, (c: Capabilities) => {
|
||||
expect(c).toEqual(caps);
|
||||
return !c["m.change_password"]?.enabled;
|
||||
});
|
||||
|
||||
// Test that we fetch caps
|
||||
controller["initMatrixClient"]();
|
||||
expect(client.getCapabilities).toHaveBeenCalled();
|
||||
|
||||
// Test that we check caps.
|
||||
expect(controller.settingDisabled).toEqual(true);
|
||||
expect(controller.getValueOverride()).toEqual(false);
|
||||
expect(client.getCachedCapabilities).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user