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

Commit 068a293

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

File tree

3 files changed

+616
-1
lines changed

3 files changed

+616
-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: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
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+
80+
it("reaction row button renders custom image reactions correctly", () => {
81+
const props = createProps({
82+
"com.beeper.reaction.shortcode": ":test:",
83+
"shortcode": ":test:",
84+
"m.relates_to": {
85+
event_id: "$user1:example.com",
86+
key: "mxc://example.com/123456789",
87+
rel_type: "m.annotation",
88+
},
89+
});
90+
91+
const root = render(
92+
<MatrixClientContext.Provider value={mockClient}>
93+
<ReactionsRowButton {...props} />
94+
</MatrixClientContext.Provider>,
95+
);
96+
expect(root).toMatchSnapshot();
97+
});
98+
99+
it("reaction row button renders emoji reactions in the tooltip correctly", () => {
100+
const props = createProps({
101+
"m.relates_to": {
102+
event_id: "$user2:example.com",
103+
key: "👍",
104+
rel_type: "m.annotation",
105+
},
106+
});
107+
108+
const root = render(
109+
<MatrixClientContext.Provider value={mockClient}>
110+
<ReactionsRowButton {...props} />
111+
</MatrixClientContext.Provider>,
112+
);
113+
const reactionButton = root.getByRole("button");
114+
const event = new MouseEvent("mouseover", {
115+
bubbles: true,
116+
cancelable: true,
117+
});
118+
reactionButton.dispatchEvent(event);
119+
120+
expect(root).toMatchSnapshot();
121+
});
122+
123+
it("reaction row button renders custom image reactions in the tooltip correctly", () => {
124+
const props = createProps({
125+
"com.beeper.reaction.shortcode": ":test:",
126+
"shortcode": ":test:",
127+
"m.relates_to": {
128+
event_id: "$user1:example.com",
129+
key: "mxc://example.com/123456789",
130+
rel_type: "m.annotation",
131+
},
132+
});
133+
134+
const root = render(
135+
<MatrixClientContext.Provider value={mockClient}>
136+
<ReactionsRowButton {...props} />
137+
</MatrixClientContext.Provider>,
138+
);
139+
const reactionButton = root.getByRole("button");
140+
const event = new MouseEvent("mouseover", {
141+
bubbles: true,
142+
cancelable: true,
143+
});
144+
reactionButton.dispatchEvent(event);
145+
146+
expect(root).toMatchSnapshot();
147+
});
148+
});

0 commit comments

Comments
 (0)