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 830
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Poll history - setup labs setting (#10039)
* add settings while under development * very basic tests for roomsummarycard * empty poll history dialog and option in room summary * pollS history in settings * use more user-centric selectors in roomsummarycard test
- Loading branch information
Kerry
authored
Feb 1, 2023
1 parent
19b81d2
commit 923ad43
Showing
7 changed files
with
366 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
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 { _t } from "../../../../languageHandler"; | ||
import BaseDialog from "../BaseDialog"; | ||
import { IDialogProps } from "../IDialogProps"; | ||
|
||
type PollHistoryDialogProps = Pick<IDialogProps, "onFinished"> & { | ||
roomId: string; | ||
}; | ||
|
||
export const PollHistoryDialog: React.FC<PollHistoryDialogProps> = ({ onFinished }) => { | ||
return ( | ||
<BaseDialog title={_t("Polls history")} onFinished={onFinished}> | ||
{/* @TODO(kerrya) to be implemented in PSG-906 */} | ||
</BaseDialog> | ||
); | ||
}; |
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
182 changes: 182 additions & 0 deletions
182
test/components/views/right_panel/RoomSummaryCard-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,182 @@ | ||
/* | ||
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 { render, fireEvent } from "@testing-library/react"; | ||
import { MatrixEvent, Room } from "matrix-js-sdk/src/matrix"; | ||
|
||
import DMRoomMap from "../../../../src/utils/DMRoomMap"; | ||
import RoomSummaryCard from "../../../../src/components/views/right_panel/RoomSummaryCard"; | ||
import ShareDialog from "../../../../src/components/views/dialogs/ShareDialog"; | ||
import ExportDialog from "../../../../src/components/views/dialogs/ExportDialog"; | ||
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext"; | ||
import defaultDispatcher from "../../../../src/dispatcher/dispatcher"; | ||
import * as settingsHooks from "../../../../src/hooks/useSettings"; | ||
import Modal from "../../../../src/Modal"; | ||
import RightPanelStore from "../../../../src/stores/right-panel/RightPanelStore"; | ||
import { RightPanelPhases } from "../../../../src/stores/right-panel/RightPanelStorePhases"; | ||
import { getMockClientWithEventEmitter, mockClientMethodsUser } from "../../../test-utils"; | ||
import { PollHistoryDialog } from "../../../../src/components/views/dialogs/polls/PollHistoryDialog"; | ||
|
||
describe("<RoomSummaryCard />", () => { | ||
const userId = "@alice:domain.org"; | ||
const mockClient = getMockClientWithEventEmitter({ | ||
...mockClientMethodsUser(userId), | ||
isRoomEncrypted: jest.fn(), | ||
getRoom: jest.fn(), | ||
}); | ||
const roomId = "!room:domain.org"; | ||
const room = new Room(roomId, mockClient, userId); | ||
const roomCreateEvent = new MatrixEvent({ | ||
type: "m.room.create", | ||
room_id: roomId, | ||
sender: userId, | ||
content: { | ||
creator: userId, | ||
room_version: "5", | ||
}, | ||
state_key: "", | ||
}); | ||
room.currentState.setStateEvents([roomCreateEvent]); | ||
const defaultProps = { | ||
room, | ||
onClose: jest.fn(), | ||
}; | ||
const getComponent = (props = {}) => | ||
render(<RoomSummaryCard {...defaultProps} {...props} />, { | ||
wrapper: ({ children }) => ( | ||
<MatrixClientContext.Provider value={mockClient}>{children}</MatrixClientContext.Provider> | ||
), | ||
}); | ||
|
||
const modalSpy = jest.spyOn(Modal, "createDialog"); | ||
const dispatchSpy = jest.spyOn(defaultDispatcher, "dispatch"); | ||
const rightPanelCardSpy = jest.spyOn(RightPanelStore.instance, "pushCard"); | ||
const featureEnabledSpy = jest.spyOn(settingsHooks, "useFeatureEnabled"); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
DMRoomMap.makeShared(); | ||
|
||
mockClient.getRoom.mockReturnValue(room); | ||
jest.spyOn(room, "isElementVideoRoom").mockRestore(); | ||
jest.spyOn(room, "isCallRoom").mockRestore(); | ||
featureEnabledSpy.mockReset().mockReturnValue(false); | ||
}); | ||
|
||
it("renders the room summary", () => { | ||
const { container } = getComponent(); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it("opens room members list on button click", () => { | ||
const { getByText } = getComponent(); | ||
|
||
fireEvent.click(getByText("People")); | ||
|
||
expect(rightPanelCardSpy).toHaveBeenCalledWith({ phase: RightPanelPhases.RoomMemberList }, true); | ||
}); | ||
|
||
it("opens room file panel on button click", () => { | ||
const { getByText } = getComponent(); | ||
|
||
fireEvent.click(getByText("Files")); | ||
|
||
expect(rightPanelCardSpy).toHaveBeenCalledWith({ phase: RightPanelPhases.FilePanel }, true); | ||
}); | ||
|
||
it("opens room export dialog on button click", () => { | ||
const { getByText } = getComponent(); | ||
|
||
fireEvent.click(getByText("Export chat")); | ||
|
||
expect(modalSpy).toHaveBeenCalledWith(ExportDialog, { room }); | ||
}); | ||
|
||
it("opens share room dialog on button click", () => { | ||
const { getByText } = getComponent(); | ||
|
||
fireEvent.click(getByText("Share room")); | ||
|
||
expect(modalSpy).toHaveBeenCalledWith(ShareDialog, { target: room }); | ||
}); | ||
|
||
it("opens room settings on button click", () => { | ||
const { getByText } = getComponent(); | ||
|
||
fireEvent.click(getByText("Room settings")); | ||
|
||
expect(dispatchSpy).toHaveBeenCalledWith({ action: "open_room_settings" }); | ||
}); | ||
|
||
describe("pinning", () => { | ||
it("renders pins options when pinning feature is enabled", () => { | ||
featureEnabledSpy.mockImplementation((feature) => feature === "feature_pinning"); | ||
const { getByText } = getComponent(); | ||
|
||
expect(getByText("Pinned")).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
describe("poll history", () => { | ||
it("renders poll history option when feature is enabled", () => { | ||
featureEnabledSpy.mockImplementation((feature) => feature === "feature_poll_history"); | ||
const { getByText } = getComponent(); | ||
|
||
expect(getByText("Polls history")).toBeInTheDocument(); | ||
}); | ||
|
||
it("opens poll history dialog on button click", () => { | ||
featureEnabledSpy.mockImplementation((feature) => feature === "feature_poll_history"); | ||
const { getByText } = getComponent(); | ||
|
||
fireEvent.click(getByText("Polls history")); | ||
|
||
expect(modalSpy).toHaveBeenCalledWith(PollHistoryDialog, { roomId }); | ||
}); | ||
}); | ||
|
||
describe("video rooms", () => { | ||
it("does not render irrelevant options for element video room", () => { | ||
jest.spyOn(room, "isElementVideoRoom").mockReturnValue(true); | ||
featureEnabledSpy.mockImplementation( | ||
(feature) => feature === "feature_video_rooms" || feature === "feature_pinning", | ||
); | ||
const { queryByText } = getComponent(); | ||
|
||
// options not rendered | ||
expect(queryByText("Files")).not.toBeInTheDocument(); | ||
expect(queryByText("Pinned")).not.toBeInTheDocument(); | ||
expect(queryByText("Export chat")).not.toBeInTheDocument(); | ||
}); | ||
|
||
it("does not render irrelevant options for element call room", () => { | ||
jest.spyOn(room, "isCallRoom").mockReturnValue(true); | ||
featureEnabledSpy.mockImplementation( | ||
(feature) => | ||
feature === "feature_element_call_video_rooms" || | ||
feature === "feature_video_rooms" || | ||
feature === "feature_pinning", | ||
); | ||
const { queryByText } = getComponent(); | ||
|
||
// options not rendered | ||
expect(queryByText("Files")).not.toBeInTheDocument(); | ||
expect(queryByText("Pinned")).not.toBeInTheDocument(); | ||
expect(queryByText("Export chat")).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.