-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1196 from tchapgouv/1187-copy-link-behavior
TCHAP: add disabled behavior on copy room link when joinrule is invite
- Loading branch information
Showing
7 changed files
with
991 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
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
105 changes: 105 additions & 0 deletions
105
test/unit-tests/tchap/components/views/context_menus/RoomGeneralContextMenu-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,105 @@ | ||
import { logRoles, render, screen } from "jest-matrix-react"; | ||
import { mocked } from "jest-mock"; | ||
import { MatrixClient, PendingEventOrdering, Room, JoinRule, KnownMembership } from "matrix-js-sdk/src/matrix"; | ||
import React from "react"; | ||
|
||
import { stubClient } from "~tchap-web/test/test-utils/test-utils"; | ||
import { clearAllModals } from "~tchap-web/test/test-utils"; | ||
import { ChevronFace } from "~tchap-web/src/components/structures/ContextMenu"; | ||
import { | ||
RoomGeneralContextMenu, | ||
RoomGeneralContextMenuProps, | ||
} from "~tchap-web/src/components/views/context_menus/RoomGeneralContextMenu"; | ||
import MatrixClientContext from "~tchap-web/src/contexts/MatrixClientContext"; | ||
import { MatrixClientPeg } from "~tchap-web/src/MatrixClientPeg"; | ||
import { DefaultTagID } from "~tchap-web/src/stores/room-list/models"; | ||
import RoomListStore from "~tchap-web/src/stores/room-list/RoomListStore"; | ||
import DMRoomMap from "~tchap-web/src/utils/DMRoomMap"; | ||
import TchapRoomUtils from "~tchap-web/src/tchap/util/TchapRoomUtils"; | ||
|
||
jest.mock("~tchap-web/src/tchap/util/TchapRoomUtils"); | ||
|
||
describe("RoomGeneralContextMenu", () => { | ||
const ROOM_ID = "!123:matrix.org"; | ||
|
||
let room: Room; | ||
let mockClient: MatrixClient; | ||
|
||
let onFinished: () => void; | ||
|
||
const mockedTchapRoomUtils = mocked(TchapRoomUtils); | ||
|
||
function getComponent(props?: Partial<RoomGeneralContextMenuProps>) { | ||
return render( | ||
<MatrixClientContext.Provider value={mockClient}> | ||
<RoomGeneralContextMenu | ||
room={room} | ||
onFinished={onFinished} | ||
{...props} | ||
managed={true} | ||
mountAsChild={true} | ||
left={1} | ||
top={1} | ||
chevronFace={ChevronFace.Left} | ||
/> | ||
</MatrixClientContext.Provider>, | ||
); | ||
} | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
|
||
stubClient(); | ||
mockClient = mocked(MatrixClientPeg.safeGet()); | ||
|
||
room = new Room(ROOM_ID, mockClient, mockClient.getUserId() ?? "", { | ||
pendingEventOrdering: PendingEventOrdering.Detached, | ||
}); | ||
|
||
const dmRoomMap = { | ||
getUserIdForRoomId: jest.fn().mockReturnValue(null), | ||
} as unknown as DMRoomMap; | ||
DMRoomMap.setShared(dmRoomMap); | ||
|
||
jest.spyOn(RoomListStore.instance, "getTagsForRoom").mockReturnValueOnce([ | ||
DefaultTagID.DM, | ||
DefaultTagID.Favourite, | ||
]); | ||
|
||
room.updateMyMembership(KnownMembership.Join); | ||
jest.spyOn(room, "canInvite").mockReturnValue(true); | ||
|
||
onFinished = jest.fn(); | ||
}); | ||
|
||
afterEach(async () => { | ||
await clearAllModals(); | ||
}); | ||
|
||
it("renders the default context menu", async () => { | ||
const { container } = getComponent({}); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it("able the copy link button when joinrule is public", () => { | ||
mockedTchapRoomUtils.getRoomJoinRule.mockImplementation(() => JoinRule.Public); | ||
|
||
const { container } = getComponent({}); | ||
|
||
logRoles(container); | ||
|
||
const roomLinkButton = screen.getByRole("menuitem", { name: "Copy room link" }); | ||
|
||
expect(roomLinkButton).not.toHaveAttribute("aria-disabled"); | ||
}); | ||
|
||
it("disable the copy link button when joinrule is not public", () => { | ||
mockedTchapRoomUtils.getRoomJoinRule.mockImplementation(() => JoinRule.Invite); | ||
|
||
getComponent({}); | ||
|
||
const roomLinkButton = screen.getByRole("menuitem", { name: "Copy room link" }); | ||
|
||
expect(roomLinkButton).toHaveAttribute("aria-disabled", "true"); | ||
}); | ||
}); |
148 changes: 148 additions & 0 deletions
148
...s/tchap/components/views/context_menus/__snapshots__/RoomGeneralContextMenu-test.tsx.snap
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,148 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`RoomGeneralContextMenu renders the default context menu 1`] = ` | ||
<div> | ||
<div | ||
class="mx_ContextualMenu_wrapper" | ||
style="top: 1px; left: 1px;" | ||
> | ||
<div | ||
class="mx_ContextualMenu_background" | ||
/> | ||
<div | ||
class="mx_ContextualMenu mx_ContextualMenu_withChevron_left" | ||
role="menu" | ||
> | ||
<div | ||
class="mx_ContextualMenu_chevron_left" | ||
/> | ||
<ul | ||
class="mx_IconizedContextMenu mx_RoomGeneralContextMenu mx_IconizedContextMenu_compact" | ||
role="none" | ||
> | ||
<div | ||
class="mx_IconizedContextMenu_optionList mx_IconizedContextMenu_optionList_notFirst" | ||
> | ||
<li | ||
aria-label="Mark as unread" | ||
class="mx_AccessibleButton mx_IconizedContextMenu_item" | ||
role="menuitem" | ||
tabindex="0" | ||
> | ||
<span | ||
class="mx_IconizedContextMenu_icon mx_RoomGeneralContextMenu_iconMarkAsUnread" | ||
/> | ||
<span | ||
class="mx_IconizedContextMenu_label" | ||
> | ||
Mark as unread | ||
</span> | ||
</li> | ||
<div | ||
aria-checked="false" | ||
aria-label="Favourite" | ||
class="mx_AccessibleButton mx_IconizedContextMenu_item" | ||
role="menuitemcheckbox" | ||
tabindex="-1" | ||
> | ||
<span | ||
class="mx_IconizedContextMenu_icon mx_RoomGeneralContextMenu_iconStar" | ||
/> | ||
<span | ||
class="mx_IconizedContextMenu_label" | ||
> | ||
Favourite | ||
</span> | ||
<span | ||
class="mx_IconizedContextMenu_icon mx_IconizedContextMenu_unchecked" | ||
/> | ||
</div> | ||
<div | ||
aria-checked="false" | ||
aria-label="Low Priority" | ||
class="mx_AccessibleButton mx_IconizedContextMenu_item" | ||
role="menuitemcheckbox" | ||
tabindex="-1" | ||
> | ||
<span | ||
class="mx_IconizedContextMenu_icon mx_RoomGeneralContextMenu_iconArrowDown" | ||
/> | ||
<span | ||
class="mx_IconizedContextMenu_label" | ||
> | ||
Low Priority | ||
</span> | ||
<span | ||
class="mx_IconizedContextMenu_icon mx_IconizedContextMenu_unchecked" | ||
/> | ||
</div> | ||
<li | ||
aria-label="Invite" | ||
class="mx_AccessibleButton mx_IconizedContextMenu_item" | ||
role="menuitem" | ||
tabindex="-1" | ||
> | ||
<span | ||
class="mx_IconizedContextMenu_icon mx_RoomGeneralContextMenu_iconInvite" | ||
/> | ||
<span | ||
class="mx_IconizedContextMenu_label" | ||
> | ||
Invite | ||
</span> | ||
</li> | ||
<li | ||
aria-label="Copy room link" | ||
class="mx_AccessibleButton mx_IconizedContextMenu_item" | ||
role="menuitem" | ||
tabindex="-1" | ||
> | ||
<span | ||
class="mx_IconizedContextMenu_icon mx_RoomGeneralContextMenu_iconCopyLink" | ||
/> | ||
<span | ||
class="mx_IconizedContextMenu_label" | ||
> | ||
Copy room link | ||
</span> | ||
</li> | ||
<li | ||
aria-label="Settings" | ||
class="mx_AccessibleButton mx_IconizedContextMenu_item" | ||
role="menuitem" | ||
tabindex="-1" | ||
> | ||
<span | ||
class="mx_IconizedContextMenu_icon mx_RoomGeneralContextMenu_iconSettings" | ||
/> | ||
<span | ||
class="mx_IconizedContextMenu_label" | ||
> | ||
Settings | ||
</span> | ||
</li> | ||
</div> | ||
<div | ||
class="mx_IconizedContextMenu_optionList mx_IconizedContextMenu_optionList_notFirst mx_IconizedContextMenu_optionList_red" | ||
> | ||
<li | ||
aria-label="Leave" | ||
class="mx_AccessibleButton mx_IconizedContextMenu_option_red mx_IconizedContextMenu_item" | ||
role="menuitem" | ||
tabindex="-1" | ||
> | ||
<span | ||
class="mx_IconizedContextMenu_icon mx_RoomGeneralContextMenu_iconSignOut" | ||
/> | ||
<span | ||
class="mx_IconizedContextMenu_label" | ||
> | ||
Leave | ||
</span> | ||
</li> | ||
</div> | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
`; |
Oops, something went wrong.