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

Commit bc48d1e

Browse files
committed
Update tests
Signed-off-by: Michael Telatynski <[email protected]>
1 parent 50c8e93 commit bc48d1e

File tree

2 files changed

+330
-165
lines changed

2 files changed

+330
-165
lines changed

test/components/views/right_panel/UserInfo-test.tsx

Lines changed: 77 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ describe("<UserInfo />", () => {
323323
</MatrixClientContext.Provider>,
324324
);
325325

326-
screen.getByRole("button", { name: "Message" });
326+
screen.getByRole("button", { name: "Send message" });
327327
});
328328

329329
it("hides the message button if the visibility customisation hides all create room features", () => {
@@ -342,6 +342,64 @@ describe("<UserInfo />", () => {
342342
},
343343
);
344344
});
345+
346+
describe("Block", () => {
347+
const member = new RoomMember(defaultRoomId, defaultUserId);
348+
349+
it("shows block button when member userId does not match client userId", () => {
350+
// call to client.getUserId returns undefined, which will not match member.userId
351+
renderComponent();
352+
353+
expect(screen.getByRole("button", { name: "Block" })).toBeInTheDocument();
354+
});
355+
356+
it("shows a modal before ignoring the user", async () => {
357+
const originalCreateDialog = Modal.createDialog;
358+
const modalSpy = (Modal.createDialog = jest.fn().mockReturnValue({
359+
finished: Promise.resolve([true]),
360+
close: () => {},
361+
}));
362+
363+
try {
364+
mockClient.getIgnoredUsers.mockReturnValue([]);
365+
renderComponent();
366+
367+
await userEvent.click(screen.getByRole("button", { name: "Block" }));
368+
expect(modalSpy).toHaveBeenCalled();
369+
expect(mockClient.setIgnoredUsers).toHaveBeenLastCalledWith([member.userId]);
370+
} finally {
371+
Modal.createDialog = originalCreateDialog;
372+
}
373+
});
374+
375+
it("cancels ignoring the user", async () => {
376+
const originalCreateDialog = Modal.createDialog;
377+
const modalSpy = (Modal.createDialog = jest.fn().mockReturnValue({
378+
finished: Promise.resolve([false]),
379+
close: () => {},
380+
}));
381+
382+
try {
383+
mockClient.getIgnoredUsers.mockReturnValue([]);
384+
renderComponent();
385+
386+
await userEvent.click(screen.getByRole("button", { name: "Block" }));
387+
expect(modalSpy).toHaveBeenCalled();
388+
expect(mockClient.setIgnoredUsers).not.toHaveBeenCalled();
389+
} finally {
390+
Modal.createDialog = originalCreateDialog;
391+
}
392+
});
393+
394+
it("unignores the user", async () => {
395+
mockClient.isUserIgnored.mockReturnValue(true);
396+
mockClient.getIgnoredUsers.mockReturnValue([member.userId]);
397+
renderComponent();
398+
399+
await userEvent.click(screen.getByRole("button", { name: "Unblock" }));
400+
expect(mockClient.setIgnoredUsers).toHaveBeenCalledWith([]);
401+
});
402+
});
345403
});
346404

