2022-10-11 11:10:55 +02:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2022-10-11 11:10:55 +02:00
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
2025-01-06 11:18:54 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-09 14:57:16 +01:00
|
|
|
Please see LICENSE files in the repository root for full details.
|
2022-10-11 11:10:55 +02:00
|
|
|
*/
|
2024-10-14 21:41:58 +05:30
|
|
|
import { render } from "jest-matrix-react";
|
2025-04-08 10:08:00 +01:00
|
|
|
import React, { act } from "react";
|
|
|
|
|
import userEvent from "@testing-library/user-event";
|
2022-10-11 11:10:55 +02:00
|
|
|
|
2024-10-15 14:57:26 +01:00
|
|
|
import SecurityUserSettingsTab from "../../../../../../../src/components/views/settings/tabs/user/SecurityUserSettingsTab";
|
|
|
|
|
import MatrixClientContext from "../../../../../../../src/contexts/MatrixClientContext";
|
2022-10-11 11:10:55 +02:00
|
|
|
import {
|
|
|
|
|
getMockClientWithEventEmitter,
|
|
|
|
|
mockClientMethodsServer,
|
|
|
|
|
mockClientMethodsUser,
|
|
|
|
|
mockClientMethodsCrypto,
|
|
|
|
|
mockClientMethodsDevice,
|
|
|
|
|
mockPlatformPeg,
|
2024-10-15 14:57:26 +01:00
|
|
|
} from "../../../../../../test-utils";
|
|
|
|
|
import { SDKContext, SdkContextClass } from "../../../../../../../src/contexts/SDKContext";
|
2025-04-08 10:08:00 +01:00
|
|
|
import defaultDispatcher from "../../../../../../../src/dispatcher/dispatcher";
|
2022-10-11 11:10:55 +02:00
|
|
|
|
|
|
|
|
describe("<SecurityUserSettingsTab />", () => {
|
|
|
|
|
const defaultProps = {
|
|
|
|
|
closeSettingsFn: jest.fn(),
|
|
|
|
|
};
|
|
|
|
|
|
2025-04-08 10:08:00 +01:00
|
|
|
const getIgnoredUsers = jest.fn();
|
|
|
|
|
const setIgnoredUsers = jest.fn();
|
|
|
|
|
|
2022-10-11 11:10:55 +02:00
|
|
|
const userId = "@alice:server.org";
|
|
|
|
|
const deviceId = "alices-device";
|
2022-10-19 13:31:20 +01:00
|
|
|
const mockClient = getMockClientWithEventEmitter({
|
2022-10-11 11:10:55 +02:00
|
|
|
...mockClientMethodsUser(userId),
|
|
|
|
|
...mockClientMethodsServer(),
|
|
|
|
|
...mockClientMethodsDevice(deviceId),
|
|
|
|
|
...mockClientMethodsCrypto(),
|
|
|
|
|
getRooms: jest.fn().mockReturnValue([]),
|
2025-04-08 10:08:00 +01:00
|
|
|
getPushers: jest.fn().mockReturnValue([]),
|
|
|
|
|
getIgnoredUsers,
|
|
|
|
|
setIgnoredUsers,
|
2022-10-11 11:10:55 +02:00
|
|
|
});
|
|
|
|
|
|
2024-04-15 11:47:15 -04:00
|
|
|
const sdkContext = new SdkContextClass();
|
|
|
|
|
sdkContext.client = mockClient;
|
|
|
|
|
|
2022-10-19 13:31:20 +01:00
|
|
|
const getComponent = () => (
|
|
|
|
|
<MatrixClientContext.Provider value={mockClient}>
|
2024-04-15 11:47:15 -04:00
|
|
|
<SDKContext.Provider value={sdkContext}>
|
|
|
|
|
<SecurityUserSettingsTab {...defaultProps} />
|
|
|
|
|
</SDKContext.Provider>
|
2022-10-19 13:31:20 +01:00
|
|
|
</MatrixClientContext.Provider>
|
|
|
|
|
);
|
|
|
|
|
|
2022-10-11 11:10:55 +02:00
|
|
|
beforeEach(() => {
|
|
|
|
|
mockPlatformPeg();
|
|
|
|
|
jest.clearAllMocks();
|
|
|
|
|
});
|
|
|
|
|
|
2023-05-26 13:58:28 +12:00
|
|
|
it("renders security section", () => {
|
|
|
|
|
const { container } = render(getComponent());
|
2022-10-11 11:10:55 +02:00
|
|
|
|
2023-05-26 13:58:28 +12:00
|
|
|
expect(container).toMatchSnapshot();
|
2022-10-19 17:11:42 +02:00
|
|
|
});
|
2025-04-08 10:08:00 +01:00
|
|
|
|
|
|
|
|
it("renders ignored users", () => {
|
|
|
|
|
getIgnoredUsers.mockReturnValue(["@bob:example.org"]);
|
|
|
|
|
const { getByRole } = render(getComponent());
|
|
|
|
|
const ignoredUsers = getByRole("list", { name: "Ignored users" });
|
|
|
|
|
|
|
|
|
|
expect(ignoredUsers).toMatchSnapshot();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("allows unignoring a user", async () => {
|
|
|
|
|
getIgnoredUsers.mockReturnValue(["@bob:example.org"]);
|
|
|
|
|
const { getByText, getByRole } = render(getComponent());
|
|
|
|
|
await userEvent.click(getByRole("button", { name: "Unignore" }));
|
|
|
|
|
expect(setIgnoredUsers).toHaveBeenCalledWith([]);
|
|
|
|
|
await act(() => {
|
|
|
|
|
getIgnoredUsers.mockReturnValue([]);
|
|
|
|
|
defaultDispatcher.dispatch(
|
|
|
|
|
{
|
|
|
|
|
action: "ignore_state_changed",
|
|
|
|
|
},
|
|
|
|
|
true,
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
expect(getByText("You have no ignored users.")).toBeVisible();
|
|
|
|
|
});
|
2022-10-11 11:10:55 +02:00
|
|
|
});
|