mirror of
https://github.com/vector-im/element-web.git
synced 2025-12-12 21:01:15 +01:00
* Use EditInPlace for identity server picker. * Update test * Add a test for setting an ID server. * fix tests * Reformat other :not sections * forgot a comma * Update Apperance settings to use toggle switches. * Remove unused checkbox setting. * Remove unused import. * Update tests * lint * update apperance screenshot * Begin replacing settings * Refactor RoomPublishSetting * Remove LabelledToggleSwitch * Refactor SettingsFlag to use SettingsToggleInput * Refactor CreateRoomDialog to use SettingsToggleInput * Refactor DeclineAndBlockInviteDialog to use SettingsToggleInput * Update DevtoolsDialog * Refactor ReportRoomDialog to use SettingsToggle * Update RoomUpgradeWarningDialog to use SettingsToggleInput * Update WidgetCapabilitiesPromptDialog to use SettingsToggleInput * Update trivial switchovers * Update Notifications settings to use SettingsFlag where possible * Update RoomPublishSetting and SpaceSettingVisibilityTab to use SettingsToggleInput with a warning * revert changes to field * Updated screenshots * Prevent accidental submits * Replace test ID tests * Create new snapshot tests * Add screenshot test for DeclineAndBlockDialog * Add screenshot for create room dialog. * Add devtools test * Add upgrade rooms test * Add widget capabilites prompt test * Fix spec * Add a test for the live location sharing prompt. * fix copyright * Add tests for notification settings * Add tests for user security tab. * Add test for room security tab. * Add test for video settings tab. * remove .only * Test creating a video room * Mask the IM name in the header. * Add spaces vis tab test. * Fixup unit tests to check correct attributes. * Various fixes to components for tests. * lint * Update compound * update setting names * Cleanup tests prettier Updates some more playwright tests Update more snapshots Update switch more fixes drop .only last screenshot round fix video room flake Remove console.logs Remove roomId from devtools view. lint final screenshot * Add playwright tests * import pages/ remove duplicate create-room * Update screenshots * Fix accessibility for devtools * Disable region test * Fixup headers * remove extra test * Fix permissions dialog * fixup tests * update snapshot * Update jest tests * Clear up playwright tests * update widget screenshot * Fix wrong snaps from using wrong compound version * Revert mistaken s/checkbox/switch/ * lint lint * Update headings * fix snap * remove unused * update snapshot * update tab screenshot * Update snapshots * Fix margins * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Delint Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Update snapshot Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Update snapshot Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
247 lines
9.7 KiB
TypeScript
247 lines
9.7 KiB
TypeScript
/*
|
|
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 { mocked } from "jest-mock";
|
|
import { secureRandomString } from "matrix-js-sdk/src/randomstring";
|
|
import { act, fireEvent, render, type RenderResult } from "jest-matrix-react";
|
|
import {
|
|
EventType,
|
|
type MatrixClient,
|
|
type Room,
|
|
GuestAccess,
|
|
HistoryVisibility,
|
|
JoinRule,
|
|
} from "matrix-js-sdk/src/matrix";
|
|
|
|
import _SpaceSettingsVisibilityTab from "../../../../../src/components/views/spaces/SpaceSettingsVisibilityTab";
|
|
import {
|
|
createTestClient,
|
|
mkEvent,
|
|
wrapInMatrixClientContext,
|
|
mkSpace,
|
|
mockStateEventImplementation,
|
|
} from "../../../../test-utils";
|
|
import { MatrixClientPeg } from "../../../../../src/MatrixClientPeg";
|
|
|
|
const SpaceSettingsVisibilityTab = wrapInMatrixClientContext(_SpaceSettingsVisibilityTab);
|
|
|
|
jest.useFakeTimers();
|
|
|
|
describe("<SpaceSettingsVisibilityTab />", () => {
|
|
const mockMatrixClient = createTestClient() as MatrixClient;
|
|
|
|
const makeJoinEvent = (rule: JoinRule = JoinRule.Invite) =>
|
|
mkEvent({
|
|
type: EventType.RoomJoinRules,
|
|
event: true,
|
|
content: {
|
|
join_rule: rule,
|
|
},
|
|
} as any);
|
|
const makeGuestAccessEvent = (rule: GuestAccess = GuestAccess.CanJoin) =>
|
|
mkEvent({
|
|
type: EventType.RoomGuestAccess,
|
|
event: true,
|
|
content: {
|
|
guest_access: rule,
|
|
},
|
|
} as any);
|
|
const makeHistoryEvent = (rule: HistoryVisibility = HistoryVisibility.Shared) =>
|
|
mkEvent({
|
|
type: EventType.RoomHistoryVisibility,
|
|
event: true,
|
|
content: {
|
|
history_visibility: rule,
|
|
},
|
|
} as any);
|
|
|
|
const mockSpaceId = "mock-space";
|
|
|
|
// TODO case for canonical
|
|
const makeMockSpace = (
|
|
client: MatrixClient,
|
|
joinRule: JoinRule = JoinRule.Invite,
|
|
guestRule: GuestAccess = GuestAccess.CanJoin,
|
|
historyRule: HistoryVisibility = HistoryVisibility.WorldReadable,
|
|
): Room => {
|
|
const events = [makeJoinEvent(joinRule), makeGuestAccessEvent(guestRule), makeHistoryEvent(historyRule)];
|
|
const space = mkSpace(client, mockSpaceId);
|
|
const getStateEvents = mockStateEventImplementation(events);
|
|
mocked(space.currentState).getStateEvents.mockImplementation(getStateEvents);
|
|
mocked(space.currentState).mayClientSendStateEvent.mockReturnValue(false);
|
|
space.getJoinRule.mockReturnValue(joinRule);
|
|
mocked(space.currentState).getJoinRule.mockReturnValue(joinRule);
|
|
return space as unknown as Room;
|
|
};
|
|
const defaultProps = {
|
|
matrixClient: mockMatrixClient,
|
|
space: makeMockSpace(mockMatrixClient),
|
|
closeSettingsFn: jest.fn(),
|
|
};
|
|
|
|
const getComponent = (props = {}) => {
|
|
return render(<SpaceSettingsVisibilityTab {...defaultProps} {...props} />);
|
|
};
|
|
|
|
const toggleGuestAccessSection = async ({ getByTestId }: RenderResult) => {
|
|
const toggleButton = getByTestId("toggle-guest-access-btn")!;
|
|
fireEvent.click(toggleButton);
|
|
};
|
|
const getGuestAccessToggle = ({ getByLabelText }: RenderResult) => getByLabelText("Enable guest access");
|
|
const getHistoryVisibilityToggle = ({ getByLabelText }: RenderResult) => getByLabelText("Preview Space");
|
|
const getErrorMessage = ({ getByTestId }: RenderResult) => getByTestId("space-settings-error")?.textContent;
|
|
|
|
beforeEach(() => {
|
|
let i = 0;
|
|
mocked(secureRandomString).mockImplementation(() => {
|
|
return "testid_" + i++;
|
|
});
|
|
|
|
(mockMatrixClient.sendStateEvent as jest.Mock).mockClear().mockResolvedValue({});
|
|
MatrixClientPeg.get = jest.fn().mockReturnValue(mockMatrixClient);
|
|
MatrixClientPeg.safeGet = jest.fn().mockReturnValue(mockMatrixClient);
|
|
});
|
|
|
|
afterEach(() => {
|
|
jest.runAllTimers();
|
|
});
|
|
|
|
it("renders container", () => {
|
|
const { asFragment } = getComponent();
|
|
expect(asFragment()).toMatchSnapshot();
|
|
});
|
|
|
|
describe("for a private space", () => {
|
|
const joinRule = JoinRule.Invite;
|
|
it("does not render addresses section", () => {
|
|
const space = makeMockSpace(mockMatrixClient, joinRule);
|
|
const { queryByTestId } = getComponent({ space });
|
|
|
|
expect(queryByTestId("published-address-fieldset")).toBeFalsy();
|
|
expect(queryByTestId("local-address-fieldset")).toBeFalsy();
|
|
});
|
|
});
|
|
|
|
describe("for a public space", () => {
|
|
const joinRule = JoinRule.Public;
|
|
const guestRule = GuestAccess.CanJoin;
|
|
const historyRule = HistoryVisibility.Joined;
|
|
|
|
describe("Access", () => {
|
|
it("renders guest access section toggle", async () => {
|
|
const space = makeMockSpace(mockMatrixClient, joinRule, guestRule);
|
|
const component = getComponent({ space });
|
|
|
|
await toggleGuestAccessSection(component);
|
|
|
|
expect(getGuestAccessToggle(component)).toMatchSnapshot();
|
|
});
|
|
|
|
it("send guest access event on toggle", async () => {
|
|
const space = makeMockSpace(mockMatrixClient, joinRule, guestRule);
|
|
|
|
const component = getComponent({ space });
|
|
await toggleGuestAccessSection(component);
|
|
const guestAccessInput = getGuestAccessToggle(component);
|
|
|
|
expect(guestAccessInput).toBeChecked();
|
|
|
|
fireEvent.click(guestAccessInput!);
|
|
expect(mockMatrixClient.sendStateEvent).toHaveBeenCalledWith(
|
|
mockSpaceId,
|
|
EventType.RoomGuestAccess,
|
|
// toggled off
|
|
{ guest_access: GuestAccess.Forbidden },
|
|
"",
|
|
);
|
|
|
|
// toggled off
|
|
expect(guestAccessInput).not.toBeChecked();
|
|
});
|
|
|
|
it("renders error message when update fails", async () => {
|
|
const space = makeMockSpace(mockMatrixClient, joinRule, guestRule);
|
|
(mockMatrixClient.sendStateEvent as jest.Mock).mockRejectedValue({});
|
|
const component = getComponent({ space });
|
|
await toggleGuestAccessSection(component);
|
|
await act(() => {
|
|
fireEvent.click(getGuestAccessToggle(component)!);
|
|
});
|
|
|
|
expect(getErrorMessage(component)).toEqual("Failed to update the guest access of this space");
|
|
});
|
|
|
|
it("disables guest access toggle when setting guest access is not allowed", async () => {
|
|
const space = makeMockSpace(mockMatrixClient, joinRule, guestRule);
|
|
(space.currentState.maySendStateEvent as jest.Mock).mockReturnValue(false);
|
|
const component = getComponent({ space });
|
|
|
|
await toggleGuestAccessSection(component);
|
|
|
|
expect(getGuestAccessToggle(component)).toBeDisabled();
|
|
});
|
|
});
|
|
|
|
describe("Preview", () => {
|
|
it("renders preview space toggle", () => {
|
|
const space = makeMockSpace(mockMatrixClient, joinRule, guestRule, historyRule);
|
|
const component = getComponent({ space });
|
|
|
|
// toggle off because space settings is != WorldReadable
|
|
expect(getHistoryVisibilityToggle(component)).not.toBeChecked();
|
|
});
|
|
|
|
it("updates history visibility on toggle", () => {
|
|
const space = makeMockSpace(mockMatrixClient, joinRule, guestRule, historyRule);
|
|
const component = getComponent({ space });
|
|
|
|
// toggle off because space settings is != WorldReadable
|
|
expect(getHistoryVisibilityToggle(component)).not.toBeChecked();
|
|
|
|
fireEvent.click(getHistoryVisibilityToggle(component)!);
|
|
expect(mockMatrixClient.sendStateEvent).toHaveBeenCalledWith(
|
|
mockSpaceId,
|
|
EventType.RoomHistoryVisibility,
|
|
{ history_visibility: HistoryVisibility.WorldReadable },
|
|
"",
|
|
);
|
|
|
|
expect(getHistoryVisibilityToggle(component)).toBeChecked();
|
|
});
|
|
|
|
it("renders error message when history update fails", async () => {
|
|
const space = makeMockSpace(mockMatrixClient, joinRule, guestRule, historyRule);
|
|
(mockMatrixClient.sendStateEvent as jest.Mock).mockRejectedValue({});
|
|
const component = getComponent({ space });
|
|
|
|
await act(() => {
|
|
fireEvent.click(getHistoryVisibilityToggle(component)!);
|
|
});
|
|
|
|
expect(getErrorMessage(component)).toEqual("Failed to update the history visibility of this space");
|
|
});
|
|
|
|
it("disables room preview toggle when history visibility changes are not allowed", () => {
|
|
const space = makeMockSpace(mockMatrixClient, joinRule, guestRule, historyRule);
|
|
(space.currentState.maySendStateEvent as jest.Mock).mockReturnValue(false);
|
|
const component = getComponent({ space });
|
|
expect(getHistoryVisibilityToggle(component)).toBeDisabled();
|
|
});
|
|
});
|
|
|
|
it("renders addresses section", () => {
|
|
const space = makeMockSpace(mockMatrixClient, joinRule, guestRule);
|
|
const { getByTestId } = getComponent({ space });
|
|
|
|
expect(getByTestId("published-address-fieldset")).toBeTruthy();
|
|
expect(getByTestId("local-address-fieldset")).toBeTruthy();
|
|
});
|
|
});
|
|
});
|