mirror of
https://github.com/vector-im/element-web.git
synced 2025-12-28 12:41:54 +01:00
Co-authored-by: github-merge-queue <118344674+github-merge-queue@users.noreply.github.com> Co-authored-by: github-merge-queue <github-merge-queue@users.noreply.github.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Florian Duros <florian.duros@ormaz.fr> Co-authored-by: Kim Brose <kim.brose@nordeck.net> Co-authored-by: Florian Duros <florianduros@element.io> Co-authored-by: R Midhun Suresh <hi@midhun.dev> Co-authored-by: dbkr <986903+dbkr@users.noreply.github.com> Co-authored-by: ElementRobot <releases@riot.im> Co-authored-by: dbkr <dbkr@users.noreply.github.com> Co-authored-by: David Baker <dbkr@users.noreply.github.com> Co-authored-by: Michael Telatynski <7t3chguy@gmail.com> Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Co-authored-by: David Langley <davidl@element.io> Co-authored-by: Michael Weimann <michaelw@matrix.org> Co-authored-by: Timshel <Timshel@users.noreply.github.com> Co-authored-by: Sahil Silare <32628578+sahil9001@users.noreply.github.com> Co-authored-by: Will Hunt <will@half-shot.uk> Co-authored-by: Hubert Chathi <hubert@uhoreg.ca> Co-authored-by: Andrew Ferrazzutti <andrewf@element.io> Co-authored-by: Robin <robin@robin.town> Co-authored-by: Tulir Asokan <tulir@maunium.net>
97 lines
3.9 KiB
TypeScript
97 lines
3.9 KiB
TypeScript
/*
|
|
Copyright 2024 New Vector Ltd.
|
|
Copyright 2024 The Matrix.org Foundation C.I.C.
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
Please see LICENSE files in the repository root for full details.
|
|
*/
|
|
|
|
import React from "react";
|
|
import { fireEvent, render, screen, waitFor, within } from "jest-matrix-react";
|
|
import { logger } from "matrix-js-sdk/src/logger";
|
|
|
|
import MatrixClientContext from "../../../../../src/contexts/MatrixClientContext";
|
|
import { SDKContext, SdkContextClass } from "../../../../../src/contexts/SDKContext";
|
|
import SettingsStore from "../../../../../src/settings/SettingsStore";
|
|
import { UIFeature } from "../../../../../src/settings/UIFeature";
|
|
import {
|
|
getMockClientWithEventEmitter,
|
|
mockClientMethodsServer,
|
|
mockClientMethodsUser,
|
|
flushPromises,
|
|
} from "../../../../test-utils";
|
|
import SetIntegrationManager from "../../../../../src/components/views/settings/SetIntegrationManager";
|
|
import { SettingLevel } from "../../../../../src/settings/SettingLevel";
|
|
|
|
describe("SetIntegrationManager", () => {
|
|
const userId = "@alice:server.org";
|
|
|
|
const mockClient = getMockClientWithEventEmitter({
|
|
...mockClientMethodsUser(userId),
|
|
...mockClientMethodsServer(),
|
|
getCapabilities: jest.fn(),
|
|
getThreePids: jest.fn(),
|
|
getIdentityServerUrl: jest.fn(),
|
|
deleteThreePid: jest.fn(),
|
|
});
|
|
|
|
let stores: SdkContextClass;
|
|
|
|
const getComponent = () => (
|
|
<MatrixClientContext.Provider value={mockClient}>
|
|
<SDKContext.Provider value={stores}>
|
|
<SetIntegrationManager />
|
|
</SDKContext.Provider>
|
|
</MatrixClientContext.Provider>
|
|
);
|
|
|
|
it("should not render manage integrations section when widgets feature is disabled", () => {
|
|
jest.spyOn(SettingsStore, "getValue").mockImplementation((settingName) => settingName !== UIFeature.Widgets);
|
|
render(getComponent());
|
|
|
|
expect(screen.queryByTestId("mx_SetIntegrationManager")).not.toBeInTheDocument();
|
|
expect(SettingsStore.getValue).toHaveBeenCalledWith(UIFeature.Widgets);
|
|
});
|
|
it("should render manage integrations sections", () => {
|
|
jest.spyOn(SettingsStore, "getValue").mockImplementation((settingName) => settingName === UIFeature.Widgets);
|
|
|
|
render(getComponent());
|
|
|
|
expect(screen.getByTestId("mx_SetIntegrationManager")).toMatchSnapshot();
|
|
});
|
|
it("should update integrations provisioning on toggle", () => {
|
|
jest.spyOn(SettingsStore, "getValue").mockImplementation((settingName) => settingName === UIFeature.Widgets);
|
|
jest.spyOn(SettingsStore, "setValue").mockResolvedValue(undefined);
|
|
|
|
render(getComponent());
|
|
|
|
const integrationSection = screen.getByTestId("mx_SetIntegrationManager");
|
|
fireEvent.click(within(integrationSection).getByRole("switch"));
|
|
|
|
expect(SettingsStore.setValue).toHaveBeenCalledWith(
|
|
"integrationProvisioning",
|
|
null,
|
|
SettingLevel.ACCOUNT,
|
|
true,
|
|
);
|
|
expect(within(integrationSection).getByRole("switch")).toBeChecked();
|
|
});
|
|
it("handles error when updating setting fails", async () => {
|
|
jest.spyOn(SettingsStore, "getValue").mockImplementation((settingName) => settingName === UIFeature.Widgets);
|
|
jest.spyOn(logger, "error").mockImplementation(() => {});
|
|
|
|
jest.spyOn(SettingsStore, "setValue").mockRejectedValue("oups");
|
|
|
|
render(getComponent());
|
|
|
|
const integrationSection = screen.getByTestId("mx_SetIntegrationManager");
|
|
fireEvent.click(within(integrationSection).getByRole("switch"));
|
|
|
|
await flushPromises();
|
|
|
|
expect(logger.error).toHaveBeenCalledWith("Error changing integration manager provisioning");
|
|
expect(logger.error).toHaveBeenCalledWith("oups");
|
|
await waitFor(() => expect(within(integrationSection).getByRole("switch")).not.toBeChecked());
|
|
});
|
|
});
|