Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 53e9eda

Browse files
committed
Add test for ReactionsRowButton
Signed-off-by: Sumner Evans <sumner@beeper.com>
1 parent 3045c3f commit 53e9eda

File tree

3 files changed

+589
-1
lines changed

3 files changed

+589
-1
lines changed

src/components/views/messages/ReactionsRowButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import ReactionsRowButtonTooltip from "./ReactionsRowButtonTooltip";
2727
import AccessibleButton from "../elements/AccessibleButton";
2828
import MatrixClientContext from "../../../contexts/MatrixClientContext";
2929
import { REACTION_SHORTCODE_KEY } from "./ReactionsRow";
30-
interface IProps {
30+
export interface IProps {
3131
// The event we're displaying reactions for
3232
mxEvent: MatrixEvent;
3333
// The reaction content / key / emoji
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
Copyright 2023 Beeper
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
import React from "react";
17+
import { IContent, MatrixEvent, Room } from "matrix-js-sdk/src/matrix";
18+
import { render } from "@testing-library/react";
19+
20+
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
21+
import { getMockClientWithEventEmitter } from "../../../test-utils";
22+
import ReactionsRowButton, { IProps } from "../../../../src/components/views/messages/ReactionsRowButton";
23+
24+
describe("ReactionsRowButton", () => {
25+
const userId = "@alice:server";
26+
const roomId = "!randomcharacters:aser.ver";
27+
const mockClient = getMockClientWithEventEmitter({
28+
mxcUrlToHttp: jest.fn().mockReturnValue("https://not.a.real.url"),
29+
getRoom: jest.fn(),
30+
});
31+
const room = new Room(roomId, mockClient, userId);
32+
33+
const createProps = (relationContent: IContent): IProps => ({
34+
mxEvent: new MatrixEvent({
35+
room_id: roomId,
36+
event_id: "$test:example.com",
37+
content: { body: "test" },
38+
}),
39+
content: relationContent["m.relates_to"]?.key || "",
40+
count: 2,
41+
reactionEvents: [
42+
new MatrixEvent({
43+
type: "m.reaction",
44+
sender: "@user1:example.com",
45+
content: relationContent,
46+
}),
47+
new MatrixEvent({
48+
type: "m.reaction",
49+
sender: "@user2:example.com",
50+
content: relationContent,
51+
}),
52+
],
53+
customReactionImagesEnabled: true,
54+
});
55+
56+
beforeEach(function () {
57+
jest.clearAllMocks();
58+
mockClient.credentials = { userId: userId };
59+
mockClient.getRoom.mockImplementation((roomId: string): Room | null => {
60+
return roomId === room.roomId ? room : null;
61+
});
62+
});
63+
64+
it("reaction row button renders emojis correctly", () => {
65+
const props = createProps({
66+
"m.relates_to": {
67+
event_id: "$user2:example.com",
68+
key: "👍",
69+
rel_type: "m.annotation",
70+
},
71+
});
72+
const root = render(
73+
<MatrixClientContext.Provider value={mockClient}>
74+
<ReactionsRowButton {...props} />
75+
</MatrixClientContext.Provider>,
76+
);
77+
expect(root).toMatchSnapshot();
78+
79+
// Try hover and make sure that the ReactionsRowButtonTooltip works
80+
const reactionButton = root.getByRole("button");
81+
const event = new MouseEvent("mouseover", {
82+
bubbles: true,
83+
cancelable: true,
84+
});
85+
reactionButton.dispatchEvent(event);
86+
87+
expect(root).toMatchSnapshot();
88+
});
89+
90+
it("reaction row button renders custom image reactions correctly", () => {
91+
const props = createProps({
92+
"com.beeper.reaction.shortcode": ":test:",
93+
"shortcode": ":test:",
94+
"m.relates_to": {
95+
event_id: "$user1:example.com",
96+
key: "mxc://example.com/123456789",
97+
rel_type: "m.annotation",
98+
},
99+
});
100+
101+
const root = render(
102+
<MatrixClientContext.Provider value={mockClient}>
103+
<ReactionsRowButton {...props} />
104+
</MatrixClientContext.Provider>,
105+
);
106+
expect(root).toMatchSnapshot();
107+
108+
// Try hover and make sure that the ReactionsRowButtonTooltip works
109+
const reactionButton = root.getByRole("button");
110+
const event = new MouseEvent("mouseover", {
111+
bubbles: true,
112+
cancelable: true,
113+
});
114+
reactionButton.dispatchEvent(event);
115+
116+
expect(root).toMatchSnapshot();
117+
});
118+
});

0 commit comments

Comments
 (0)