|
| 1 | +import { render, screen } from "@testing-library/react"; |
| 2 | +import GroupChatListItem from "features/messages/groupchats/GroupChatListItem"; |
| 3 | +import { GroupChat } from "proto/conversations_pb"; |
| 4 | +import { service } from "service"; |
| 5 | +import groupChat from "test/fixtures/groupChat.json"; |
| 6 | +import wrapper from "test/hookWrapper"; |
| 7 | +import { getLiteUsers } from "test/serviceMockDefaults"; |
| 8 | +import { addDefaultUser } from "test/utils"; |
| 9 | + |
| 10 | +const getLiteUsersMock = service.user.getLiteUsers as jest.Mock; |
| 11 | + |
| 12 | +beforeEach(() => { |
| 13 | + addDefaultUser(1); |
| 14 | + getLiteUsersMock.mockImplementation(getLiteUsers); |
| 15 | +}); |
| 16 | + |
| 17 | +afterEach(() => jest.restoreAllMocks()); |
| 18 | + |
| 19 | +describe("GroupChatListItem avatar", () => { |
| 20 | + it("shows a group icon for non-DM group chats", async () => { |
| 21 | + render(<GroupChatListItem groupChat={groupChat} />, { wrapper }); |
| 22 | + |
| 23 | + expect(await screen.findByTestId("GroupsIcon")).toBeVisible(); |
| 24 | + expect(screen.queryByText("FD")).not.toBeInTheDocument(); |
| 25 | + }); |
| 26 | + |
| 27 | + it("shows the other member's avatar for DMs", async () => { |
| 28 | + const dmGroupChat: GroupChat.AsObject = { |
| 29 | + ...groupChat, |
| 30 | + isDm: true, |
| 31 | + latestMessage: { |
| 32 | + ...groupChat.latestMessage!, |
| 33 | + authorUserId: 2, |
| 34 | + text: { text: "Reply" }, |
| 35 | + }, |
| 36 | + }; |
| 37 | + |
| 38 | + render(<GroupChatListItem groupChat={dmGroupChat} />, { wrapper }); |
| 39 | + |
| 40 | + expect(await screen.findByText("FD")).toBeVisible(); |
| 41 | + expect(screen.queryByTestId("GroupsIcon")).not.toBeInTheDocument(); |
| 42 | + }); |
| 43 | + |
| 44 | + it("shows the other member's avatar for DMs even when current user sent the latest message", async () => { |
| 45 | + const dmGroupChat: GroupChat.AsObject = { |
| 46 | + ...groupChat, |
| 47 | + isDm: true, |
| 48 | + latestMessage: { |
| 49 | + ...groupChat.latestMessage!, |
| 50 | + authorUserId: 1, |
| 51 | + text: { text: "Hello there" }, |
| 52 | + }, |
| 53 | + }; |
| 54 | + |
| 55 | + render(<GroupChatListItem groupChat={dmGroupChat} />, { wrapper }); |
| 56 | + |
| 57 | + expect(await screen.findByText("FD")).toBeVisible(); |
| 58 | + expect(screen.queryByTestId("GroupsIcon")).not.toBeInTheDocument(); |
| 59 | + }); |
| 60 | +}); |
0 commit comments