You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-07-30 02:21:17 +03:00
Add sign out button to settings profile section (#12666)
* Add sign out button to settings profile section And move the logic for displaying the dialog out of the user menu to somewhere it can be re-used. Also close any open dialog on logout, because otherwise, well... you can guess. * Missing import * Update screenshot * This button doesn't need to be an anchor * Use Flex component * Use new force-close function * More tests
This commit is contained in:
@ -18,12 +18,15 @@ import React, { ChangeEvent } from "react";
|
||||
import { act, render, screen } from "@testing-library/react";
|
||||
import { MatrixClient, UploadResponse } from "matrix-js-sdk/src/matrix";
|
||||
import { mocked } from "jest-mock";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
|
||||
import UserProfileSettings from "../../../../src/components/views/settings/UserProfileSettings";
|
||||
import { stubClient } from "../../../test-utils";
|
||||
import { mkStubRoom, stubClient } from "../../../test-utils";
|
||||
import { ToastContext, ToastRack } from "../../../../src/contexts/ToastContext";
|
||||
import { OwnProfileStore } from "../../../../src/stores/OwnProfileStore";
|
||||
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
|
||||
import dis from "../../../../src/dispatcher/dispatcher";
|
||||
import Modal from "../../../../src/Modal";
|
||||
|
||||
interface MockedAvatarSettingProps {
|
||||
removeAvatar: () => void;
|
||||
@ -43,6 +46,11 @@ jest.mock(
|
||||
}) as React.FC<MockedAvatarSettingProps>,
|
||||
);
|
||||
|
||||
jest.mock("../../../../src/dispatcher/dispatcher", () => ({
|
||||
dispatch: jest.fn(),
|
||||
register: jest.fn(),
|
||||
}));
|
||||
|
||||
let editInPlaceOnChange: (e: ChangeEvent<HTMLInputElement>) => void;
|
||||
let editInPlaceOnSave: () => void;
|
||||
let editInPlaceOnCancel: () => void;
|
||||
@ -209,4 +217,30 @@ describe("ProfileSettings", () => {
|
||||
|
||||
expect(await screen.findByText("Mocked EditInPlace: Alice")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("signs out directly if no rooms are encrypted", async () => {
|
||||
renderProfileSettings(toastRack, client);
|
||||
|
||||
const signOutButton = await screen.findByText("Sign out");
|
||||
await userEvent.click(signOutButton);
|
||||
|
||||
expect(dis.dispatch).toHaveBeenCalledWith({ action: "logout" });
|
||||
});
|
||||
|
||||
it("displays confirmation dialog if rooms are encrypted", async () => {
|
||||
jest.spyOn(Modal, "createDialog");
|
||||
|
||||
const mockRoom = mkStubRoom("!test:room", "Test Room", client);
|
||||
client.getRooms = jest.fn().mockReturnValue([mockRoom]);
|
||||
client.getCrypto = jest.fn().mockReturnValue({
|
||||
isEncryptionEnabledInRoom: jest.fn().mockReturnValue(true),
|
||||
});
|
||||
|
||||
renderProfileSettings(toastRack, client);
|
||||
|
||||
const signOutButton = await screen.findByText("Sign out");
|
||||
await userEvent.click(signOutButton);
|
||||
|
||||
expect(Modal.createDialog).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user