This repository was archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 823
Show "Invite" menu option if "UIComponent.sendInvites" is enabled. #10363
Merged
kerryarchibald
merged 6 commits into
matrix-org:develop
from
nordeck:room_menu_invite_should_show
Mar 27, 2023
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
068f7d6
Show "Invite" menu option if "UIComponent.sendInvites" is enabled.
43fa9b8
Update test names
f6458e7
Merge branch 'develop' into room_menu_invite_should_show
maheichyk 766f4bf
Merge branch 'develop' into room_menu_invite_should_show
maheichyk 12e8d5a
Merge branch 'develop' into room_menu_invite_should_show
maheichyk 0f75958
Merge branch 'develop' into room_menu_invite_should_show
maheichyk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and | |
limitations under the License. | ||
*/ | ||
|
||
import { fireEvent, getByLabelText, render } from "@testing-library/react"; | ||
import { fireEvent, getByLabelText, render, screen } from "@testing-library/react"; | ||
import { mocked } from "jest-mock"; | ||
import { ReceiptType } from "matrix-js-sdk/src/@types/read_receipts"; | ||
import { MatrixClient, PendingEventOrdering } from "matrix-js-sdk/src/client"; | ||
|
@@ -32,6 +32,12 @@ import { DefaultTagID } from "../../../../src/stores/room-list/models"; | |
import RoomListStore from "../../../../src/stores/room-list/RoomListStore"; | ||
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"; | ||
|
||
jest.mock("../../../../src/customisations/helpers/UIComponents", () => ({ | ||
shouldShowComponent: jest.fn(), | ||
})); | ||
|
||
describe("RoomGeneralContextMenu", () => { | ||
const ROOM_ID = "!123:matrix.org"; | ||
|
@@ -93,6 +99,28 @@ describe("RoomGeneralContextMenu", () => { | |
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it("does not render when UIComponent customisations disable room invite", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here for more specific test descriptions There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is updated, thanks for notice |
||
room.updateMyMembership("join"); | ||
jest.spyOn(room, "canInvite").mockReturnValue(true); | ||
mocked(shouldShowComponent).mockReturnValue(false); | ||
|
||
getComponent({}); | ||
|
||
expect(shouldShowComponent).toHaveBeenCalledWith(UIComponent.InviteUsers); | ||
expect(screen.queryByRole("menuitem", { name: "Invite" })).not.toBeInTheDocument(); | ||
}); | ||
|
||
it("renders when UIComponent customisations enables invite", () => { | ||
room.updateMyMembership("join"); | ||
jest.spyOn(room, "canInvite").mockReturnValue(true); | ||
mocked(shouldShowComponent).mockReturnValue(true); | ||
|
||
getComponent({}); | ||
|
||
expect(shouldShowComponent).toHaveBeenCalledWith(UIComponent.InviteUsers); | ||
expect(screen.getByRole("menuitem", { name: "Invite" })).toBeInTheDocument(); | ||
}); | ||
|
||
it("marks the room as read", async () => { | ||
const event = mkMessage({ | ||
event: true, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you be more specific about which component is/is not rendered here? Ie
does not render Invite button when...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test name is updated