diff --git a/src/components/views/dialogs/IntegrationsDisabledDialog.tsx b/src/components/views/dialogs/IntegrationsDisabledDialog.tsx index ad0f7654136..93cd5f82c99 100644 --- a/src/components/views/dialogs/IntegrationsDisabledDialog.tsx +++ b/src/components/views/dialogs/IntegrationsDisabledDialog.tsx @@ -1,55 +1,53 @@ /* -Copyright 2024 New Vector Ltd. +Copyright 2024, 2025 New Vector Ltd. Copyright 2019 The Matrix.org Foundation C.I.C. SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial Please see LICENSE files in the repository root for full details. */ -import React from "react"; +import React, { useCallback } from "react"; import { _t } from "../../../languageHandler"; import dis from "../../../dispatcher/dispatcher"; import { Action } from "../../../dispatcher/actions"; import BaseDialog from "./BaseDialog"; import DialogButtons from "../elements/DialogButtons"; +import { UserTab } from "./UserTab"; interface IProps { onFinished(): void; } -export default class IntegrationsDisabledDialog extends React.Component { - private onAcknowledgeClick = (): void => { - this.props.onFinished(); - }; +export const IntegrationsDisabledDialog: React.FC = ({ onFinished }) => { + const onOpenSettingsClick = useCallback(() => { + onFinished(); + dis.dispatch({ + action: Action.ViewUserSettings, + initialTabId: UserTab.Security, + }); + }, [onFinished]); - private onOpenSettingsClick = (): void => { - this.props.onFinished(); - dis.fire(Action.ViewUserSettings); - }; - - public render(): React.ReactNode { - return ( - -
-

- {_t("integrations|disabled_dialog_description", { - manageIntegrations: _t("integration_manager|manage_title"), - })} -

-
- -
- ); - } -} + return ( + +
+

+ {_t("integrations|disabled_dialog_description", { + manageIntegrations: _t("integration_manager|manage_title"), + })} +

+
+ +
+ ); +}; diff --git a/src/integrations/IntegrationManagers.ts b/src/integrations/IntegrationManagers.ts index 6d8ab69ccc8..7c2fc48adcf 100644 --- a/src/integrations/IntegrationManagers.ts +++ b/src/integrations/IntegrationManagers.ts @@ -13,7 +13,7 @@ import SdkConfig from "../SdkConfig"; import Modal from "../Modal"; import { IntegrationManagerInstance, Kind } from "./IntegrationManagerInstance"; import IntegrationsImpossibleDialog from "../components/views/dialogs/IntegrationsImpossibleDialog"; -import IntegrationsDisabledDialog from "../components/views/dialogs/IntegrationsDisabledDialog"; +import { IntegrationsDisabledDialog } from "../components/views/dialogs/IntegrationsDisabledDialog"; import WidgetUtils from "../utils/WidgetUtils"; import { MatrixClientPeg } from "../MatrixClientPeg"; diff --git a/test/unit-tests/components/views/dialogs/IntegrationsDisabledDialog-test.tsx b/test/unit-tests/components/views/dialogs/IntegrationsDisabledDialog-test.tsx new file mode 100644 index 00000000000..e89e33f4cda --- /dev/null +++ b/test/unit-tests/components/views/dialogs/IntegrationsDisabledDialog-test.tsx @@ -0,0 +1,46 @@ +/* + * Copyright 2025 New Vector Ltd. + * + * SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial + * Please see LICENSE files in the repository root for full details. + */ + +import React from "react"; +import { fireEvent, render } from "jest-matrix-react"; + +import { IntegrationsDisabledDialog } from "../../../../../src/components/views/dialogs/IntegrationsDisabledDialog.tsx"; +import defaultDispatcher from "../../../../../src/dispatcher/dispatcher.ts"; +import { Action } from "../../../../../src/dispatcher/actions.ts"; +import { UserTab } from "../../../../../src/components/views/dialogs/UserTab.ts"; + +describe("", () => { + const onFinished = jest.fn(); + + afterEach(() => { + jest.restoreAllMocks(); + }); + + function renderComponent() { + return render(); + } + + it("should render as expected", () => { + const { asFragment } = renderComponent(); + expect(asFragment()).toMatchSnapshot(); + }); + it("should do nothing on clicking OK", () => { + const { getByText } = renderComponent(); + fireEvent.click(getByText("OK")); + expect(onFinished).toHaveBeenCalled(); + }); + it("should open the correct user settings tab on clicking Settings", () => { + jest.spyOn(defaultDispatcher, "dispatch").mockImplementation(() => {}); + const { getByText } = renderComponent(); + fireEvent.click(getByText("Settings")); + expect(onFinished).toHaveBeenCalled(); + expect(defaultDispatcher.dispatch).toHaveBeenCalledWith({ + action: Action.ViewUserSettings, + initialTabId: UserTab.Security, + }); + }); +}); diff --git a/test/unit-tests/components/views/dialogs/__snapshots__/IntegrationsDisabledDialog-test.tsx.snap b/test/unit-tests/components/views/dialogs/__snapshots__/IntegrationsDisabledDialog-test.tsx.snap new file mode 100644 index 00000000000..24905f01302 --- /dev/null +++ b/test/unit-tests/components/views/dialogs/__snapshots__/IntegrationsDisabledDialog-test.tsx.snap @@ -0,0 +1,68 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` should render as expected 1`] = ` + +
+