347405
describe("with crypto enabled", () => {
@@ -801,7 +859,7 @@ describe("<DeviceItem />", () => {
801859

802860
describe("<UserOptionsSection />", () => {
803861
const member = new RoomMember(defaultRoomId, defaultUserId);
804-
const defaultProps = { member, isIgnored: false, canInvite: false, isSpace: false };
862+
const defaultProps = { member, canInvite: false, isSpace: false };
805863

806864
const renderComponent = (props = {}) => {
807865
const Wrapper = (wrapperProps = {}) => {
@@ -830,7 +888,7 @@ describe("<UserOptionsSection />", () => {
830888

831889
it("always shows share user button", () => {
832890
renderComponent();
833-
expect(screen.getByRole("button", { name: /share link to user/i })).toBeInTheDocument();
891+
expect(screen.getByRole("button", { name: "Share profile" })).toBeInTheDocument();
834892
});
835893

836894
it("does not show ignore or direct message buttons when member userId matches client userId", () => {
@@ -842,36 +900,35 @@ describe("<UserOptionsSection />", () => {
842900
expect(screen.queryByRole("button", { name: /message/i })).not.toBeInTheDocument();
843901
});
844902

845-
it("shows ignore, direct message and mention buttons when member userId does not match client userId", () => {
903+
it("shows direct message and mention buttons when member userId does not match client userId", () => {
846904
// call to client.getUserId returns undefined, which will not match member.userId
847905
renderComponent();
848906

849-
expect(screen.getByRole("button", { name: /ignore/i })).toBeInTheDocument();
850-
expect(screen.getByRole("button", { name: /message/i })).toBeInTheDocument();
851-
expect(screen.getByRole("button", { name: /mention/i })).toBeInTheDocument();
907+
expect(screen.getByRole("button", { name: "Send message" })).toBeInTheDocument();
908+
expect(screen.getByRole("button", { name: "Mention" })).toBeInTheDocument();
852909
});
853910

854911
it("when call to client.getRoom is null, does not show read receipt button", () => {
855912
mockClient.getRoom.mockReturnValueOnce(null);
856913
renderComponent();
857914

858-
expect(screen.queryByRole("button", { name: /jump to read receipt/i })).not.toBeInTheDocument();
915+
expect(screen.queryByRole("button", { name: "Jump to read receipt" })).not.toBeInTheDocument();
859916
});
860917

861918
it("when call to client.getRoom is non-null and room.getEventReadUpTo is null, does not show read receipt button", () => {
862919
mockRoom.getEventReadUpTo.mockReturnValueOnce(null);
863920
mockClient.getRoom.mockReturnValueOnce(mockRoom);
864921
renderComponent();
865922

866-
expect(screen.queryByRole("button", { name: /jump to read receipt/i })).not.toBeInTheDocument();
923+
expect(screen.queryByRole("button", { name: "Jump to read receipt" })).not.toBeInTheDocument();
867924
});
868925

869926
it("when calls to client.getRoom and room.getEventReadUpTo are non-null, shows read receipt button", () => {
870927
mockRoom.getEventReadUpTo.mockReturnValueOnce("1234");
871928
mockClient.getRoom.mockReturnValueOnce(mockRoom);
872929
renderComponent();
873930

874-
expect(screen.getByRole("button", { name: /jump to read receipt/i })).toBeInTheDocument();
931+
expect(screen.getByRole("button", { name: "Jump to read receipt" })).toBeInTheDocument();
875932
});
876933

877934
it("clicking the read receipt button calls dispatch with correct event_id", async () => {
@@ -880,7 +937,7 @@ describe("<UserOptionsSection />", () => {
880937
mockClient.getRoom.mockReturnValue(mockRoom);
881938
renderComponent();
882939

883-
const readReceiptButton = screen.getByRole("button", { name: /jump to read receipt/i });
940+
const readReceiptButton = screen.getByRole("button", { name: "Jump to read receipt" });
884941

885942
expect(readReceiptButton).toBeInTheDocument();
886943
await userEvent.click(readReceiptButton);
@@ -904,7 +961,7 @@ describe("<UserOptionsSection />", () => {
904961
mockClient.getRoom.mockReturnValue(mockRoom);
905962
renderComponent();
906963

907-
const readReceiptButton = screen.getByRole("button", { name: /jump to read receipt/i });
964+
const readReceiptButton = screen.getByRole("button", { name: "Jump to read receipt" });
908965

909966
expect(readReceiptButton).toBeInTheDocument();
910967
await userEvent.click(readReceiptButton);
@@ -964,52 +1021,6 @@ describe("<UserOptionsSection />", () => {
9641021
});
9651022
});
9661023

967-
it("shows a modal before ignoring the user", async () => {
968-
const originalCreateDialog = Modal.createDialog;
969-
const modalSpy = (Modal.createDialog = jest.fn().mockReturnValue({
970-
finished: Promise.resolve([true]),
971-
close: () => {},
972-
}));
973-
974-
try {
975-
mockClient.getIgnoredUsers.mockReturnValue([]);
976-
renderComponent({ isIgnored: false });
977-
978-
await userEvent.click(screen.getByRole("button", { name: "Ignore" }));
979-
expect(modalSpy).toHaveBeenCalled();
980-
expect(mockClient.setIgnoredUsers).toHaveBeenLastCalledWith([member.userId]);
981-
} finally {
982-
Modal.createDialog = originalCreateDialog;
983-
}
984-
});
985-
986-
it("cancels ignoring the user", async () => {
987-
const originalCreateDialog = Modal.createDialog;
988-
const modalSpy = (Modal.createDialog = jest.fn().mockReturnValue({
989-
finished: Promise.resolve([false]),
990-
close: () => {},
991-
}));
992-
993-
try {
994-
mockClient.getIgnoredUsers.mockReturnValue([]);
995-
renderComponent({ isIgnored: false });
996-
997-
await userEvent.click(screen.getByRole("button", { name: "Ignore" }));
998-
expect(modalSpy).toHaveBeenCalled();
999-
expect(mockClient.setIgnoredUsers).not.toHaveBeenCalled();
1000-
} finally {
1001-
Modal.createDialog = originalCreateDialog;
1002-
}
1003-
});
1004-
1005-
it("unignores the user", async () => {
1006-
mockClient.getIgnoredUsers.mockReturnValue([member.userId]);
1007-
renderComponent({ isIgnored: true });
1008-
1009-
await userEvent.click(screen.getByRole("button", { name: "Unignore" }));
1010-
expect(mockClient.setIgnoredUsers).toHaveBeenCalledWith([]);
1011-
});
1012-
10131024
it.each([
10141025
["for a RoomMember", member, member.getMxcAvatarUrl()],
10151026
["for a User", defaultUser, defaultUser.avatarUrl],
@@ -1020,10 +1031,10 @@ describe("<UserOptionsSection />", () => {
10201031
mocked(startDmOnFirstMessage).mockReturnValue(deferred.promise);
10211032

10221033
renderComponent({ member });
1023-
await userEvent.click(screen.getByText("Message"));
1034+
await userEvent.click(screen.getByRole("button", { name: "Send message" }));
10241035

10251036
// Checking the attribute, because the button is a DIV and toBeDisabled() does not work.
1026-
expect(screen.getByText("Message")).toHaveAttribute("disabled");
1037+
expect(screen.getByRole("button", { name: "Send message" })).toBeDisabled();
10271038

10281039
expect(startDmOnFirstMessage).toHaveBeenCalledWith(mockClient, [
10291040
new DirectoryMember({
@@ -1039,7 +1050,7 @@ describe("<UserOptionsSection />", () => {
10391050
});
10401051

10411052
// Checking the attribute, because the button is a DIV and toBeDisabled() does not work.
1042-
expect(screen.getByText("Message")).not.toHaveAttribute("disabled");
1053+
expect(screen.getByRole("button", { name: "Send message" })).not.toBeDisabled();
10431054
},
10441055
);
10451056
});
@@ -1396,10 +1407,9 @@ describe("<RoomAdminToolsContainer />", () => {
13961407

13971408
renderComponent({ member: defaultMemberWithPowerLevel });
13981409

1399-
expect(screen.getByRole("heading", { name: /admin tools/i })).toBeInTheDocument();
1400-
expect(screen.getByText(/disinvite from room/i)).toBeInTheDocument();
1401-
expect(screen.getByText(/ban from room/i)).toBeInTheDocument();
1402-
expect(screen.getByText(/remove recent messages/i)).toBeInTheDocument();
1410+
expect(screen.getByRole("button", { name: "Disinvite from room" })).toBeInTheDocument();
1411+
expect(screen.getByRole("button", { name: "Ban from room" })).toBeInTheDocument();
1412+
expect(screen.getByRole("button", { name: "Remove messages" })).toBeInTheDocument();
14031413
});
14041414

14051415
it("returns mute toggle button if conditions met", () => {
@@ -1441,10 +1451,9 @@ describe("<RoomAdminToolsContainer />", () => {
14411451
isUpdating: true,
14421452
});
14431453

1444-
const button = screen.getByText(/mute/i);
1454+
const button = screen.getByRole("button", { name: "Mute" });
14451455
expect(button).toBeInTheDocument();
1446-
expect(button).toHaveAttribute("disabled");
1447-
expect(button).toHaveAttribute("aria-disabled", "true");
1456+
expect(button).toBeDisabled();
14481457
});
14491458

14501459
it("should not show mute button for one's own member", () => {

0 commit comments

Comments
 (0)