2024-07-10 19:10:19 +00:00
|
|
|
/*
|
2024-09-09 13:57:16 +00:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2024-07-10 19:10:19 +00:00
|
|
|
Copyright 2024 The Matrix.org Foundation C.I.C.
|
|
|
|
|
2024-09-09 13:57:16 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2024-07-10 19:10:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
import React from "react";
|
2024-10-14 16:11:58 +00:00
|
|
|
import { fireEvent, render, screen, waitFor, within } from "jest-matrix-react";
|
2024-07-10 19:10:19 +00:00
|
|
|
import { logger } from "matrix-js-sdk/src/logger";
|
|
|
|
|
2024-10-15 13:57:26 +00:00
|
|
|
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";
|
2024-07-10 19:10:19 +00:00
|
|
|
import {
|
|
|
|
getMockClientWithEventEmitter,
|
|
|
|
mockClientMethodsServer,
|
|
|
|
mockClientMethodsUser,
|
|
|
|
flushPromises,
|
2024-10-15 13:57:26 +00:00
|
|
|
} from "../../../../test-utils";
|
|
|
|
import SetIntegrationManager from "../../../../../src/components/views/settings/SetIntegrationManager";
|
|
|
|
import { SettingLevel } from "../../../../../src/settings/SettingLevel";
|
2024-07-10 19:10:19 +00:00
|
|
|
|
|
|
|
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");
|
2024-08-06 17:22:02 +00:00
|
|
|
await waitFor(() => expect(within(integrationSection).getByRole("switch")).not.toBeChecked());
|
2024-07-10 19:10:19 +00:00
|
|
|
});
|
|
|
|
});
|