-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework
UrlPreviewSettings
to use `MatrixClient.CryptoApi.isEncrypti…
…onEnabledInRoom`
- Loading branch information
1 parent
9a12679
commit d2b8446
Showing
4 changed files
with
406 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
test/unit-tests/components/views/room_settings/UrlPreviewSettings-test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright 2024 New Vector Ltd. | ||
* | ||
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only | ||
* Please see LICENSE files in the repository root for full details. | ||
*/ | ||
|
||
import React from "react"; | ||
import { MatrixClient, Room } from "matrix-js-sdk/src/matrix"; | ||
import { render, screen } from "jest-matrix-react"; | ||
import { waitFor } from "@testing-library/dom"; | ||
|
||
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(<UrlPreviewSettings room={room} />, withClientContextRenderOptions(client)); | ||
} | ||
|
||
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, "getValue").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(); | ||
}); | ||
}); |
Oops, something went wrong.