Merge branch 'develop' into hs/media-previews-server-config

This commit is contained in:
Will Hunt
2025-04-08 15:04:34 +01:00
committed by GitHub
59 changed files with 1018 additions and 2629 deletions

View File

@@ -303,7 +303,9 @@ export function createTestClient(): MatrixClient {
getLocalAliases: jest.fn().mockReturnValue([]),
uploadDeviceSigningKeys: jest.fn(),
isKeyBackupKeyStored: jest.fn().mockResolvedValue(null),
getIgnoredUsers: jest.fn().mockReturnValue([]),
setIgnoredUsers: jest.fn(),
reportRoom: jest.fn(),
pushProcessor: {
getPushRuleById: jest.fn(),
},

View File

@@ -19,6 +19,7 @@ import {
MatrixEvent,
Room,
RoomEvent,
RoomMember,
RoomStateEvent,
SearchResult,
} from "matrix-js-sdk/src/matrix";
@@ -78,6 +79,7 @@ import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
import { type ViewUserPayload } from "../../../../src/dispatcher/payloads/ViewUserPayload.ts";
import { CallStore } from "../../../../src/stores/CallStore.ts";
import MediaDeviceHandler, { MediaDeviceKindEnum } from "../../../../src/MediaDeviceHandler.ts";
import Modal from "../../../../src/Modal.tsx";
// Used by group calls
jest.spyOn(MediaDeviceHandler, "getDevices").mockResolvedValue({
@@ -196,7 +198,7 @@ describe("RoomView", () => {
<RoomView
// threepidInvite should be optional on RoomView props
// it is treated as optional in RoomView
threepidInvite={undefined as any}
threepidInvite={undefined}
resizeNotifier={new ResizeNotifier()}
forceTimeline={false}
onRegistered={jest.fn()}
@@ -233,6 +235,62 @@ describe("RoomView", () => {
expect(instance.getHiddenHighlightCount()).toBe(0);
});
describe("invites", () => {
beforeEach(() => {
const member = new RoomMember(room.roomId, cli.getSafeUserId());
member.membership = KnownMembership.Invite;
member.events.member = new MatrixEvent({
sender: "@bob:example.org",
});
room.getMyMembership = jest.fn().mockReturnValue(KnownMembership.Invite);
room.getMember = jest.fn().mockReturnValue(member);
});
it("renders an invite room", async () => {
const { asFragment } = await mountRoomView();
expect(asFragment()).toMatchSnapshot();
});
it("handles accepting an invite", async () => {
const { getByRole } = await mountRoomView();
await fireEvent.click(getByRole("button", { name: "Accept" }));
await untilDispatch(Action.JoinRoomReady, defaultDispatcher);
});
it("handles declining an invite", async () => {
const { getByRole } = await mountRoomView();
jest.spyOn(Modal, "createDialog").mockReturnValue({
finished: Promise.resolve([true, false, false]),
close: jest.fn(),
});
await fireEvent.click(getByRole("button", { name: "Decline" }));
await waitFor(() => expect(cli.leave).toHaveBeenCalledWith(room.roomId));
expect(cli.setIgnoredUsers).not.toHaveBeenCalled();
});
it("handles declining an invite and ignoring the user", async () => {
const { getByRole } = await mountRoomView();
cli.getIgnoredUsers.mockReturnValue(["@carol:example.org"]);
jest.spyOn(Modal, "createDialog").mockReturnValue({
finished: Promise.resolve([true, true, false]),
close: jest.fn(),
});
await fireEvent.click(getByRole("button", { name: "Decline and block" }));
expect(cli.leave).toHaveBeenCalledWith(room.roomId);
expect(cli.setIgnoredUsers).toHaveBeenCalledWith(["@carol:example.org", "@bob:example.org"]);
});
it("handles declining an invite and reporting the room", async () => {
const { getByRole } = await mountRoomView();
jest.spyOn(Modal, "createDialog").mockReturnValue({
finished: Promise.resolve([true, false, "with a reason"]),
close: jest.fn(),
});
await fireEvent.click(getByRole("button", { name: "Decline and block" }));
expect(cli.leave).toHaveBeenCalledWith(room.roomId);
expect(cli.reportRoom).toHaveBeenCalledWith(room.roomId, "with a reason");
});
});
describe("when there is an old room", () => {
let instance: RoomView;
let oldRoom: Room;

View File

@@ -1264,6 +1264,79 @@ exports[`RoomView for a local room in state NEW that is encrypted should match t
</div>
`;
exports[`RoomView invites renders an invite room 1`] = `
<DocumentFragment>
<div
class="mx_RoomView"
>
<div
class="mx_RoomPreviewBar mx_RoomPreviewBar_Invite mx_RoomPreviewBar_dialog"
role="complementary"
>
<div
class="mx_RoomPreviewBar_message"
>
<h3>
Do you want to join !2:example.org?
</h3>
<p>
<span
class="_avatar_1qbcf_8 mx_BaseAvatar _avatar-imageless_1qbcf_52"
data-color="4"
data-testid="avatar-img"
data-type="round"
role="presentation"
style="--cpd-avatar-size: 36px;"
>
!
</span>
</p>
<p>
<span>
Invited by
<span
class="mx_RoomPreviewBar_inviter"
>
@bob:example.org
</span>
</span>
</p>
</div>
<div
class="mx_RoomPreviewBar_actions"
>
<div
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_primary"
role="button"
tabindex="0"
>
Accept
</div>
<div
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_secondary"
role="button"
tabindex="0"
>
Decline
</div>
<button
class="_button_vczzf_8 _destructive_vczzf_107"
data-kind="tertiary"
data-size="lg"
role="button"
tabindex="0"
>
Decline and block
</button>
</div>
<div
class="mx_RoomPreviewBar_footer"
/>
</div>
</div>
</DocumentFragment>
`;
exports[`RoomView should not display the timeline when the room encryption is loading 1`] = `
<DocumentFragment>
<div
@@ -1290,7 +1363,7 @@ exports[`RoomView should not display the timeline when the room encryption is lo
aria-label="Open room settings"
aria-live="off"
class="_avatar_1qbcf_8 mx_BaseAvatar _avatar-imageless_1qbcf_52"
data-color="2"
data-color="4"
data-testid="avatar-img"
data-type="round"
role="button"
@@ -1317,7 +1390,7 @@ exports[`RoomView should not display the timeline when the room encryption is lo
<span
class="mx_RoomHeader_truncated mx_lineClamp"
>
!6:example.org
!11:example.org
</span>
</div>
</div>
@@ -1498,7 +1571,7 @@ exports[`RoomView should not display the timeline when the room encryption is lo
aria-label="Open room settings"
aria-live="off"
class="_avatar_1qbcf_8 mx_BaseAvatar _avatar-imageless_1qbcf_52"
data-color="2"
data-color="4"
data-testid="avatar-img"
data-type="round"
role="button"
@@ -1525,7 +1598,7 @@ exports[`RoomView should not display the timeline when the room encryption is lo
<span
class="mx_RoomHeader_truncated mx_lineClamp"
>
!6:example.org
!11:example.org
</span>
</div>
</div>
@@ -1879,7 +1952,7 @@ exports[`RoomView video rooms should render joined video room view 1`] = `
aria-label="Open room settings"
aria-live="off"
class="_avatar_1qbcf_8 mx_BaseAvatar _avatar-imageless_1qbcf_52"
data-color="6"
data-color="5"
data-testid="avatar-img"
data-type="round"
role="button"
@@ -1906,7 +1979,7 @@ exports[`RoomView video rooms should render joined video room view 1`] = `
<span
class="mx_RoomHeader_truncated mx_lineClamp"
>
!13:example.org
!18:example.org
</span>
</div>
</div>

View File

@@ -77,9 +77,9 @@ describe("RoomListItemViewModel", () => {
it.each([
{
label: "unset message",
label: "unsent message",
mock: () => jest.spyOn(notificationState, "isUnsetMessage", "get").mockReturnValue(true),
expected: "Open room roomName with an unset message.",
expected: "Open room roomName with an unsent message.",
},
{
label: "invitation",

View File

@@ -22,6 +22,8 @@ import { hasCreateRoomRights, createRoom } from "../../../../../src/components/v
import dispatcher from "../../../../../src/dispatcher/dispatcher";
import { Action } from "../../../../../src/dispatcher/actions";
import { SdkContextClass } from "../../../../../src/contexts/SDKContext";
import SpaceStore from "../../../../../src/stores/spaces/SpaceStore";
import { UPDATE_SELECTED_SPACE } from "../../../../../src/stores/spaces";
jest.mock("../../../../../src/components/viewmodels/roomlist/utils", () => ({
hasCreateRoomRights: jest.fn().mockReturnValue(false),
@@ -185,6 +187,33 @@ describe("RoomListViewModel", () => {
expect(fn).toHaveBeenLastCalledWith(expect.arrayContaining([FilterKey.MentionsFilter]));
});
it("should remove all filters when active space is changed", async () => {
mockAndCreateRooms();
const { result: vm } = renderHook(() => useRoomListViewModel());
// Let's first toggle the People filter
const i = vm.current.primaryFilters.findIndex((f) => f.name === "People");
act(() => {
vm.current.primaryFilters[i].toggle();
});
expect(vm.current.primaryFilters[i].active).toEqual(true);
// Let's say we toggle the mentions secondary filter
act(() => {
vm.current.activateSecondaryFilter(SecondaryFilters.MentionsOnly);
});
expect(vm.current.activeSecondaryFilter).toEqual(SecondaryFilters.MentionsOnly);
// Simulate a space change
await act(() => SpaceStore.instance.emit(UPDATE_SELECTED_SPACE));
// Primary filer should have been unapplied
expect(vm.current.activePrimaryFilter).toEqual(undefined);
// Secondary filter should be reset to "All Activity"
expect(vm.current.activeSecondaryFilter).toEqual(SecondaryFilters.AllActivity);
});
const testcases: Array<[string, { secondary: SecondaryFilters; filterKey: FilterKey }, string]> = [
[
"Mentions only",

View File

@@ -0,0 +1,52 @@
/*
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 { render } from "jest-matrix-react";
import userEvent from "@testing-library/user-event";
import React from "react";
import SdkConfig from "../../../../../src/SdkConfig";
import { DeclineAndBlockInviteDialog } from "../../../../../src/components/views/dialogs/DeclineAndBlockInviteDialog";
describe("ConfirmRejectInviteDialog", () => {
const onFinished: jest.Mock<any, any> = jest.fn();
const MY_ROOM_NAME = "foo";
beforeEach(() => {
jest.resetAllMocks();
});
afterEach(() => {
SdkConfig.reset();
});
it("can close the dialog", async () => {
const { getByTestId } = render(<DeclineAndBlockInviteDialog onFinished={onFinished} roomName={MY_ROOM_NAME} />);
await userEvent.click(getByTestId("dialog-cancel-button"));
expect(onFinished).toHaveBeenCalledWith(false, false, false);
});
it("can reject with options selected", async () => {
const { container, getByLabelText, getByRole } = render(
<DeclineAndBlockInviteDialog onFinished={onFinished} roomName={MY_ROOM_NAME} />,
);
await userEvent.click(getByRole("switch", { name: "Ignore user" }));
await userEvent.click(getByRole("switch", { name: "Report room" }));
await userEvent.type(getByLabelText("Reason"), "I want to report this room");
expect(container).toMatchSnapshot();
await userEvent.click(getByRole("button", { name: "Decline invite" }));
expect(onFinished).toHaveBeenCalledWith(true, true, "I want to report this room");
});
it("can reject without a reason", async () => {
const { getByRole } = render(<DeclineAndBlockInviteDialog onFinished={onFinished} roomName={MY_ROOM_NAME} />);
await userEvent.click(getByRole("switch", { name: "Ignore user" }));
await userEvent.click(getByRole("switch", { name: "Report room" }));
await userEvent.click(getByRole("button", { name: "Decline invite" }));
expect(onFinished).toHaveBeenCalledWith(true, true, "");
});
});

View File

@@ -0,0 +1,151 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`ConfirmRejectInviteDialog can reject with options selected 1`] = `
<div>
<div
data-focus-guard="true"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="0"
/>
<div
aria-describedby="mx_Dialog_content"
aria-labelledby="mx_BaseDialog_title"
class="mx_DeclineAndBlockInviteDialog mx_Dialog_fixedWidth"
data-focus-lock-disabled="false"
role="dialog"
>
<div
class="mx_Dialog_header"
>
<h1
class="mx_Heading_h3 mx_Dialog_title"
id="mx_BaseDialog_title"
>
Decline invitation
</h1>
</div>
<form
class="_root_19upo_16"
>
<p>
Are you sure you want to decline the invitation to join "foo"?
</p>
<div
class="mx_SettingsFlag"
>
<span
class="mx_SettingsFlag_label"
>
<div
id="mx_LabelledToggleSwitch_:r7:"
>
Ignore user
</div>
<span
class="mx_Caption"
id="mx_LabelledToggleSwitch_:r7:_caption"
>
You will not see any messages or room invites from this user.
</span>
</span>
<div
aria-checked="true"
aria-describedby="mx_LabelledToggleSwitch_:r7:_caption"
aria-disabled="false"
aria-labelledby="mx_LabelledToggleSwitch_:r7:"
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_on mx_ToggleSwitch_enabled"
role="switch"
tabindex="0"
>
<div
class="mx_ToggleSwitch_ball"
/>
</div>
</div>
<div
class="mx_SettingsFlag"
>
<span
class="mx_SettingsFlag_label"
>
<div
id="mx_LabelledToggleSwitch_:r8:"
>
Report room
</div>
<span
class="mx_Caption"
id="mx_LabelledToggleSwitch_:r8:_caption"
>
Report this room to your account provider.
</span>
</span>
<div
aria-checked="true"
aria-describedby="mx_LabelledToggleSwitch_:r8:_caption"
aria-disabled="false"
aria-labelledby="mx_LabelledToggleSwitch_:r8:"
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_on mx_ToggleSwitch_enabled"
role="switch"
tabindex="0"
>
<div
class="mx_ToggleSwitch_ball"
/>
</div>
</div>
<div
aria-disabled="false"
class="_field_19upo_26"
>
<label
class="_label_19upo_59"
for="mx_DeclineAndBlockInviteDialog_reason"
>
Reason
</label>
<textarea
class="mx_RoomReportTextArea"
id="mx_DeclineAndBlockInviteDialog_reason"
placeholder="Describe the reason for reporting the room."
rows="5"
>
I want to report this room
</textarea>
</div>
<div
class="mx_Dialog_buttons"
>
<span
class="mx_Dialog_buttons_row"
>
<button
data-testid="dialog-cancel-button"
type="button"
>
Cancel
</button>
<button
class="mx_Dialog_primary danger"
data-testid="dialog-primary-button"
type="button"
>
Decline invite
</button>
</span>
</div>
</form>
<div
aria-label="Close dialog"
class="mx_AccessibleButton mx_Dialog_cancelButton"
role="button"
tabindex="0"
/>
</div>
<div
data-focus-guard="true"
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
tabindex="0"
/>
</div>
`;

View File

@@ -43,7 +43,7 @@ exports[`ReportRoomDialog displays admin message 1`] = `
/>
<span
class="_message_19upo_85 _help-message_19upo_91"
id="radix-:r7:"
id="radix-:r8:"
>
Report this room to your account provider. If the messages are encrypted, your admin will not be able to read them.
</span>
@@ -71,7 +71,7 @@ exports[`ReportRoomDialog displays admin message 1`] = `
class="mx_SettingsFlag_label"
>
<div
id="mx_LabelledToggleSwitch_undefined"
id="mx_LabelledToggleSwitch_:r9:"
>
Leave room
</div>
@@ -79,7 +79,7 @@ exports[`ReportRoomDialog displays admin message 1`] = `
<div
aria-checked="false"
aria-disabled="false"
aria-labelledby="mx_LabelledToggleSwitch_undefined"
aria-labelledby="mx_LabelledToggleSwitch_:r9:"
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_enabled"
role="switch"
tabindex="0"

View File

@@ -26,7 +26,7 @@ exports[`<LocationShareMenu /> with live location disabled goes to labs flag scr
class="mx_SettingsFlag_label"
>
<div
id="mx_LabelledToggleSwitch_vY7Q4uEh9K38"
id="mx_LabelledToggleSwitch_:r0:"
>
Enable live location sharing
</div>
@@ -34,7 +34,7 @@ exports[`<LocationShareMenu /> with live location disabled goes to labs flag scr
<div
aria-checked="false"
aria-disabled="false"
aria-labelledby="mx_LabelledToggleSwitch_vY7Q4uEh9K38"
aria-labelledby="mx_LabelledToggleSwitch_:r0:"
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_enabled"
role="switch"
tabindex="0"

View File

@@ -279,37 +279,31 @@ describe("<RoomPreviewBar />", () => {
});
it("renders join and reject action buttons correctly", () => {
const component = getComponent({ inviterName, room, onJoinClick, onRejectClick });
expect(getActions(component)).toMatchSnapshot();
});
it("renders reject and ignore action buttons when handler is provided", () => {
const onRejectAndIgnoreClick = jest.fn();
const component = getComponent({
inviterName,
room,
onJoinClick,
onRejectClick,
onRejectAndIgnoreClick,
});
const component = getComponent({ inviterName, room, onJoinClick, onDeclineClick: onRejectClick });
expect(getActions(component)).toMatchSnapshot();
});
it("renders join and reject action buttons in reverse order when room can previewed", () => {
// when room is previewed action buttons are rendered left to right, with primary on the right
const component = getComponent({ inviterName, room, onJoinClick, onRejectClick, canPreview: true });
const component = getComponent({
inviterName,
room,
onJoinClick,
onDeclineClick: onRejectClick,
canPreview: true,
});
expect(getActions(component)).toMatchSnapshot();
});
it("joins room on primary button click", () => {
const component = getComponent({ inviterName, room, onJoinClick, onRejectClick });
const component = getComponent({ inviterName, room, onJoinClick, onDeclineClick: onRejectClick });
fireEvent.click(getPrimaryActionButton(component)!);
expect(onJoinClick).toHaveBeenCalled();
});
it("rejects invite on secondary button click", () => {
const component = getComponent({ inviterName, room, onJoinClick, onRejectClick });
const component = getComponent({ inviterName, room, onJoinClick, onDeclineClick: onRejectClick });
fireEvent.click(getSecondaryActionButton(component)!);
expect(onRejectClick).toHaveBeenCalled();
@@ -337,18 +331,6 @@ describe("<RoomPreviewBar />", () => {
const component = getComponent({ inviterName, room });
expect(getMessage(component)).toMatchSnapshot();
});
it("renders join and reject action buttons with correct labels", () => {
const onRejectAndIgnoreClick = jest.fn();
const component = getComponent({
inviterName,
room,
onJoinClick,
onRejectAndIgnoreClick,
onRejectClick,
});
expect(getActions(component)).toMatchSnapshot();
});
});
});
@@ -364,7 +346,7 @@ describe("<RoomPreviewBar />", () => {
async () => {
const onJoinClick = jest.fn();
const onRejectClick = jest.fn();
const component = getComponent({ ...props, onJoinClick, onRejectClick });
const component = getComponent({ ...props, onJoinClick, onDeclineClick: onRejectClick });
await waitFor(() => expect(getPrimaryActionButton(component)).toBeTruthy());
if (expectSecondaryButton) expect(getSecondaryActionButton(component)).toBeFalsy();
fireEvent.click(getPrimaryActionButton(component)!);

View File

@@ -339,34 +339,6 @@ exports[`<RoomPreviewBar /> with an invite without an invited email for a dm roo
</div>
`;
exports[`<RoomPreviewBar /> with an invite without an invited email for a dm room renders join and reject action buttons with correct labels 1`] = `
<div
class="mx_RoomPreviewBar_actions"
>
<div
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_primary"
role="button"
tabindex="0"
>
Start chatting
</div>
<div
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_secondary"
role="button"
tabindex="0"
>
Reject & Ignore user
</div>
<div
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_secondary"
role="button"
tabindex="0"
>
Reject
</div>
</div>
`;
exports[`<RoomPreviewBar /> with an invite without an invited email for a non-dm room renders invite message 1`] = `
<div
class="mx_RoomPreviewBar_message"
@@ -421,7 +393,7 @@ exports[`<RoomPreviewBar /> with an invite without an invited email for a non-dm
role="button"
tabindex="0"
>
Reject
Decline
</div>
</div>
`;
@@ -435,7 +407,7 @@ exports[`<RoomPreviewBar /> with an invite without an invited email for a non-dm
role="button"
tabindex="0"
>
Reject
Decline
</div>
<div
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_primary"
@@ -446,31 +418,3 @@ exports[`<RoomPreviewBar /> with an invite without an invited email for a non-dm
</div>
</div>
`;
exports[`<RoomPreviewBar /> with an invite without an invited email for a non-dm room renders reject and ignore action buttons when handler is provided 1`] = `
<div
class="mx_RoomPreviewBar_actions"
>
<div
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_primary"
role="button"
tabindex="0"
>
Accept
</div>
<div
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_secondary"
role="button"
tabindex="0"
>
Reject & Ignore user
</div>
<div
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_secondary"
role="button"
tabindex="0"
>
Reject
</div>
</div>
`;

View File

@@ -1,133 +0,0 @@
/*
Copyright 2024 New Vector Ltd.
Copyright 2023 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 { render, screen } from "jest-matrix-react";
import { type Mocked, mocked } from "jest-mock";
import { type MatrixClient } from "matrix-js-sdk/src/matrix";
import CrossSigningPanel from "../../../../../src/components/views/settings/CrossSigningPanel";
import {
flushPromises,
getMockClientWithEventEmitter,
mockClientMethodsCrypto,
mockClientMethodsUser,
} from "../../../../test-utils";
import Modal from "../../../../../src/Modal";
import ConfirmDestroyCrossSigningDialog from "../../../../../src/components/views/dialogs/security/ConfirmDestroyCrossSigningDialog";
describe("<CrossSigningPanel />", () => {
const userId = "@alice:server.org";
let mockClient: Mocked<MatrixClient>;
const getComponent = () => render(<CrossSigningPanel />);
beforeEach(() => {
mockClient = getMockClientWithEventEmitter({
...mockClientMethodsUser(userId),
...mockClientMethodsCrypto(),
doesServerSupportUnstableFeature: jest.fn(),
});
mockClient.doesServerSupportUnstableFeature.mockResolvedValue(true);
});
afterEach(() => {
jest.restoreAllMocks();
});
it("should render a spinner while loading", () => {
getComponent();
expect(screen.getByRole("progressbar")).toBeInTheDocument();
});
it("should render when homeserver does not support cross-signing", async () => {
mockClient.doesServerSupportUnstableFeature.mockResolvedValue(false);
getComponent();
await flushPromises();
expect(screen.getByText("Your homeserver does not support cross-signing.")).toBeInTheDocument();
});
describe("when cross signing is ready", () => {
it("should render when keys are not backed up", async () => {
getComponent();
await flushPromises();
expect(screen.getByTestId("summarised-status").innerHTML).toEqual(
"⚠️ Cross-signing is ready but keys are not backed up.",
);
expect(screen.getByText("Cross-signing private keys:").parentElement!).toMatchSnapshot();
});
it("should render when keys are backed up", async () => {
mocked(mockClient.getCrypto()!.getCrossSigningStatus).mockResolvedValue({
publicKeysOnDevice: true,
privateKeysInSecretStorage: true,
privateKeysCachedLocally: {
masterKey: true,
selfSigningKey: true,
userSigningKey: true,
},
});
getComponent();
await flushPromises();
expect(screen.getByTestId("summarised-status").innerHTML).toEqual("✅ Cross-signing is ready for use.");
expect(screen.getByText("Cross-signing private keys:").parentElement!).toMatchSnapshot();
});
it("should allow reset of cross-signing", async () => {
mockClient.getCrypto()!.bootstrapCrossSigning = jest.fn().mockResolvedValue(undefined);
getComponent();
await flushPromises();
const modalSpy = jest.spyOn(Modal, "createDialog");
screen.getByRole("button", { name: "Reset" }).click();
expect(modalSpy).toHaveBeenCalledWith(ConfirmDestroyCrossSigningDialog, expect.any(Object));
modalSpy.mock.lastCall![1]!.onFinished(true);
expect(mockClient.getCrypto()!.bootstrapCrossSigning).toHaveBeenCalledWith(
expect.objectContaining({ setupNewCrossSigning: true }),
);
});
});
describe("when cross signing is not ready", () => {
beforeEach(() => {
mocked(mockClient.getCrypto()!.isCrossSigningReady).mockResolvedValue(false);
});
it("should render when keys are not backed up", async () => {
getComponent();
await flushPromises();
expect(screen.getByTestId("summarised-status").innerHTML).toEqual("Cross-signing is not set up.");
});
it("should render when keys are backed up", async () => {
mocked(mockClient.getCrypto()!.getCrossSigningStatus).mockResolvedValue({
publicKeysOnDevice: true,
privateKeysInSecretStorage: true,
privateKeysCachedLocally: {
masterKey: true,
selfSigningKey: true,
userSigningKey: true,
},
});
getComponent();
await flushPromises();
expect(screen.getByTestId("summarised-status").innerHTML).toEqual(
"Your account has a cross-signing identity in secret storage, but it is not yet trusted by this session.",
);
expect(screen.getByText("Cross-signing private keys:").parentElement!).toMatchSnapshot();
});
});
});

View File

@@ -1,97 +0,0 @@
/*
Copyright 2024 New Vector Ltd.
Copyright 2022 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 { render, waitFor, screen, fireEvent } from "jest-matrix-react";
import { type MatrixClient } from "matrix-js-sdk/src/matrix";
import { mocked } from "jest-mock";
import { MatrixClientPeg } from "../../../../../src/MatrixClientPeg";
import * as TestUtils from "../../../../test-utils";
import CryptographyPanel from "../../../../../src/components/views/settings/CryptographyPanel";
import { withClientContextRenderOptions } from "../../../../test-utils";
describe("CryptographyPanel", () => {
it("shows the session ID and key", async () => {
const sessionId = "ABCDEFGHIJ";
const sessionKey = "AbCDeFghIJK7L/m4nOPqRSTUVW4xyzaBCDef6gHIJkl";
const sessionKeyFormatted = "<strong>AbCD eFgh IJK7 L/m4 nOPq RSTU VW4x yzaB CDef 6gHI Jkl</strong>";
TestUtils.stubClient();
const client: MatrixClient = MatrixClientPeg.safeGet();
client.deviceId = sessionId;
mocked(client.getCrypto()!.getOwnDeviceKeys).mockResolvedValue({ ed25519: sessionKey, curve25519: "1234" });
// When we render the CryptographyPanel
const rendered = render(<CryptographyPanel />, withClientContextRenderOptions(client));
// Then it displays info about the user's session
const codes = rendered.container.querySelectorAll("code");
expect(codes.length).toEqual(2);
expect(codes[0].innerHTML).toEqual(sessionId);
// Initially a placeholder
expect(codes[1].innerHTML).toEqual("<strong>...</strong>");
// Then the actual key
await waitFor(() => expect(codes[1].innerHTML).toEqual(sessionKeyFormatted));
});
it("handles errors fetching session key", async () => {
const sessionId = "ABCDEFGHIJ";
TestUtils.stubClient();
const client: MatrixClient = MatrixClientPeg.safeGet();
client.deviceId = sessionId;
mocked(client.getCrypto()!.getOwnDeviceKeys).mockRejectedValue(new Error("bleh"));
// When we render the CryptographyPanel
const rendered = render(<CryptographyPanel />, withClientContextRenderOptions(client));
// Then it displays info about the user's session
const codes = rendered.container.querySelectorAll("code");
// Initially a placeholder
expect(codes[1].innerHTML).toEqual("<strong>...</strong>");
// Then "not supported key
await waitFor(() => expect(codes[1].innerHTML).toEqual("<strong>&lt;not supported&gt;</strong>"));
});
it("should open the export e2e keys dialog on click", async () => {
const sessionId = "ABCDEFGHIJ";
const sessionKey = "AbCDeFghIJK7L/m4nOPqRSTUVW4xyzaBCDef6gHIJkl";
TestUtils.stubClient();
const client: MatrixClient = MatrixClientPeg.safeGet();
client.deviceId = sessionId;
mocked(client.getCrypto()!.getOwnDeviceKeys).mockResolvedValue({ ed25519: sessionKey, curve25519: "1234" });
render(<CryptographyPanel />, withClientContextRenderOptions(client));
fireEvent.click(await screen.findByRole("button", { name: "Export E2E room keys" }));
await expect(screen.findByRole("heading", { name: "Export room keys" })).resolves.toBeInTheDocument();
});
it("should open the import e2e keys dialog on click", async () => {
const sessionId = "ABCDEFGHIJ";
const sessionKey = "AbCDeFghIJK7L/m4nOPqRSTUVW4xyzaBCDef6gHIJkl";
TestUtils.stubClient();
const client: MatrixClient = MatrixClientPeg.safeGet();
client.deviceId = sessionId;
mocked(client.getCrypto()!.getOwnDeviceKeys).mockResolvedValue({ ed25519: sessionKey, curve25519: "1234" });
render(<CryptographyPanel />, withClientContextRenderOptions(client));
fireEvent.click(await screen.findByRole("button", { name: "Import E2E room keys" }));
await expect(screen.findByRole("heading", { name: "Import room keys" })).resolves.toBeInTheDocument();
});
});

View File

@@ -1,171 +0,0 @@
/*
Copyright 2024 New Vector Ltd.
Copyright 2023 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 { fireEvent, render, screen, within } from "jest-matrix-react";
import { mocked } from "jest-mock";
import {
flushPromises,
getMockClientWithEventEmitter,
mockClientMethodsCrypto,
mockClientMethodsUser,
} from "../../../../test-utils";
import SecureBackupPanel from "../../../../../src/components/views/settings/SecureBackupPanel";
import { accessSecretStorage } from "../../../../../src/SecurityManager";
jest.mock("../../../../../src/SecurityManager", () => ({
accessSecretStorage: jest.fn(),
}));
describe("<SecureBackupPanel />", () => {
const userId = "@alice:server.org";
const client = getMockClientWithEventEmitter({
...mockClientMethodsUser(userId),
...mockClientMethodsCrypto(),
getClientWellKnown: jest.fn(),
});
const getComponent = () => render(<SecureBackupPanel />);
beforeEach(() => {
jest.spyOn(client.getCrypto()!, "getKeyBackupInfo").mockResolvedValue({
version: "1",
algorithm: "test",
auth_data: {
public_key: "1234",
},
});
Object.assign(client.getCrypto()!, {
isKeyBackupTrusted: jest.fn().mockResolvedValue({
trusted: false,
matchesDecryptionKey: false,
}),
getActiveSessionBackupVersion: jest.fn().mockResolvedValue(null),
deleteKeyBackupVersion: jest.fn().mockResolvedValue(undefined),
});
mocked(client.secretStorage.hasKey).mockClear().mockResolvedValue(false);
mocked(accessSecretStorage).mockClear().mockResolvedValue();
});
it("displays a loader while checking keybackup", async () => {
getComponent();
expect(screen.getByRole("progressbar")).toBeInTheDocument();
await flushPromises();
expect(screen.queryByRole("progressbar")).not.toBeInTheDocument();
});
it("handles error fetching backup", async () => {
// getKeyBackupInfo can fail for various reasons
jest.spyOn(client.getCrypto()!, "getKeyBackupInfo").mockImplementation(async () => {
throw new Error("beep beep");
});
const renderResult = getComponent();
await renderResult.findByText("Unable to load key backup status");
expect(renderResult.container).toMatchSnapshot();
});
it("handles absence of backup", async () => {
jest.spyOn(client.getCrypto()!, "getKeyBackupInfo").mockResolvedValue(null);
getComponent();
// flush getKeyBackupInfo promise
await flushPromises();
expect(screen.getByText("Back up your keys before signing out to avoid losing them.")).toBeInTheDocument();
});
it("suggests connecting session to key backup when backup exists", async () => {
const { container } = getComponent();
// flush checkKeyBackup promise
await flushPromises();
expect(container).toMatchSnapshot();
});
it("displays when session is connected to key backup", async () => {
mocked(client.getCrypto()!).getActiveSessionBackupVersion.mockResolvedValue("1");
getComponent();
// flush checkKeyBackup promise
await flushPromises();
expect(screen.getByText("✅ This session is backing up your keys.")).toBeInTheDocument();
});
it("asks for confirmation before deleting a backup", async () => {
getComponent();
// flush checkKeyBackup promise
await flushPromises();
fireEvent.click(screen.getByText("Delete Backup"));
const dialog = await screen.findByRole("dialog");
expect(
within(dialog).getByText(
"Are you sure? You will lose your encrypted messages if your keys are not backed up properly.",
),
).toBeInTheDocument();
fireEvent.click(within(dialog).getByText("Cancel"));
expect(client.getCrypto()!.deleteKeyBackupVersion).not.toHaveBeenCalled();
});
it("deletes backup after confirmation", async () => {
jest.spyOn(client.getCrypto()!, "getKeyBackupInfo")
.mockResolvedValueOnce({
version: "1",
algorithm: "test",
auth_data: {
public_key: "1234",
},
})
.mockResolvedValue(null);
getComponent();
fireEvent.click(await screen.findByText("Delete Backup"));
const dialog = await screen.findByRole("dialog");
expect(
within(dialog).getByText(
"Are you sure? You will lose your encrypted messages if your keys are not backed up properly.",
),
).toBeInTheDocument();
fireEvent.click(within(dialog).getByTestId("dialog-primary-button"));
expect(client.getCrypto()!.deleteKeyBackupVersion).toHaveBeenCalledWith("1");
// delete request
await flushPromises();
// refresh backup info
await flushPromises();
});
it("resets secret storage", async () => {
mocked(client.secretStorage.hasKey).mockClear().mockResolvedValue(true);
getComponent();
// flush checkKeyBackup promise
await flushPromises();
jest.spyOn(client.getCrypto()!, "getKeyBackupInfo").mockClear();
mocked(client.getCrypto()!).isKeyBackupTrusted.mockClear();
fireEvent.click(screen.getByText("Reset"));
// enter loading state
expect(accessSecretStorage).toHaveBeenCalled();
await flushPromises();
// backup status refreshed
expect(client.getCrypto()!.getKeyBackupInfo).toHaveBeenCalled();
expect(client.getCrypto()!.isKeyBackupTrusted).toHaveBeenCalled();
});
});

View File

@@ -1,40 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<CrossSigningPanel /> when cross signing is not ready should render when keys are backed up 1`] = `
<tr>
<th
scope="row"
>
Cross-signing private keys:
</th>
<td>
in secret storage
</td>
</tr>
`;
exports[`<CrossSigningPanel /> when cross signing is ready should render when keys are backed up 1`] = `
<tr>
<th
scope="row"
>
Cross-signing private keys:
</th>
<td>
in secret storage
</td>
</tr>
`;
exports[`<CrossSigningPanel /> when cross signing is ready should render when keys are not backed up 1`] = `
<tr>
<th
scope="row"
>
Cross-signing private keys:
</th>
<td>
not found in storage
</td>
</tr>
`;

View File

@@ -10,22 +10,22 @@ exports[`<Notifications /> main notification switches renders only enable notifi
class="mx_SettingsFlag_label"
>
<div
id="mx_LabelledToggleSwitch_testid_0"
id="mx_LabelledToggleSwitch_:r0:"
>
Enable notifications for this account
</div>
<span
class="mx_Caption"
id="mx_LabelledToggleSwitch_testid_0_caption"
id="mx_LabelledToggleSwitch_:r0:_caption"
>
Turn off to disable notifications on all your devices and sessions
</span>
</span>
<div
aria-checked="false"
aria-describedby="mx_LabelledToggleSwitch_testid_0_caption"
aria-describedby="mx_LabelledToggleSwitch_:r0:_caption"
aria-disabled="false"
aria-labelledby="mx_LabelledToggleSwitch_testid_0"
aria-labelledby="mx_LabelledToggleSwitch_:r0:"
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_enabled"
role="switch"
tabindex="0"
@@ -41,7 +41,7 @@ exports[`<Notifications /> main notification switches renders only enable notifi
>
<label
class="mx_SettingsFlag_label"
for="mx_SettingsFlag_testid_1"
for="mx_SettingsFlag_testid_0"
>
<span
class="mx_SettingsFlag_labelText"
@@ -54,7 +54,7 @@ exports[`<Notifications /> main notification switches renders only enable notifi
aria-disabled="false"
aria-label="Show all activity in the room list (dots or number of unread messages)"
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_on mx_ToggleSwitch_enabled"
id="mx_SettingsFlag_testid_1"
id="mx_SettingsFlag_testid_0"
role="switch"
tabindex="0"
>
@@ -68,7 +68,7 @@ exports[`<Notifications /> main notification switches renders only enable notifi
>
<label
class="mx_SettingsFlag_label"
for="mx_SettingsFlag_testid_2"
for="mx_SettingsFlag_testid_1"
>
<span
class="mx_SettingsFlag_labelText"
@@ -81,7 +81,7 @@ exports[`<Notifications /> main notification switches renders only enable notifi
aria-disabled="false"
aria-label="Only show notifications in the thread activity centre"
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_on mx_ToggleSwitch_enabled"
id="mx_SettingsFlag_testid_2"
id="mx_SettingsFlag_testid_1"
role="switch"
tabindex="0"
>

View File

@@ -1,190 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<SecureBackupPanel /> handles error fetching backup 1`] = `
<div>
<div
class="mx_SettingsSubsection_text"
>
Back up your encryption keys with your account data in case you lose access to your sessions. Your keys will be secured with a unique Recovery Key.
</div>
<div
class="mx_SettingsSubsection_text"
>
Unable to load key backup status
</div>
<details>
<summary
class="mx_SecureBackupPanel_advanced"
>
Advanced
</summary>
<table
class="mx_SecureBackupPanel_statusList"
>
<tr>
<th
scope="row"
>
Backup key stored:
</th>
<td>
not stored
</td>
</tr>
<tr>
<th
scope="row"
>
Backup key cached:
</th>
<td>
not found locally
</td>
</tr>
<tr>
<th
scope="row"
>
Secret storage public key:
</th>
<td>
not found
</td>
</tr>
<tr>
<th
scope="row"
>
Secret storage:
</th>
<td>
not ready
</td>
</tr>
</table>
</details>
</div>
`;
exports[`<SecureBackupPanel /> suggests connecting session to key backup when backup exists 1`] = `
<div>
<div
class="mx_SettingsSubsection_text"
>
Back up your encryption keys with your account data in case you lose access to your sessions. Your keys will be secured with a unique Recovery Key.
</div>
<div
class="mx_SettingsSubsection_text"
>
<span>
This session is
<strong>
not backing up your keys
</strong>
, but you do have an existing backup you can restore from and add to going forward.
</span>
</div>
<div
class="mx_SettingsSubsection_text"
>
Connect this session to key backup before signing out to avoid losing any keys that may only be on this session.
</div>
<details>
<summary
class="mx_SecureBackupPanel_advanced"
>
Advanced
</summary>
<table
class="mx_SecureBackupPanel_statusList"
>
<tr>
<th
scope="row"
>
Backup key stored:
</th>
<td>
not stored
</td>
</tr>
<tr>
<th
scope="row"
>
Backup key cached:
</th>
<td>
not found locally
</td>
</tr>
<tr>
<th
scope="row"
>
Secret storage public key:
</th>
<td>
not found
</td>
</tr>
<tr>
<th
scope="row"
>
Secret storage:
</th>
<td>
not ready
</td>
</tr>
<tr>
<th
scope="row"
>
Latest backup version on server:
</th>
<td>
1
(
Algorithm:
<code>
test
</code>
)
</td>
</tr>
<tr>
<th
scope="row"
>
Active backup version:
</th>
<td>
None
</td>
</tr>
</table>
<div />
</details>
<div
class="mx_SecureBackupPanel_buttonRow"
>
<div
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_primary_outline"
role="button"
tabindex="0"
>
Connect this session to Key Backup
</div>
<div
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_danger_outline"
role="button"
tabindex="0"
>
Delete Backup
</div>
</div>
</div>
`;

View File

@@ -21,7 +21,7 @@ exports[`<Notifications /> correctly handles the loading/disabled state 1`] = `
class="mx_SettingsFlag_label"
>
<div
id="mx_LabelledToggleSwitch_vY7Q4uEh9K38"
id="mx_LabelledToggleSwitch_:r17:"
>
Enable notifications for this account
</div>
@@ -29,7 +29,7 @@ exports[`<Notifications /> correctly handles the loading/disabled state 1`] = `
<div
aria-checked="true"
aria-disabled="true"
aria-labelledby="mx_LabelledToggleSwitch_vY7Q4uEh9K38"
aria-labelledby="mx_LabelledToggleSwitch_:r17:"
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_on"
role="switch"
tabindex="0"
@@ -46,7 +46,7 @@ exports[`<Notifications /> correctly handles the loading/disabled state 1`] = `
class="mx_SettingsFlag_label"
>
<div
id="mx_LabelledToggleSwitch_QgU2PomxwKpa"
id="mx_LabelledToggleSwitch_:r18:"
>
Enable desktop notifications for this session
</div>
@@ -54,7 +54,7 @@ exports[`<Notifications /> correctly handles the loading/disabled state 1`] = `
<div
aria-checked="false"
aria-disabled="false"
aria-labelledby="mx_LabelledToggleSwitch_QgU2PomxwKpa"
aria-labelledby="mx_LabelledToggleSwitch_:r18:"
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_enabled"
role="switch"
tabindex="0"
@@ -71,7 +71,7 @@ exports[`<Notifications /> correctly handles the loading/disabled state 1`] = `
class="mx_SettingsFlag_label"
>
<div
id="mx_LabelledToggleSwitch_6hpi3YEetmBG"
id="mx_LabelledToggleSwitch_:r19:"
>
Show message preview in desktop notification
</div>
@@ -79,7 +79,7 @@ exports[`<Notifications /> correctly handles the loading/disabled state 1`] = `
<div
aria-checked="false"
aria-disabled="false"
aria-labelledby="mx_LabelledToggleSwitch_6hpi3YEetmBG"
aria-labelledby="mx_LabelledToggleSwitch_:r19:"
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_enabled"
role="switch"
tabindex="0"
@@ -96,7 +96,7 @@ exports[`<Notifications /> correctly handles the loading/disabled state 1`] = `
class="mx_SettingsFlag_label"
>
<div
id="mx_LabelledToggleSwitch_4yVCeEefiPqp"
id="mx_LabelledToggleSwitch_:r1a:"
>
Enable audible notifications for this session
</div>
@@ -104,7 +104,7 @@ exports[`<Notifications /> correctly handles the loading/disabled state 1`] = `
<div
aria-checked="true"
aria-disabled="false"
aria-labelledby="mx_LabelledToggleSwitch_4yVCeEefiPqp"
aria-labelledby="mx_LabelledToggleSwitch_:r1a:"
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_on mx_ToggleSwitch_enabled"
role="switch"
tabindex="0"
@@ -251,7 +251,7 @@ exports[`<Notifications /> correctly handles the loading/disabled state 1`] = `
checked=""
class="_input_1hel1_18"
disabled=""
id="checkbox_MRMwbPDmfG"
id="checkbox_vY7Q4uEh9K"
type="checkbox"
/>
<div
@@ -277,7 +277,7 @@ exports[`<Notifications /> correctly handles the loading/disabled state 1`] = `
>
<label
class="_label_19upo_59"
for="checkbox_MRMwbPDmfG"
for="checkbox_vY7Q4uEh9K"
>
<span
class="mx_LabelledCheckbox_label"
@@ -308,7 +308,7 @@ exports[`<Notifications /> correctly handles the loading/disabled state 1`] = `
checked=""
class="_input_1hel1_18"
disabled=""
id="checkbox_tmGQvdMWe9"
id="checkbox_38QgU2Pomx"
type="checkbox"
/>
<div
@@ -334,7 +334,7 @@ exports[`<Notifications /> correctly handles the loading/disabled state 1`] = `
>
<label
class="_label_19upo_59"
for="checkbox_tmGQvdMWe9"
for="checkbox_38QgU2Pomx"
>
<span
class="mx_LabelledCheckbox_label"
@@ -365,7 +365,7 @@ exports[`<Notifications /> correctly handles the loading/disabled state 1`] = `
checked=""
class="_input_1hel1_18"
disabled=""
id="checkbox_54DVIAu5Cs"
id="checkbox_wKpa6hpi3Y"
type="checkbox"
/>
<div
@@ -391,7 +391,7 @@ exports[`<Notifications /> correctly handles the loading/disabled state 1`] = `
>
<label
class="_label_19upo_59"
for="checkbox_54DVIAu5Cs"
for="checkbox_wKpa6hpi3Y"
>
<span
class="mx_LabelledCheckbox_label"
@@ -439,7 +439,7 @@ exports[`<Notifications /> correctly handles the loading/disabled state 1`] = `
checked=""
class="_input_1hel1_18"
disabled=""
id="checkbox_iHRD7nyrA2"
id="checkbox_EetmBG4yVC"
type="checkbox"
/>
<div
@@ -465,7 +465,7 @@ exports[`<Notifications /> correctly handles the loading/disabled state 1`] = `
>
<label
class="_label_19upo_59"
for="checkbox_iHRD7nyrA2"
for="checkbox_EetmBG4yVC"
>
<span
class="mx_LabelledCheckbox_label"
@@ -495,7 +495,7 @@ exports[`<Notifications /> correctly handles the loading/disabled state 1`] = `
<input
class="_input_1hel1_18"
disabled=""
id="checkbox_ohjWVJIPau"
id="checkbox_eEefiPqpMR"
type="checkbox"
/>
<div
@@ -521,7 +521,7 @@ exports[`<Notifications /> correctly handles the loading/disabled state 1`] = `
>
<label
class="_label_19upo_59"
for="checkbox_ohjWVJIPau"
for="checkbox_eEefiPqpMR"
>
<span
class="mx_LabelledCheckbox_label"
@@ -552,7 +552,7 @@ exports[`<Notifications /> correctly handles the loading/disabled state 1`] = `
checked=""
class="_input_1hel1_18"
disabled=""
id="checkbox_y1OmnTidX4"
id="checkbox_MwbPDmfGtm"
type="checkbox"
/>
<div
@@ -578,7 +578,7 @@ exports[`<Notifications /> correctly handles the loading/disabled state 1`] = `
>
<label
class="_label_19upo_59"
for="checkbox_y1OmnTidX4"
for="checkbox_MwbPDmfGtm"
>
<span
class="mx_LabelledCheckbox_label"
@@ -647,7 +647,7 @@ exports[`<Notifications /> correctly handles the loading/disabled state 1`] = `
checked=""
class="_input_1hel1_18"
disabled=""
id="checkbox_ePDS0OpWwA"
id="checkbox_GQvdMWe954"
type="checkbox"
/>
<div
@@ -673,7 +673,7 @@ exports[`<Notifications /> correctly handles the loading/disabled state 1`] = `
>
<label
class="_label_19upo_59"
for="checkbox_ePDS0OpWwA"
for="checkbox_GQvdMWe954"
>
<span
class="mx_LabelledCheckbox_label"
@@ -704,7 +704,7 @@ exports[`<Notifications /> correctly handles the loading/disabled state 1`] = `
checked=""
class="_input_1hel1_18"
disabled=""
id="checkbox_HG75JNTNkN"
id="checkbox_DVIAu5CsiH"
type="checkbox"
/>
<div
@@ -730,7 +730,7 @@ exports[`<Notifications /> correctly handles the loading/disabled state 1`] = `
>
<label
class="_label_19upo_59"
for="checkbox_HG75JNTNkN"
for="checkbox_DVIAu5CsiH"
>
<span
class="mx_LabelledCheckbox_label"
@@ -758,11 +758,11 @@ exports[`<Notifications /> correctly handles the loading/disabled state 1`] = `
class="_container_1hel1_10"
>
<input
aria-describedby=":r1s:"
aria-describedby=":r24:"
checked=""
class="_input_1hel1_18"
disabled=""
id="checkbox_U64raTLcRs"
id="checkbox_RD7nyrA2oh"
type="checkbox"
/>
<div
@@ -788,7 +788,7 @@ exports[`<Notifications /> correctly handles the loading/disabled state 1`] = `
>
<label
class="_label_19upo_59"
for="checkbox_U64raTLcRs"
for="checkbox_RD7nyrA2oh"
>
<span
class="mx_LabelledCheckbox_label"
@@ -798,7 +798,7 @@ exports[`<Notifications /> correctly handles the loading/disabled state 1`] = `
</label>
<span
class="_message_19upo_85 _help-message_19upo_91"
id=":r1s:"
id=":r24:"
>
Enter keywords here, or use for spelling variations or nicknames
</span>
@@ -850,7 +850,7 @@ exports[`<Notifications /> correctly handles the loading/disabled state 1`] = `
>
<label
class="mx_SettingsFlag_label"
for="mx_SettingsFlag_QRlYy75nfv5b"
for="mx_SettingsFlag_jWVJIPauy1Om"
>
<span
class="mx_SettingsFlag_labelText"
@@ -863,7 +863,7 @@ exports[`<Notifications /> correctly handles the loading/disabled state 1`] = `
aria-disabled="false"
aria-label="Show all activity in the room list (dots or number of unread messages)"
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_on mx_ToggleSwitch_enabled"
id="mx_SettingsFlag_QRlYy75nfv5b"
id="mx_SettingsFlag_jWVJIPauy1Om"
role="switch"
tabindex="0"
>
@@ -877,7 +877,7 @@ exports[`<Notifications /> correctly handles the loading/disabled state 1`] = `
>
<label
class="mx_SettingsFlag_label"
for="mx_SettingsFlag_OEPN1su1JYVt"
for="mx_SettingsFlag_nTidX4ePDS0O"
>
<span
class="mx_SettingsFlag_labelText"
@@ -890,7 +890,7 @@ exports[`<Notifications /> correctly handles the loading/disabled state 1`] = `
aria-disabled="false"
aria-label="Only show notifications in the thread activity centre"
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_on mx_ToggleSwitch_enabled"
id="mx_SettingsFlag_OEPN1su1JYVt"
id="mx_SettingsFlag_nTidX4ePDS0O"
role="switch"
tabindex="0"
>
@@ -998,7 +998,7 @@ exports[`<Notifications /> matches the snapshot 1`] = `
class="mx_SettingsFlag_label"
>
<div
id="mx_LabelledToggleSwitch_vY7Q4uEh9K38"
id="mx_LabelledToggleSwitch_:r0:"
>
Enable notifications for this account
</div>
@@ -1006,7 +1006,7 @@ exports[`<Notifications /> matches the snapshot 1`] = `
<div
aria-checked="true"
aria-disabled="false"
aria-labelledby="mx_LabelledToggleSwitch_vY7Q4uEh9K38"
aria-labelledby="mx_LabelledToggleSwitch_:r0:"
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_on mx_ToggleSwitch_enabled"
role="switch"
tabindex="0"
@@ -1023,7 +1023,7 @@ exports[`<Notifications /> matches the snapshot 1`] = `
class="mx_SettingsFlag_label"
>
<div
id="mx_LabelledToggleSwitch_QgU2PomxwKpa"
id="mx_LabelledToggleSwitch_:r1:"
>
Enable desktop notifications for this session
</div>
@@ -1031,7 +1031,7 @@ exports[`<Notifications /> matches the snapshot 1`] = `
<div
aria-checked="false"
aria-disabled="false"
aria-labelledby="mx_LabelledToggleSwitch_QgU2PomxwKpa"
aria-labelledby="mx_LabelledToggleSwitch_:r1:"
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_enabled"
role="switch"
tabindex="0"
@@ -1048,7 +1048,7 @@ exports[`<Notifications /> matches the snapshot 1`] = `
class="mx_SettingsFlag_label"
>
<div
id="mx_LabelledToggleSwitch_6hpi3YEetmBG"
id="mx_LabelledToggleSwitch_:r2:"
>
Show message preview in desktop notification
</div>
@@ -1056,7 +1056,7 @@ exports[`<Notifications /> matches the snapshot 1`] = `
<div
aria-checked="false"
aria-disabled="false"
aria-labelledby="mx_LabelledToggleSwitch_6hpi3YEetmBG"
aria-labelledby="mx_LabelledToggleSwitch_:r2:"
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_enabled"
role="switch"
tabindex="0"
@@ -1073,7 +1073,7 @@ exports[`<Notifications /> matches the snapshot 1`] = `
class="mx_SettingsFlag_label"
>
<div
id="mx_LabelledToggleSwitch_4yVCeEefiPqp"
id="mx_LabelledToggleSwitch_:r3:"
>
Enable audible notifications for this session
</div>
@@ -1081,7 +1081,7 @@ exports[`<Notifications /> matches the snapshot 1`] = `
<div
aria-checked="true"
aria-disabled="false"
aria-labelledby="mx_LabelledToggleSwitch_4yVCeEefiPqp"
aria-labelledby="mx_LabelledToggleSwitch_:r3:"
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_on mx_ToggleSwitch_enabled"
role="switch"
tabindex="0"
@@ -1224,7 +1224,7 @@ exports[`<Notifications /> matches the snapshot 1`] = `
<input
checked=""
class="_input_1hel1_18"
id="checkbox_OyR5kbu3pE"
id="checkbox_pWwAHG75JN"
type="checkbox"
/>
<div
@@ -1250,7 +1250,7 @@ exports[`<Notifications /> matches the snapshot 1`] = `
>
<label
class="_label_19upo_59"
for="checkbox_OyR5kbu3pE"
for="checkbox_pWwAHG75JN"
>
<span
class="mx_LabelledCheckbox_label"
@@ -1280,7 +1280,7 @@ exports[`<Notifications /> matches the snapshot 1`] = `
<input
checked=""
class="_input_1hel1_18"
id="checkbox_wuLn9EnnYu"
id="checkbox_TNkNU64raT"
type="checkbox"
/>
<div
@@ -1306,7 +1306,7 @@ exports[`<Notifications /> matches the snapshot 1`] = `
>
<label
class="_label_19upo_59"
for="checkbox_wuLn9EnnYu"
for="checkbox_TNkNU64raT"
>
<span
class="mx_LabelledCheckbox_label"
@@ -1336,7 +1336,7 @@ exports[`<Notifications /> matches the snapshot 1`] = `
<input
checked=""
class="_input_1hel1_18"
id="checkbox_xfFEpOsztW"
id="checkbox_LcRsQRlYy7"
type="checkbox"
/>
<div
@@ -1362,7 +1362,7 @@ exports[`<Notifications /> matches the snapshot 1`] = `
>
<label
class="_label_19upo_59"
for="checkbox_xfFEpOsztW"
for="checkbox_LcRsQRlYy7"
>
<span
class="mx_LabelledCheckbox_label"
@@ -1409,7 +1409,7 @@ exports[`<Notifications /> matches the snapshot 1`] = `
<input
checked=""
class="_input_1hel1_18"
id="checkbox_hQkBerF1ej"
id="checkbox_5nfv5bOEPN"
type="checkbox"
/>
<div
@@ -1435,7 +1435,7 @@ exports[`<Notifications /> matches the snapshot 1`] = `
>
<label
class="_label_19upo_59"
for="checkbox_hQkBerF1ej"
for="checkbox_5nfv5bOEPN"
>
<span
class="mx_LabelledCheckbox_label"
@@ -1464,7 +1464,7 @@ exports[`<Notifications /> matches the snapshot 1`] = `
>
<input
class="_input_1hel1_18"
id="checkbox_c4GFes1UFz"
id="checkbox_1su1JYVtOy"
type="checkbox"
/>
<div
@@ -1490,7 +1490,7 @@ exports[`<Notifications /> matches the snapshot 1`] = `
>
<label
class="_label_19upo_59"
for="checkbox_c4GFes1UFz"
for="checkbox_1su1JYVtOy"
>
<span
class="mx_LabelledCheckbox_label"
@@ -1520,7 +1520,7 @@ exports[`<Notifications /> matches the snapshot 1`] = `
<input
checked=""
class="_input_1hel1_18"
id="checkbox_OK2nvfGFMl"
id="checkbox_R5kbu3pEwu"
type="checkbox"
/>
<div
@@ -1546,7 +1546,7 @@ exports[`<Notifications /> matches the snapshot 1`] = `
>
<label
class="_label_19upo_59"
for="checkbox_OK2nvfGFMl"
for="checkbox_R5kbu3pEwu"
>
<span
class="mx_LabelledCheckbox_label"
@@ -1614,7 +1614,7 @@ exports[`<Notifications /> matches the snapshot 1`] = `
<input
checked=""
class="_input_1hel1_18"
id="checkbox_dL2r2vbsSw"
id="checkbox_Ln9EnnYuxf"
type="checkbox"
/>
<div
@@ -1640,7 +1640,7 @@ exports[`<Notifications /> matches the snapshot 1`] = `
>
<label
class="_label_19upo_59"
for="checkbox_dL2r2vbsSw"
for="checkbox_Ln9EnnYuxf"
>
<span
class="mx_LabelledCheckbox_label"
@@ -1670,7 +1670,7 @@ exports[`<Notifications /> matches the snapshot 1`] = `
<input
checked=""
class="_input_1hel1_18"
id="checkbox_icmKUiOBdv"
id="checkbox_FEpOsztWhQ"
type="checkbox"
/>
<div
@@ -1696,7 +1696,7 @@ exports[`<Notifications /> matches the snapshot 1`] = `
>
<label
class="_label_19upo_59"
for="checkbox_icmKUiOBdv"
for="checkbox_FEpOsztWhQ"
>
<span
class="mx_LabelledCheckbox_label"
@@ -1724,10 +1724,10 @@ exports[`<Notifications /> matches the snapshot 1`] = `
class="_container_1hel1_10"
>
<input
aria-describedby=":rp:"
aria-describedby=":rt:"
checked=""
class="_input_1hel1_18"
id="checkbox_qsxEaZtl3A"
id="checkbox_kBerF1ejc4"
type="checkbox"
/>
<div
@@ -1753,7 +1753,7 @@ exports[`<Notifications /> matches the snapshot 1`] = `
>
<label
class="_label_19upo_59"
for="checkbox_qsxEaZtl3A"
for="checkbox_kBerF1ejc4"
>
<span
class="mx_LabelledCheckbox_label"
@@ -1763,7 +1763,7 @@ exports[`<Notifications /> matches the snapshot 1`] = `
</label>
<span
class="_message_19upo_85 _help-message_19upo_91"
id=":rp:"
id=":rt:"
>
Enter keywords here, or use for spelling variations or nicknames
</span>
@@ -2029,7 +2029,7 @@ exports[`<Notifications /> matches the snapshot 1`] = `
>
<label
class="mx_SettingsFlag_label"
for="mx_SettingsFlag_QRlYy75nfv5b"
for="mx_SettingsFlag_jWVJIPauy1Om"
>
<span
class="mx_SettingsFlag_labelText"
@@ -2042,7 +2042,7 @@ exports[`<Notifications /> matches the snapshot 1`] = `
aria-disabled="false"
aria-label="Show all activity in the room list (dots or number of unread messages)"
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_on mx_ToggleSwitch_enabled"
id="mx_SettingsFlag_QRlYy75nfv5b"
id="mx_SettingsFlag_jWVJIPauy1Om"
role="switch"
tabindex="0"
>
@@ -2056,7 +2056,7 @@ exports[`<Notifications /> matches the snapshot 1`] = `
>
<label
class="mx_SettingsFlag_label"
for="mx_SettingsFlag_OEPN1su1JYVt"
for="mx_SettingsFlag_nTidX4ePDS0O"
>
<span
class="mx_SettingsFlag_labelText"
@@ -2069,7 +2069,7 @@ exports[`<Notifications /> matches the snapshot 1`] = `
aria-disabled="false"
aria-label="Only show notifications in the thread activity centre"
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_on mx_ToggleSwitch_enabled"
id="mx_SettingsFlag_OEPN1su1JYVt"
id="mx_SettingsFlag_nTidX4ePDS0O"
role="switch"
tabindex="0"
>
@@ -2139,7 +2139,7 @@ exports[`<Notifications /> matches the snapshot 1`] = `
>
<input
class="_input_1hel1_18"
id="checkbox_NIiWzqsApP"
id="checkbox_GFes1UFzOK"
type="checkbox"
/>
<div
@@ -2165,7 +2165,7 @@ exports[`<Notifications /> matches the snapshot 1`] = `
>
<label
class="_label_19upo_59"
for="checkbox_NIiWzqsApP"
for="checkbox_GFes1UFzOK"
>
<span
class="mx_LabelledCheckbox_label"

View File

@@ -6,7 +6,8 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
Please see LICENSE files in the repository root for full details.
*/
import { render } from "jest-matrix-react";
import React from "react";
import React, { act } from "react";
import userEvent from "@testing-library/user-event";
import SecurityUserSettingsTab from "../../../../../../../src/components/views/settings/tabs/user/SecurityUserSettingsTab";
import MatrixClientContext from "../../../../../../../src/contexts/MatrixClientContext";
@@ -19,12 +20,16 @@ import {
mockPlatformPeg,
} from "../../../../../../test-utils";
import { SDKContext, SdkContextClass } from "../../../../../../../src/contexts/SDKContext";
import defaultDispatcher from "../../../../../../../src/dispatcher/dispatcher";
describe("<SecurityUserSettingsTab />", () => {
const defaultProps = {
closeSettingsFn: jest.fn(),
};
const getIgnoredUsers = jest.fn();
const setIgnoredUsers = jest.fn();
const userId = "@alice:server.org";
const deviceId = "alices-device";
const mockClient = getMockClientWithEventEmitter({
@@ -33,7 +38,9 @@ describe("<SecurityUserSettingsTab />", () => {
...mockClientMethodsDevice(deviceId),
...mockClientMethodsCrypto(),
getRooms: jest.fn().mockReturnValue([]),
getIgnoredUsers: jest.fn(),
getPushers: jest.fn().mockReturnValue([]),
getIgnoredUsers,
setIgnoredUsers,
});
const sdkContext = new SdkContextClass();
@@ -57,4 +64,29 @@ describe("<SecurityUserSettingsTab />", () => {
expect(container).toMatchSnapshot();
});
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();
});
});

View File

@@ -1,5 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<SecurityUserSettingsTab /> renders ignored users 1`] = `
<ul
aria-label="Ignored users"
class="mx_SecurityUserSettingsTab_ignoredUsers"
>
<li
aria-label="@bob:example.org"
class="mx_SecurityUserSettingsTab_ignoredUser"
>
<div
aria-describedby="mx_SecurityUserSettingsTab_ignoredUser_@bob:example.org"
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_primary_sm"
role="button"
tabindex="0"
>
Unignore
</div>
<span
id="mx_SecurityUserSettingsTab_ignoredUser_@bob:example.org"
>
@bob:example.org
</span>
</li>
</ul>
`;
exports[`<SecurityUserSettingsTab /> renders security section 1`] = `
<div>
<div
@@ -94,90 +120,6 @@ exports[`<SecurityUserSettingsTab /> renders security section 1`] = `
<div
class="mx_SettingsSection_subSections"
>
<div
class="mx_SettingsSubsection"
>
<div
class="mx_SettingsSubsectionHeading"
>
<h3
class="mx_Heading_h4 mx_SettingsSubsectionHeading_heading"
>
Secure Backup
</h3>
</div>
<div
class="mx_SettingsSubsection_content"
>
<div
class="mx_SettingsSubsection_text"
>
Back up your encryption keys with your account data in case you lose access to your sessions. Your keys will be secured with a unique Recovery Key.
</div>
<div
class="mx_Spinner"
>
<div
aria-label="Loading…"
class="mx_Spinner_icon"
data-testid="spinner"
role="progressbar"
style="width: 32px; height: 32px;"
/>
</div>
<details>
<summary
class="mx_SecureBackupPanel_advanced"
>
Advanced
</summary>
<table
class="mx_SecureBackupPanel_statusList"
>
<tr>
<th
scope="row"
>
Backup key stored:
</th>
<td>
not stored
</td>
</tr>
<tr>
<th
scope="row"
>
Backup key cached:
</th>
<td>
not found locally
</td>
</tr>
<tr>
<th
scope="row"
>
Secret storage public key:
</th>
<td>
not found
</td>
</tr>
<tr>
<th
scope="row"
>
Secret storage:
</th>
<td>
not ready
</td>
</tr>
</table>
</details>
</div>
</div>
<div
class="mx_SettingsSubsection"
>
@@ -214,203 +156,6 @@ exports[`<SecurityUserSettingsTab /> renders security section 1`] = `
</div>
</div>
</div>
<div
class="mx_SettingsSubsection"
>
<div
class="mx_SettingsSubsectionHeading"
>
<h3
class="mx_Heading_h4 mx_SettingsSubsectionHeading_heading"
>
Cross-signing
</h3>
</div>
<div
class="mx_SettingsSubsection_content"
>
<div
class="mx_Spinner"
>
<div
aria-label="Loading…"
class="mx_Spinner_icon"
data-testid="spinner"
role="progressbar"
style="width: 32px; height: 32px;"
/>
</div>
<details>
<summary
class="mx_CrossSigningPanel_advanced"
>
Advanced
</summary>
<table
class="mx_CrossSigningPanel_statusList"
>
<tbody>
<tr>
<th
scope="row"
>
Cross-signing public keys:
</th>
<td>
not found
</td>
</tr>
<tr>
<th
scope="row"
>
Cross-signing private keys:
</th>
<td>
not found in storage
</td>
</tr>
<tr>
<th
scope="row"
>
Master private key:
</th>
<td>
not found locally
</td>
</tr>
<tr>
<th
scope="row"
>
Self signing private key:
</th>
<td>
not found locally
</td>
</tr>
<tr>
<th
scope="row"
>
User signing private key:
</th>
<td>
not found locally
</td>
</tr>
<tr>
<th
scope="row"
>
Homeserver feature support:
</th>
<td>
not found
</td>
</tr>
</tbody>
</table>
</details>
</div>
</div>
<div
class="mx_SettingsSubsection"
>
<div
class="mx_SettingsSubsectionHeading"
>
<h3
class="mx_Heading_h4 mx_SettingsSubsectionHeading_heading"
>
Cryptography
</h3>
</div>
<div
class="mx_SettingsSubsection_content"
>
<div
class="mx_SettingsSubsection_text"
>
<table
class="mx_CryptographyPanel_sessionInfo"
>
<tbody>
<tr>
<th
scope="row"
>
Session ID:
</th>
<td>
<code />
</td>
</tr>
<tr>
<th
scope="row"
>
Session key:
</th>
<td>
<code>
<strong>
...
</strong>
</code>
</td>
</tr>
</tbody>
</table>
</div>
<div
class="mx_CryptographyPanel_importExportButtons"
>
<div
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_primary_outline"
role="button"
tabindex="0"
>
Export E2E room keys
</div>
<div
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_primary_outline"
role="button"
tabindex="0"
>
Import E2E room keys
</div>
</div>
<div
class="mx_SettingsFlag"
>
<label
class="mx_SettingsFlag_label"
for="mx_SettingsFlag_vY7Q4uEh9K38"
>
<span
class="mx_SettingsFlag_labelText"
>
Only send messages to verified users
</span>
</label>
<div
aria-checked="false"
aria-disabled="false"
aria-label="Only send messages to verified users"
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_enabled"
id="mx_SettingsFlag_vY7Q4uEh9K38"
role="switch"
tabindex="0"
>
<div
class="mx_ToggleSwitch_ball"
/>
</div>
</div>
</div>
</div>
</div>
</div>
<div

View File

@@ -4,7 +4,7 @@ exports[`<SpaceSettingsVisibilityTab /> for a public space Access renders guest
<div
aria-checked="true"
aria-disabled="false"
aria-labelledby="mx_LabelledToggleSwitch_testid_1"
aria-labelledby="mx_LabelledToggleSwitch_:rb:"
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_on mx_ToggleSwitch_enabled"
role="switch"
tabindex="0"
@@ -122,7 +122,7 @@ exports[`<SpaceSettingsVisibilityTab /> renders container 1`] = `
class="mx_SettingsFlag_label"
>
<div
id="mx_LabelledToggleSwitch_testid_0"
id="mx_LabelledToggleSwitch_:r0:"
>
Preview Space
</div>
@@ -130,7 +130,7 @@ exports[`<SpaceSettingsVisibilityTab /> renders container 1`] = `
<div
aria-checked="true"
aria-disabled="false"
aria-labelledby="mx_LabelledToggleSwitch_testid_0"
aria-labelledby="mx_LabelledToggleSwitch_:r0:"
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_on mx_ToggleSwitch_enabled"
role="switch"
tabindex="0"