This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 833
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show "Invite" menu option if "UIComponent.sendInvites" is enabled.
Signed-off-by: Mikhail Aheichyk <mikhail.aheichyk@nordeck.net>
- Loading branch information
Mikhail Aheichyk
committed
Mar 14, 2023
1 parent
4c2b5df
commit 068f7d6
Showing
4 changed files
with
121 additions
and
3 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
86 changes: 86 additions & 0 deletions
86
test/components/views/context_menus/RoomContextMenu-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,86 @@ | ||
/* | ||
Copyright 2023 Mikhail Aheichyk | ||
Copyright 2023 Nordeck IT + Consulting GmbH. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import { render, screen } from "@testing-library/react"; | ||
import React, { ComponentProps } from "react"; | ||
import { mocked } from "jest-mock"; | ||
import { MatrixClient, PendingEventOrdering } from "matrix-js-sdk/src/client"; | ||
import { Room } from "matrix-js-sdk/src/models/room"; | ||
|
||
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext"; | ||
import RoomContextMenu from "../../../../src/components/views/context_menus/RoomContextMenu"; | ||
import { shouldShowComponent } from "../../../../src/customisations/helpers/UIComponents"; | ||
import { stubClient } from "../../../test-utils"; | ||
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg"; | ||
import DMRoomMap from "../../../../src/utils/DMRoomMap"; | ||
|
||
jest.mock("../../../../src/customisations/helpers/UIComponents", () => ({ | ||
shouldShowComponent: jest.fn(), | ||
})); | ||
|
||
describe("RoomContextMenu", () => { | ||
const ROOM_ID = "!123:matrix.org"; | ||
|
||
let room: Room; | ||
let mockClient: MatrixClient; | ||
|
||
let onFinished: () => void; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
|
||
stubClient(); | ||
mockClient = mocked(MatrixClientPeg.get()); | ||
|
||
room = new Room(ROOM_ID, mockClient, mockClient.getUserId() ?? "", { | ||
pendingEventOrdering: PendingEventOrdering.Detached, | ||
}); | ||
|
||
const dmRoomMap = { | ||
getUserIdForRoomId: jest.fn(), | ||
} as unknown as DMRoomMap; | ||
DMRoomMap.setShared(dmRoomMap); | ||
|
||
onFinished = jest.fn(); | ||
}); | ||
|
||
function getComponent(props: Partial<ComponentProps<typeof RoomContextMenu>> = {}) { | ||
return render( | ||
<MatrixClientContext.Provider value={mockClient}> | ||
<RoomContextMenu room={room} onFinished={onFinished} {...props} /> | ||
</MatrixClientContext.Provider>, | ||
); | ||
} | ||
|
||
it("does not render when UIComponent customisations disable invite", () => { | ||
jest.spyOn(room, "canInvite").mockReturnValue(true); | ||
mocked(shouldShowComponent).mockReturnValue(false); | ||
|
||
getComponent(); | ||
|
||
expect(screen.queryByRole("menuitem", { name: "Invite" })).not.toBeInTheDocument(); | ||
}); | ||
|
||
it("renders when UIComponent customisations enable invite", () => { | ||
jest.spyOn(room, "canInvite").mockReturnValue(true); | ||
mocked(shouldShowComponent).mockReturnValue(true); | ||
|
||
getComponent(); | ||
|
||
expect(screen.getByRole("menuitem", { name: "Invite" })).toBeInTheDocument(); | ||
}); | ||
}); |
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