1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-08-06 10:22:45 +03:00

Expose and pre-populate thread ID in devtools dialog (#10953)

Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Travis Ralston
2023-07-07 08:40:25 -06:00
committed by GitHub
parent cfd48b36aa
commit 8a97e5f351
8 changed files with 286 additions and 48 deletions

View File

@@ -15,7 +15,7 @@ limitations under the License.
*/
import React from "react";
import { getByLabelText, render } from "@testing-library/react";
import { getByLabelText, getAllByLabelText, render } from "@testing-library/react";
import { Room } from "matrix-js-sdk/src/models/room";
import { MatrixClient } from "matrix-js-sdk/src/client";
import userEvent from "@testing-library/user-event";
@@ -29,10 +29,10 @@ describe("DevtoolsDialog", () => {
let cli: MatrixClient;
let room: Room;
function getComponent(roomId: string, onFinished = () => true) {
function getComponent(roomId: string, threadRootId: string | null = null, onFinished = () => true) {
return render(
<MatrixClientContext.Provider value={cli}>
<DevtoolsDialog roomId={roomId} onFinished={onFinished} />
<DevtoolsDialog roomId={roomId} threadRootId={threadRootId} onFinished={onFinished} />
</MatrixClientContext.Provider>,
);
}
@@ -68,4 +68,20 @@ describe("DevtoolsDialog", () => {
expect(navigator.clipboard.writeText).toHaveBeenCalled();
expect(navigator.clipboard.readText()).resolves.toBe(room.roomId);
});
it("copies the thread root id when provided", async () => {
const user = userEvent.setup();
jest.spyOn(navigator.clipboard, "writeText");
const threadRootId = "$test_event_id_goes_here";
const { container } = getComponent(room.roomId, threadRootId);
const copyBtn = getAllByLabelText(container, "Copy")[1];
await user.click(copyBtn);
const copiedBtn = getByLabelText(container, "Copied!");
expect(copiedBtn).toBeInTheDocument();
expect(navigator.clipboard.writeText).toHaveBeenCalled();
expect(navigator.clipboard.readText()).resolves.toBe(threadRootId);
});
});