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 827
Add mark as read option in room setting #9798
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
50f3a50
Add mark as read option in room setting
germain-gg 96f15de
Address product review
germain-gg 6cdfb0d
strict fixes
germain-gg 619088e
Merge branch 'develop' into gsouquet/room-markasread
germain-gg 86ae6e0
strict fix
germain-gg 010313a
strict fixes
germain-gg 192a1f6
types
germain-gg a1a7bd0
fix test
germain-gg 0131828
Merge branch 'develop' into gsouquet/room-markasread
ba65b6e
Merge branch 'develop' into gsouquet/room-markasread
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
113 changes: 113 additions & 0 deletions
113
test/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,113 @@ | ||
/* | ||
Copyright 2022 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 { fireEvent, getByLabelText, render } 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"; | ||
import { Room } from "matrix-js-sdk/src/models/room"; | ||
import React from "react"; | ||
|
||
import { ChevronFace } from "../../../../src/components/structures/ContextMenu"; | ||
import { | ||
RoomGeneralContextMenu, | ||
RoomGeneralContextMenuProps, | ||
} from "../../../../src/components/views/context_menus/RoomGeneralContextMenu"; | ||
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext"; | ||
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg"; | ||
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"; | ||
|
||
describe("RoomGeneralContextMenu", () => { | ||
const ROOM_ID = "!123:matrix.org"; | ||
|
||
let room: Room; | ||
let mockClient: MatrixClient; | ||
|
||
let onFinished; | ||
|
||
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.get()); | ||
|
||
room = new Room(ROOM_ID, mockClient, mockClient.getUserId() ?? "", { | ||
pendingEventOrdering: PendingEventOrdering.Detached, | ||
}); | ||
|
||
const dmRoomMap = { | ||
getUserIdForRoomId: jest.fn(), | ||
} as unknown as DMRoomMap; | ||
DMRoomMap.setShared(dmRoomMap); | ||
|
||
jest.spyOn(RoomListStore.instance, "getTagsForRoom").mockReturnValueOnce([ | ||
DefaultTagID.DM, | ||
DefaultTagID.Favourite, | ||
]); | ||
|
||
onFinished = jest.fn(); | ||
}); | ||
|
||
it("renders an empty context menu for archived rooms", async () => { | ||
jest.spyOn(RoomListStore.instance, "getTagsForRoom").mockReturnValueOnce([DefaultTagID.Archived]); | ||
|
||
const { container } = getComponent({}); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it("renders the default context menu", async () => { | ||
const { container } = getComponent({}); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it("marks the room as read", async () => { | ||
const event = mkMessage({ | ||
event: true, | ||
room: "!room:id", | ||
user: "@user:id", | ||
ts: 1000, | ||
}); | ||
room.addLiveEvents([event], {}); | ||
|
||
const { container } = getComponent({}); | ||
|
||
const markAsReadBtn = getByLabelText(container, "Mark as read"); | ||
fireEvent.click(markAsReadBtn); | ||
|
||
expect(mockClient.sendReadReceipt).toHaveBeenCalledWith(event, ReceiptType.Read, true); | ||
expect(onFinished).toHaveBeenCalled(); | ||
}); | ||
}); |
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.
This should be done using the SVG icon approach but would warrant too large of a refactor on an untested part of the codebase that I do not want to test right now.