Add developer tools option to room list context menu (#10635)

* Make developer tools more accessible

* Extend tests

* Use settings hook

* Trigger CI
This commit is contained in:
Michael Weimann 2023-04-19 13:34:27 +02:00 committed by GitHub
parent 957945b356
commit 83e6a6057d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 126 additions and 32 deletions

View file

@ -1,5 +1,5 @@
/*
Copyright 2022 The Matrix.org Foundation C.I.C.
Copyright 2022 - 2023 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@ -20,6 +20,7 @@ import { ReceiptType } from "matrix-js-sdk/src/@types/read_receipts";
import { MatrixClient, PendingEventOrdering } from "matrix-js-sdk/src/client";
import { Room } from "matrix-js-sdk/src/models/room";
import React from "react";
import userEvent from "@testing-library/user-event";
import { ChevronFace } from "../../../../src/components/structures/ContextMenu";
import {
@ -34,6 +35,8 @@ import DMRoomMap from "../../../../src/utils/DMRoomMap";
import { mkMessage, stubClient } from "../../../test-utils/test-utils";
import { shouldShowComponent } from "../../../../src/customisations/helpers/UIComponents";
import { UIComponent } from "../../../../src/settings/UIFeature";
import SettingsStore from "../../../../src/settings/SettingsStore";
import Modal from "../../../../src/Modal";
jest.mock("../../../../src/customisations/helpers/UIComponents", () => ({
shouldShowComponent: jest.fn(),
@ -87,6 +90,10 @@ describe("RoomGeneralContextMenu", () => {
onFinished = jest.fn();
});
afterEach(() => {
Modal.closeCurrentModal("force");
});
it("renders an empty context menu for archived rooms", async () => {
jest.spyOn(RoomListStore.instance, "getTagsForRoom").mockReturnValueOnce([DefaultTagID.Archived]);
@ -138,4 +145,28 @@ describe("RoomGeneralContextMenu", () => {
expect(mockClient.sendReadReceipt).toHaveBeenCalledWith(event, ReceiptType.Read, true);
expect(onFinished).toHaveBeenCalled();
});
it("when developer mode is disabled, it should not render the developer tools option", () => {
getComponent();
expect(screen.queryByText("Developer tools")).not.toBeInTheDocument();
});
describe("when developer mode is enabled", () => {
beforeEach(() => {
jest.spyOn(SettingsStore, "getValue").mockImplementation((setting) => setting === "developerMode");
getComponent();
});
it("should render the developer tools option", async () => {
const developerToolsItem = screen.getByRole("menuitem", { name: "Developer tools" });
expect(developerToolsItem).toBeInTheDocument();
// click open developer tools dialog
await userEvent.click(developerToolsItem);
// assert that the dialog is displayed by searching some if its contents
expect(await screen.findByText("Toolbox")).toBeInTheDocument();
expect(await screen.findByText(`Room ID: ${ROOM_ID}`)).toBeInTheDocument();
});
});
});