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 828
Fix: Video Room Chat Header Button Removed #11911
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
886a454
"@vector-im/compound-design-tokens": "^0.1.0"
2a3f3d7
add chat button to room header for video rooms
344cd8c
cleanup useEffect, comments
2dd3ceb
Merge branch 'develop' into kerry/26181/video-room-chat-button
268b29b
comment
7fdf0af
Merge branch 'develop' into kerry/26181/video-room-chat-button
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 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
75 changes: 75 additions & 0 deletions
75
src/components/views/rooms/RoomHeader/VideoRoomChatButton.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,75 @@ | ||
/* | ||
Copyright 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. | ||
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 React, { useContext } from "react"; | ||
import { Icon as ChatIcon } from "@vector-im/compound-design-tokens/icons/chat-solid.svg"; | ||
import { Room } from "matrix-js-sdk/src/matrix"; | ||
import { IconButton, Tooltip } from "@vector-im/compound-web"; | ||
|
||
import { isVideoRoom as calcIsVideoRoom } from "../../../../utils/video-rooms"; | ||
import { _t } from "../../../../languageHandler"; | ||
import { useEventEmitterState } from "../../../../hooks/useEventEmitter"; | ||
import { NotificationStateEvents } from "../../../../stores/notifications/NotificationState"; | ||
import { NotificationColor } from "../../../../stores/notifications/NotificationColor"; | ||
import { RightPanelPhases } from "../../../../stores/right-panel/RightPanelStorePhases"; | ||
import { SDKContext } from "../../../../contexts/SDKContext"; | ||
import { ButtonEvent } from "../../elements/AccessibleButton"; | ||
|
||
/** | ||
* Display a button to toggle timeline for video rooms | ||
* @param room | ||
* @returns for a video room: a button to toggle timeline in the right panel | ||
* otherwise null | ||
*/ | ||
export const VideoRoomChatButton: React.FC<{ room: Room }> = ({ room }) => { | ||
const sdkContext = useContext(SDKContext); | ||
|
||
const isVideoRoom = calcIsVideoRoom(room); | ||
|
||
const notificationState = isVideoRoom ? sdkContext.roomNotificationStateStore.getRoomState(room) : undefined; | ||
const notificationColor = useEventEmitterState( | ||
notificationState, | ||
NotificationStateEvents.Update, | ||
() => notificationState?.color, | ||
); | ||
|
||
if (!isVideoRoom) { | ||
return null; | ||
} | ||
|
||
const displayUnreadIndicator = | ||
!!notificationColor && | ||
[NotificationColor.Bold, NotificationColor.Grey, NotificationColor.Red].includes(notificationColor); | ||
|
||
const onClick = (event: ButtonEvent): void => { | ||
// stop event propagating up and triggering RoomHeader bar click | ||
// which will open RoomSummary | ||
event.stopPropagation(); | ||
sdkContext.rightPanelStore.showOrHidePanel(RightPanelPhases.Timeline); | ||
}; | ||
|
||
return ( | ||
<Tooltip label={_t("right_panel|video_room_chat|title")}> | ||
<IconButton | ||
aria-label={_t("right_panel|video_room_chat|title")} | ||
onClick={onClick} | ||
indicator={displayUnreadIndicator ? "default" : undefined} | ||
> | ||
<ChatIcon /> | ||
</IconButton> | ||
</Tooltip> | ||
); | ||
}; |
144 changes: 144 additions & 0 deletions
144
test/components/views/rooms/RoomHeader/VideoRoomChatButton-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,144 @@ | ||
/* | ||
Copyright 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. | ||
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 React from "react"; | ||
import { MockedObject } from "jest-mock"; | ||
import { Room } from "matrix-js-sdk/src/matrix"; | ||
import { fireEvent, render, screen } from "@testing-library/react"; | ||
|
||
import { VideoRoomChatButton } from "../../../../../src/components/views/rooms/RoomHeader/VideoRoomChatButton"; | ||
import { SDKContext, SdkContextClass } from "../../../../../src/contexts/SDKContext"; | ||
import RightPanelStore from "../../../../../src/stores/right-panel/RightPanelStore"; | ||
import { getMockClientWithEventEmitter, mockClientMethodsUser } from "../../../../test-utils"; | ||
import { RoomNotificationState } from "../../../../../src/stores/notifications/RoomNotificationState"; | ||
import { NotificationColor } from "../../../../../src/stores/notifications/NotificationColor"; | ||
import { NotificationStateEvents } from "../../../../../src/stores/notifications/NotificationState"; | ||
import { RightPanelPhases } from "../../../../../src/stores/right-panel/RightPanelStorePhases"; | ||
|
||
describe("<VideoRoomChatButton />", () => { | ||
const roomId = "!room:server.org"; | ||
let sdkContext!: SdkContextClass; | ||
let rightPanelStore!: MockedObject<RightPanelStore>; | ||
|
||
/** | ||
* Create a room using mocked client | ||
* And mock isElementVideoRoom | ||
*/ | ||
const makeRoom = (isVideoRoom = true): Room => { | ||
const room = new Room(roomId, sdkContext.client!, sdkContext.client!.getSafeUserId()); | ||
jest.spyOn(room, "isElementVideoRoom").mockReturnValue(isVideoRoom); | ||
// stub | ||
jest.spyOn(room, "getPendingEvents").mockReturnValue([]); | ||
return room; | ||
}; | ||
|
||
const mockRoomNotificationState = (room: Room, color: NotificationColor): RoomNotificationState => { | ||
const roomNotificationState = new RoomNotificationState(room); | ||
|
||
// @ts-ignore ugly mocking | ||
roomNotificationState._color = color; | ||
jest.spyOn(sdkContext.roomNotificationStateStore, "getRoomState").mockReturnValue(roomNotificationState); | ||
return roomNotificationState; | ||
}; | ||
|
||
const getComponent = (room: Room) => | ||
render(<VideoRoomChatButton room={room} />, { | ||
wrapper: ({ children }) => <SDKContext.Provider value={sdkContext}>{children}</SDKContext.Provider>, | ||
}); | ||
|
||
beforeEach(() => { | ||
const client = getMockClientWithEventEmitter({ | ||
...mockClientMethodsUser(), | ||
}); | ||
rightPanelStore = { | ||
showOrHidePanel: jest.fn(), | ||
} as unknown as MockedObject<RightPanelStore>; | ||
sdkContext = new SdkContextClass(); | ||
sdkContext.client = client; | ||
jest.spyOn(sdkContext, "rightPanelStore", "get").mockReturnValue(rightPanelStore); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
it("does not render button when room is not a video room", () => { | ||
const room = makeRoom(false); | ||
getComponent(room); | ||
|
||
expect(screen.queryByLabelText("Chat")).not.toBeInTheDocument(); | ||
}); | ||
|
||
it("renders button when room is a video room", () => { | ||
const room = makeRoom(); | ||
getComponent(room); | ||
|
||
expect(screen.getByLabelText("Chat")).toMatchSnapshot(); | ||
}); | ||
|
||
it("toggles timeline in right panel on click", () => { | ||
const room = makeRoom(); | ||
getComponent(room); | ||
|
||
fireEvent.click(screen.getByLabelText("Chat")); | ||
|
||
expect(sdkContext.rightPanelStore.showOrHidePanel).toHaveBeenCalledWith(RightPanelPhases.Timeline); | ||
}); | ||
|
||
it("renders button with an unread marker when room is unread", () => { | ||
const room = makeRoom(); | ||
mockRoomNotificationState(room, NotificationColor.Bold); | ||
getComponent(room); | ||
|
||
// snapshot includes `data-indicator` attribute | ||
expect(screen.getByLabelText("Chat")).toMatchSnapshot(); | ||
expect(screen.getByLabelText("Chat").hasAttribute("data-indicator")).toBeTruthy(); | ||
}); | ||
|
||
it("adds unread marker when room notification state changes to unread", () => { | ||
const room = makeRoom(); | ||
// start in read state | ||
const notificationState = mockRoomNotificationState(room, NotificationColor.None); | ||
getComponent(room); | ||
|
||
// no unread marker | ||
expect(screen.getByLabelText("Chat").hasAttribute("data-indicator")).toBeFalsy(); | ||
|
||
// @ts-ignore ugly mocking | ||
notificationState._color = NotificationColor.Red; | ||
notificationState.emit(NotificationStateEvents.Update); | ||
|
||
// unread marker | ||
expect(screen.getByLabelText("Chat").hasAttribute("data-indicator")).toBeTruthy(); | ||
}); | ||
|
||
it("clears unread marker when room notification state changes to read", () => { | ||
const room = makeRoom(); | ||
// start in unread state | ||
const notificationState = mockRoomNotificationState(room, NotificationColor.Red); | ||
getComponent(room); | ||
|
||
// unread marker | ||
expect(screen.getByLabelText("Chat").hasAttribute("data-indicator")).toBeTruthy(); | ||
|
||
// @ts-ignore ugly mocking | ||
notificationState._color = NotificationColor.None; | ||
notificationState.emit(NotificationStateEvents.Update); | ||
|
||
// unread marker cleared | ||
expect(screen.getByLabelText("Chat").hasAttribute("data-indicator")).toBeFalsy(); | ||
}); | ||
}); |
24 changes: 24 additions & 0 deletions
24
test/components/views/rooms/RoomHeader/__snapshots__/VideoRoomChatButton-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,24 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<VideoRoomChatButton /> renders button when room is a video room 1`] = ` | ||
<button | ||
aria-label="Chat" | ||
class="_icon-button_1qjaf_17" | ||
data-state="closed" | ||
style="--cpd-icon-button-size: 32px;" | ||
> | ||
<div /> | ||
</button> | ||
`; | ||
|
||
exports[`<VideoRoomChatButton /> renders button with an unread marker when room is unread 1`] = ` | ||
<button | ||
aria-label="Chat" | ||
class="_icon-button_1qjaf_17" | ||
data-indicator="default" | ||
data-state="closed" | ||
style="--cpd-icon-button-size: 32px;" | ||
> | ||
<div /> | ||
</button> | ||
`; |
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
Oops, something went wrong.
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.
Might be worth having a comment to say it renders nothing outside of video rooms to avoid confusion without jumping into its source