* 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>
97 lines
4.0 KiB
TypeScript
97 lines
4.0 KiB
TypeScript
/*
|
|
* Copyright 2024 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 { type MatrixClient, type Room } from "matrix-js-sdk/src/matrix";
|
|
import { render, screen } from "jest-matrix-react";
|
|
import { waitFor } from "@testing-library/dom";
|
|
import { Form } from "@vector-im/compound-web";
|
|
|
|
import { createTestClient, mkStubRoom, withClientContextRenderOptions } from "../../../../test-utils";
|
|
import { UrlPreviewSettings } from "../../../../../src/components/views/room_settings/UrlPreviewSettings.tsx";
|
|
import SettingsStore from "../../../../../src/settings/SettingsStore.ts";
|
|
import dis from "../../../../../src/dispatcher/dispatcher.ts";
|
|
import { Action } from "../../../../../src/dispatcher/actions.ts";
|
|
|
|
describe("UrlPreviewSettings", () => {
|
|
let client: MatrixClient;
|
|
let room: Room;
|
|
|
|
beforeEach(() => {
|
|
client = createTestClient();
|
|
room = mkStubRoom("roomId", "room", client);
|
|
});
|
|
|
|
afterEach(() => {
|
|
jest.restoreAllMocks();
|
|
});
|
|
|
|
function renderComponent() {
|
|
return render(
|
|
<Form.Root>
|
|
<UrlPreviewSettings room={room} />
|
|
</Form.Root>,
|
|
withClientContextRenderOptions(client),
|
|
);
|
|
}
|
|
|
|
it("should display the correct preview when the setting is in a loading state", () => {
|
|
jest.spyOn(client, "getCrypto").mockReturnValue(undefined);
|
|
const { asFragment } = renderComponent();
|
|
expect(screen.getByText("URL Previews")).toBeInTheDocument();
|
|
|
|
expect(asFragment()).toMatchSnapshot();
|
|
});
|
|
|
|
it("should display the correct preview when the room is encrypted and the url preview is enabled", async () => {
|
|
jest.spyOn(client.getCrypto()!, "isEncryptionEnabledInRoom").mockResolvedValue(true);
|
|
jest.spyOn(SettingsStore, "getValueAt").mockReturnValue(true);
|
|
|
|
const { asFragment } = renderComponent();
|
|
await waitFor(() => {
|
|
expect(
|
|
screen.getByText(
|
|
"In encrypted rooms, like this one, URL previews are disabled by default to ensure that your homeserver (where the previews are generated) cannot gather information about links you see in this room.",
|
|
),
|
|
).toBeInTheDocument();
|
|
});
|
|
expect(asFragment()).toMatchSnapshot();
|
|
});
|
|
|
|
it("should display the correct preview when the room is unencrypted and the url preview is enabled", async () => {
|
|
jest.spyOn(client.getCrypto()!, "isEncryptionEnabledInRoom").mockResolvedValue(false);
|
|
jest.spyOn(SettingsStore, "getValueAt").mockReturnValue(true);
|
|
jest.spyOn(dis, "fire").mockReturnValue(undefined);
|
|
|
|
const { asFragment } = renderComponent();
|
|
await waitFor(() => {
|
|
expect(screen.getByRole("button", { name: "enabled" })).toBeInTheDocument();
|
|
expect(
|
|
screen.getByText("URL previews are enabled by default for participants in this room."),
|
|
).toBeInTheDocument();
|
|
});
|
|
expect(asFragment()).toMatchSnapshot();
|
|
|
|
screen.getByRole("button", { name: "enabled" }).click();
|
|
expect(dis.fire).toHaveBeenCalledWith(Action.ViewUserSettings);
|
|
});
|
|
|
|
it("should display the correct preview when the room is unencrypted and the url preview is disabled", async () => {
|
|
jest.spyOn(client.getCrypto()!, "isEncryptionEnabledInRoom").mockResolvedValue(false);
|
|
jest.spyOn(SettingsStore, "getValueAt").mockReturnValue(false);
|
|
|
|
const { asFragment } = renderComponent();
|
|
await waitFor(() => {
|
|
expect(screen.getByRole("button", { name: "disabled" })).toBeInTheDocument();
|
|
expect(
|
|
screen.getByText("URL previews are disabled by default for participants in this room."),
|
|
).toBeInTheDocument();
|
|
});
|
|
expect(asFragment()).toMatchSnapshot();
|
|
});
|
|
});
|