Revert "Member avatars without canvas" (#10057
* Revert "Apply more general fix for base avatar regressions (#10045)" This reverts commit371a3c0d36
. * Revert "Fix layout and visual regressions around default avatars (#10031)" This reverts commit0d1fce37b2
. * Revert "Member avatars without canvas (#9990)" This reverts commita8aa4de4b4
. * Update snapshots
This commit is contained in:
parent
43e7870d92
commit
21c3967010
27 changed files with 352 additions and 823 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2022 - 2023 The Matrix.org Foundation C.I.C.
|
||||
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.
|
||||
|
@ -15,106 +15,33 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import { mocked } from "jest-mock";
|
||||
import { Room, RoomMember, RoomType, User } from "matrix-js-sdk/src/matrix";
|
||||
import { Room, RoomMember, RoomType } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import {
|
||||
avatarUrlForMember,
|
||||
avatarUrlForRoom,
|
||||
avatarUrlForUser,
|
||||
defaultAvatarUrlForString,
|
||||
getColorForString,
|
||||
getInitialLetter,
|
||||
} from "../src/Avatar";
|
||||
import { mediaFromMxc } from "../src/customisations/Media";
|
||||
import { avatarUrlForRoom } from "../src/Avatar";
|
||||
import { Media, mediaFromMxc } from "../src/customisations/Media";
|
||||
import DMRoomMap from "../src/utils/DMRoomMap";
|
||||
import { filterConsole, stubClient } from "./test-utils";
|
||||
|
||||
jest.mock("../src/customisations/Media", () => ({
|
||||
mediaFromMxc: jest.fn(),
|
||||
}));
|
||||
|
||||
const roomId = "!room:example.com";
|
||||
const avatarUrl1 = "https://example.com/avatar1";
|
||||
const avatarUrl2 = "https://example.com/avatar2";
|
||||
|
||||
describe("avatarUrlForMember", () => {
|
||||
let member: RoomMember;
|
||||
|
||||
beforeEach(() => {
|
||||
stubClient();
|
||||
member = new RoomMember(roomId, "@user:example.com");
|
||||
});
|
||||
|
||||
it("returns the member's url", () => {
|
||||
const mxc = "mxc://example.com/a/b/c/d/avatar.gif";
|
||||
jest.spyOn(member, "getMxcAvatarUrl").mockReturnValue(mxc);
|
||||
|
||||
expect(avatarUrlForMember(member, 32, 32, "crop")).toBe(
|
||||
mediaFromMxc(mxc).getThumbnailOfSourceHttp(32, 32, "crop"),
|
||||
);
|
||||
});
|
||||
|
||||
it("returns a default if the member has no avatar", () => {
|
||||
jest.spyOn(member, "getMxcAvatarUrl").mockReturnValue(undefined);
|
||||
|
||||
expect(avatarUrlForMember(member, 32, 32, "crop")).toMatch(/^data:/);
|
||||
});
|
||||
});
|
||||
|
||||
describe("avatarUrlForUser", () => {
|
||||
let user: User;
|
||||
|
||||
beforeEach(() => {
|
||||
stubClient();
|
||||
user = new User("@user:example.com");
|
||||
});
|
||||
|
||||
it("should return the user's avatar", () => {
|
||||
const mxc = "mxc://example.com/a/b/c/d/avatar.gif";
|
||||
user.avatarUrl = mxc;
|
||||
|
||||
expect(avatarUrlForUser(user, 64, 64, "scale")).toBe(
|
||||
mediaFromMxc(mxc).getThumbnailOfSourceHttp(64, 64, "scale"),
|
||||
);
|
||||
});
|
||||
|
||||
it("should not provide a fallback", () => {
|
||||
expect(avatarUrlForUser(user, 64, 64, "scale")).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("defaultAvatarUrlForString", () => {
|
||||
it.each(["a", "abc", "abcde", "@".repeat(150)])("should return a value for %s", (s) => {
|
||||
expect(defaultAvatarUrlForString(s)).not.toBe("");
|
||||
});
|
||||
});
|
||||
|
||||
describe("getColorForString", () => {
|
||||
it.each(["a", "abc", "abcde", "@".repeat(150)])("should return a value for %s", (s) => {
|
||||
expect(getColorForString(s)).toMatch(/^#\w+$/);
|
||||
});
|
||||
|
||||
it("should return different values for different strings", () => {
|
||||
expect(getColorForString("a")).not.toBe(getColorForString("b"));
|
||||
});
|
||||
});
|
||||
|
||||
describe("getInitialLetter", () => {
|
||||
filterConsole("argument to `getInitialLetter` not supplied");
|
||||
|
||||
it.each(["a", "abc", "abcde", "@".repeat(150)])("should return a value for %s", (s) => {
|
||||
expect(getInitialLetter(s)).not.toBe("");
|
||||
});
|
||||
|
||||
it("should return undefined for empty strings", () => {
|
||||
expect(getInitialLetter("")).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("avatarUrlForRoom", () => {
|
||||
let getThumbnailOfSourceHttp: jest.Mock;
|
||||
let room: Room;
|
||||
let roomMember: RoomMember;
|
||||
let dmRoomMap: DMRoomMap;
|
||||
|
||||
beforeEach(() => {
|
||||
stubClient();
|
||||
|
||||
getThumbnailOfSourceHttp = jest.fn();
|
||||
mocked(mediaFromMxc).mockImplementation((): Media => {
|
||||
return {
|
||||
getThumbnailOfSourceHttp,
|
||||
} as unknown as Media;
|
||||
});
|
||||
room = {
|
||||
roomId,
|
||||
getMxcAvatarUrl: jest.fn(),
|
||||
|
@ -132,14 +59,14 @@ describe("avatarUrlForRoom", () => {
|
|||
});
|
||||
|
||||
it("should return null for a null room", () => {
|
||||
expect(avatarUrlForRoom(undefined, 128, 128)).toBeNull();
|
||||
expect(avatarUrlForRoom(null, 128, 128)).toBeNull();
|
||||
});
|
||||
|
||||
it("should return the HTTP source if the room provides a MXC url", () => {
|
||||
mocked(room.getMxcAvatarUrl).mockReturnValue(avatarUrl1);
|
||||
expect(avatarUrlForRoom(room, 128, 256, "crop")).toBe(
|
||||
mediaFromMxc(avatarUrl1).getThumbnailOfSourceHttp(128, 256, "crop"),
|
||||
);
|
||||
getThumbnailOfSourceHttp.mockReturnValue(avatarUrl2);
|
||||
expect(avatarUrlForRoom(room, 128, 256, "crop")).toEqual(avatarUrl2);
|
||||
expect(getThumbnailOfSourceHttp).toHaveBeenCalledWith(128, 256, "crop");
|
||||
});
|
||||
|
||||
it("should return null for a space room", () => {
|
||||
|
@ -156,7 +83,7 @@ describe("avatarUrlForRoom", () => {
|
|||
|
||||
it("should return null if there is no other member in the room", () => {
|
||||
mocked(dmRoomMap).getUserIdForRoomId.mockReturnValue("@user:example.com");
|
||||
mocked(room.getAvatarFallbackMember).mockReturnValue(undefined);
|
||||
mocked(room.getAvatarFallbackMember).mockReturnValue(null);
|
||||
expect(avatarUrlForRoom(room, 128, 128)).toBeNull();
|
||||
});
|
||||
|
||||
|
@ -170,8 +97,8 @@ describe("avatarUrlForRoom", () => {
|
|||
mocked(dmRoomMap).getUserIdForRoomId.mockReturnValue("@user:example.com");
|
||||
mocked(room.getAvatarFallbackMember).mockReturnValue(roomMember);
|
||||
mocked(roomMember.getMxcAvatarUrl).mockReturnValue(avatarUrl2);
|
||||
expect(avatarUrlForRoom(room, 128, 256, "crop")).toEqual(
|
||||
mediaFromMxc(avatarUrl2).getThumbnailOfSourceHttp(128, 256, "crop"),
|
||||
);
|
||||
getThumbnailOfSourceHttp.mockReturnValue(avatarUrl2);
|
||||
expect(avatarUrlForRoom(room, 128, 256, "crop")).toEqual(avatarUrl2);
|
||||
expect(getThumbnailOfSourceHttp).toHaveBeenCalledWith(128, 256, "crop");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -20,16 +20,22 @@ exports[`RoomView for a local room in state CREATING should match the snapshot 1
|
|||
<span
|
||||
class="mx_BaseAvatar"
|
||||
role="presentation"
|
||||
style="width: 24px; height: 24px;"
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image mx_BaseAvatar_initial"
|
||||
data-testid="avatar-img"
|
||||
style="background-color: rgb(172, 59, 168); width: 24px; height: 24px; font-size: 15.600000000000001px; line-height: 24px;"
|
||||
class="mx_BaseAvatar_initial"
|
||||
style="font-size: 15.600000000000001px; width: 24px; line-height: 24px;"
|
||||
>
|
||||
U
|
||||
</span>
|
||||
<img
|
||||
alt=""
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image"
|
||||
data-testid="avatar-img"
|
||||
src="data:image/png;base64,00"
|
||||
style="width: 24px; height: 24px;"
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -113,16 +119,22 @@ exports[`RoomView for a local room in state ERROR should match the snapshot 1`]
|
|||
<span
|
||||
class="mx_BaseAvatar"
|
||||
role="presentation"
|
||||
style="width: 24px; height: 24px;"
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image mx_BaseAvatar_initial"
|
||||
data-testid="avatar-img"
|
||||
style="background-color: rgb(172, 59, 168); width: 24px; height: 24px; font-size: 15.600000000000001px; line-height: 24px;"
|
||||
class="mx_BaseAvatar_initial"
|
||||
style="font-size: 15.600000000000001px; width: 24px; line-height: 24px;"
|
||||
>
|
||||
U
|
||||
</span>
|
||||
<img
|
||||
alt=""
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image"
|
||||
data-testid="avatar-img"
|
||||
src="data:image/png;base64,00"
|
||||
style="width: 24px; height: 24px;"
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -203,17 +215,23 @@ exports[`RoomView for a local room in state ERROR should match the snapshot 1`]
|
|||
aria-live="off"
|
||||
class="mx_AccessibleButton mx_BaseAvatar"
|
||||
role="button"
|
||||
style="width: 52px; height: 52px;"
|
||||
tabindex="0"
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image mx_BaseAvatar_initial"
|
||||
data-testid="avatar-img"
|
||||
style="background-color: rgb(172, 59, 168); width: 52px; height: 52px; font-size: 33.800000000000004px; line-height: 52px;"
|
||||
class="mx_BaseAvatar_initial"
|
||||
style="font-size: 33.800000000000004px; width: 52px; line-height: 52px;"
|
||||
>
|
||||
U
|
||||
</span>
|
||||
<img
|
||||
alt=""
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image"
|
||||
data-testid="avatar-img"
|
||||
src="data:image/png;base64,00"
|
||||
style="width: 52px; height: 52px;"
|
||||
/>
|
||||
</span>
|
||||
<h2>
|
||||
@user:example.com
|
||||
|
@ -296,16 +314,22 @@ exports[`RoomView for a local room in state NEW should match the snapshot 1`] =
|
|||
<span
|
||||
class="mx_BaseAvatar"
|
||||
role="presentation"
|
||||
style="width: 24px; height: 24px;"
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image mx_BaseAvatar_initial"
|
||||
data-testid="avatar-img"
|
||||
style="background-color: rgb(172, 59, 168); width: 24px; height: 24px; font-size: 15.600000000000001px; line-height: 24px;"
|
||||
class="mx_BaseAvatar_initial"
|
||||
style="font-size: 15.600000000000001px; width: 24px; line-height: 24px;"
|
||||
>
|
||||
U
|
||||
</span>
|
||||
<img
|
||||
alt=""
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image"
|
||||
data-testid="avatar-img"
|
||||
src="data:image/png;base64,00"
|
||||
style="width: 24px; height: 24px;"
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -386,17 +410,23 @@ exports[`RoomView for a local room in state NEW should match the snapshot 1`] =
|
|||
aria-live="off"
|
||||
class="mx_AccessibleButton mx_BaseAvatar"
|
||||
role="button"
|
||||
style="width: 52px; height: 52px;"
|
||||
tabindex="0"
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image mx_BaseAvatar_initial"
|
||||
data-testid="avatar-img"
|
||||
style="background-color: rgb(172, 59, 168); width: 52px; height: 52px; font-size: 33.800000000000004px; line-height: 52px;"
|
||||
class="mx_BaseAvatar_initial"
|
||||
style="font-size: 33.800000000000004px; width: 52px; line-height: 52px;"
|
||||
>
|
||||
U
|
||||
</span>
|
||||
<img
|
||||
alt=""
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image"
|
||||
data-testid="avatar-img"
|
||||
src="data:image/png;base64,00"
|
||||
style="width: 52px; height: 52px;"
|
||||
/>
|
||||
</span>
|
||||
<h2>
|
||||
@user:example.com
|
||||
|
@ -551,16 +581,22 @@ exports[`RoomView for a local room in state NEW that is encrypted should match t
|
|||
<span
|
||||
class="mx_BaseAvatar"
|
||||
role="presentation"
|
||||
style="width: 24px; height: 24px;"
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image mx_BaseAvatar_initial"
|
||||
data-testid="avatar-img"
|
||||
style="background-color: rgb(172, 59, 168); width: 24px; height: 24px; font-size: 15.600000000000001px; line-height: 24px;"
|
||||
class="mx_BaseAvatar_initial"
|
||||
style="font-size: 15.600000000000001px; width: 24px; line-height: 24px;"
|
||||
>
|
||||
U
|
||||
</span>
|
||||
<img
|
||||
alt=""
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image"
|
||||
data-testid="avatar-img"
|
||||
src="data:image/png;base64,00"
|
||||
style="width: 24px; height: 24px;"
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -636,17 +672,23 @@ exports[`RoomView for a local room in state NEW that is encrypted should match t
|
|||
aria-live="off"
|
||||
class="mx_AccessibleButton mx_BaseAvatar"
|
||||
role="button"
|
||||
style="width: 52px; height: 52px;"
|
||||
tabindex="0"
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image mx_BaseAvatar_initial"
|
||||
data-testid="avatar-img"
|
||||
style="background-color: rgb(172, 59, 168); width: 52px; height: 52px; font-size: 33.800000000000004px; line-height: 52px;"
|
||||
class="mx_BaseAvatar_initial"
|
||||
style="font-size: 33.800000000000004px; width: 52px; line-height: 52px;"
|
||||
>
|
||||
U
|
||||
</span>
|
||||
<img
|
||||
alt=""
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image"
|
||||
data-testid="avatar-img"
|
||||
src="data:image/png;base64,00"
|
||||
style="width: 52px; height: 52px;"
|
||||
/>
|
||||
</span>
|
||||
<h2>
|
||||
@user:example.com
|
||||
|
|
|
@ -20,16 +20,22 @@ exports[`<UserMenu> when rendered should render as expected 1`] = `
|
|||
<span
|
||||
class="mx_BaseAvatar mx_UserMenu_userAvatar_BaseAvatar"
|
||||
role="presentation"
|
||||
style="width: 32px; height: 32px;"
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image mx_BaseAvatar_initial"
|
||||
data-testid="avatar-img"
|
||||
style="background-color: rgb(54, 139, 214); width: 32px; height: 32px; font-size: 20.8px; line-height: 32px;"
|
||||
class="mx_BaseAvatar_initial"
|
||||
style="font-size: 20.8px; width: 32px; line-height: 32px;"
|
||||
>
|
||||
U
|
||||
</span>
|
||||
<img
|
||||
alt=""
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image"
|
||||
data-testid="avatar-img"
|
||||
src="data:image/png;base64,00"
|
||||
style="width: 32px; height: 32px;"
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,201 +0,0 @@
|
|||
/*
|
||||
Copyright 2023 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, render } from "@testing-library/react";
|
||||
import { ClientEvent, PendingEventOrdering } from "matrix-js-sdk/src/client";
|
||||
import { Room } from "matrix-js-sdk/src/models/room";
|
||||
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
|
||||
import React from "react";
|
||||
import { act } from "react-dom/test-utils";
|
||||
import { SyncState } from "matrix-js-sdk/src/sync";
|
||||
|
||||
import type { MatrixClient } from "matrix-js-sdk/src/client";
|
||||
import RoomContext from "../../../../src/contexts/RoomContext";
|
||||
import { getRoomContext } from "../../../test-utils/room";
|
||||
import { stubClient } from "../../../test-utils/test-utils";
|
||||
import BaseAvatar from "../../../../src/components/views/avatars/BaseAvatar";
|
||||
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
|
||||
|
||||
type Props = React.ComponentPropsWithoutRef<typeof BaseAvatar>;
|
||||
|
||||
describe("<BaseAvatar />", () => {
|
||||
let client: MatrixClient;
|
||||
let room: Room;
|
||||
let member: RoomMember;
|
||||
|
||||
function getComponent(props: Partial<Props>) {
|
||||
return (
|
||||
<MatrixClientContext.Provider value={client}>
|
||||
<RoomContext.Provider value={getRoomContext(room, {})}>
|
||||
<BaseAvatar name="" {...props} />
|
||||
</RoomContext.Provider>
|
||||
</MatrixClientContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
function failLoadingImg(container: HTMLElement): void {
|
||||
const img = container.querySelector<HTMLImageElement>("img")!;
|
||||
expect(img).not.toBeNull();
|
||||
act(() => {
|
||||
fireEvent.error(img);
|
||||
});
|
||||
}
|
||||
|
||||
function emitReconnect(): void {
|
||||
act(() => {
|
||||
client.emit(ClientEvent.Sync, SyncState.Prepared, SyncState.Reconnecting);
|
||||
});
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
client = stubClient();
|
||||
|
||||
room = new Room("!room:example.com", client, client.getUserId() ?? "", {
|
||||
pendingEventOrdering: PendingEventOrdering.Detached,
|
||||
});
|
||||
|
||||
member = new RoomMember(room.roomId, "@bob:example.org");
|
||||
jest.spyOn(room, "getMember").mockReturnValue(member);
|
||||
});
|
||||
|
||||
it("renders with minimal properties", () => {
|
||||
const { container } = render(getComponent({}));
|
||||
|
||||
expect(container.querySelector(".mx_BaseAvatar")).not.toBeNull();
|
||||
});
|
||||
|
||||
it("matches snapshot (avatar)", () => {
|
||||
const { container } = render(
|
||||
getComponent({
|
||||
name: "CoolUser22",
|
||||
title: "Hover title",
|
||||
url: "https://example.com/images/avatar.gif",
|
||||
className: "mx_SomethingArbitrary",
|
||||
}),
|
||||
);
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("matches snapshot (avatar + click)", () => {
|
||||
const { container } = render(
|
||||
getComponent({
|
||||
name: "CoolUser22",
|
||||
title: "Hover title",
|
||||
url: "https://example.com/images/avatar.gif",
|
||||
className: "mx_SomethingArbitrary",
|
||||
onClick: () => {},
|
||||
}),
|
||||
);
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("matches snapshot (no avatar)", () => {
|
||||
const { container } = render(
|
||||
getComponent({
|
||||
name: "xX_Element_User_Xx",
|
||||
title: ":kiss:",
|
||||
defaultToInitialLetter: true,
|
||||
className: "big-and-bold",
|
||||
}),
|
||||
);
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("matches snapshot (no avatar + click)", () => {
|
||||
const { container } = render(
|
||||
getComponent({
|
||||
name: "xX_Element_User_Xx",
|
||||
title: ":kiss:",
|
||||
defaultToInitialLetter: true,
|
||||
className: "big-and-bold",
|
||||
onClick: () => {},
|
||||
}),
|
||||
);
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("uses fallback images", () => {
|
||||
const images = [...Array(10)].map((_, i) => `https://example.com/images/${i}.webp`);
|
||||
|
||||
const { container } = render(
|
||||
getComponent({
|
||||
url: images[0],
|
||||
urls: images.slice(1),
|
||||
}),
|
||||
);
|
||||
|
||||
for (const image of images) {
|
||||
expect(container.querySelector("img")!.src).toBe(image);
|
||||
failLoadingImg(container);
|
||||
}
|
||||
});
|
||||
|
||||
it("re-renders on reconnect", () => {
|
||||
const primary = "https://example.com/image.jpeg";
|
||||
const fallback = "https://example.com/fallback.png";
|
||||
const { container } = render(
|
||||
getComponent({
|
||||
url: primary,
|
||||
urls: [fallback],
|
||||
}),
|
||||
);
|
||||
|
||||
failLoadingImg(container);
|
||||
expect(container.querySelector("img")!.src).toBe(fallback);
|
||||
|
||||
emitReconnect();
|
||||
expect(container.querySelector("img")!.src).toBe(primary);
|
||||
});
|
||||
|
||||
it("renders with an image", () => {
|
||||
const url = "https://example.com/images/small/avatar.gif?size=realBig";
|
||||
const { container } = render(getComponent({ url }));
|
||||
|
||||
const img = container.querySelector("img");
|
||||
expect(img!.src).toBe(url);
|
||||
});
|
||||
|
||||
it("renders the initial letter", () => {
|
||||
const { container } = render(getComponent({ name: "Yellow", defaultToInitialLetter: true }));
|
||||
|
||||
const avatar = container.querySelector<HTMLSpanElement>(".mx_BaseAvatar_initial")!;
|
||||
expect(avatar.innerHTML).toBe("Y");
|
||||
});
|
||||
|
||||
it.each([{}, { name: "CoolUser22" }, { name: "XxElement_FanxX", defaultToInitialLetter: true }])(
|
||||
"includes a click handler",
|
||||
(props: Partial<Props>) => {
|
||||
const onClick = jest.fn();
|
||||
|
||||
const { container } = render(
|
||||
getComponent({
|
||||
...props,
|
||||
onClick,
|
||||
}),
|
||||
);
|
||||
|
||||
act(() => {
|
||||
fireEvent.click(container.querySelector(".mx_BaseAvatar")!);
|
||||
});
|
||||
|
||||
expect(onClick).toHaveBeenCalled();
|
||||
},
|
||||
);
|
||||
});
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2022 - 2023 The Matrix.org Foundation C.I.C.
|
||||
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.
|
||||
|
@ -14,25 +14,19 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { fireEvent, getByTestId, render } from "@testing-library/react";
|
||||
import { getByTestId, render, waitFor } from "@testing-library/react";
|
||||
import { mocked } from "jest-mock";
|
||||
import { MatrixClient, PendingEventOrdering } from "matrix-js-sdk/src/client";
|
||||
import { Room } from "matrix-js-sdk/src/models/room";
|
||||
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
|
||||
import React from "react";
|
||||
import { act } from "react-dom/test-utils";
|
||||
|
||||
import MemberAvatar from "../../../../src/components/views/avatars/MemberAvatar";
|
||||
import RoomContext from "../../../../src/contexts/RoomContext";
|
||||
import { mediaFromMxc } from "../../../../src/customisations/Media";
|
||||
import { ViewUserPayload } from "../../../../src/dispatcher/payloads/ViewUserPayload";
|
||||
import defaultDispatcher from "../../../../src/dispatcher/dispatcher";
|
||||
import { SettingLevel } from "../../../../src/settings/SettingLevel";
|
||||
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
||||
import SettingsStore from "../../../../src/settings/SettingsStore";
|
||||
import { getRoomContext } from "../../../test-utils/room";
|
||||
import { stubClient } from "../../../test-utils/test-utils";
|
||||
import { Action } from "../../../../src/dispatcher/actions";
|
||||
|
||||
type Props = React.ComponentPropsWithoutRef<typeof MemberAvatar>;
|
||||
|
||||
describe("MemberAvatar", () => {
|
||||
const ROOM_ID = "roomId";
|
||||
|
@ -41,7 +35,7 @@ describe("MemberAvatar", () => {
|
|||
let room: Room;
|
||||
let member: RoomMember;
|
||||
|
||||
function getComponent(props: Partial<Props>) {
|
||||
function getComponent(props) {
|
||||
return (
|
||||
<RoomContext.Provider value={getRoomContext(room, {})}>
|
||||
<MemberAvatar member={null} width={35} height={35} {...props} />
|
||||
|
@ -50,7 +44,10 @@ describe("MemberAvatar", () => {
|
|||
}
|
||||
|
||||
beforeEach(() => {
|
||||
mockClient = stubClient();
|
||||
jest.clearAllMocks();
|
||||
|
||||
stubClient();
|
||||
mockClient = mocked(MatrixClientPeg.get());
|
||||
|
||||
room = new Room(ROOM_ID, mockClient, mockClient.getUserId() ?? "", {
|
||||
pendingEventOrdering: PendingEventOrdering.Detached,
|
||||
|
@ -58,77 +55,22 @@ describe("MemberAvatar", () => {
|
|||
|
||||
member = new RoomMember(ROOM_ID, "@bob:example.org");
|
||||
jest.spyOn(room, "getMember").mockReturnValue(member);
|
||||
});
|
||||
|
||||
it("supports 'null' members", () => {
|
||||
const { container } = render(getComponent({ member: null }));
|
||||
|
||||
expect(container.querySelector("img")).not.toBeNull();
|
||||
});
|
||||
|
||||
it("matches the snapshot", () => {
|
||||
jest.spyOn(member, "getMxcAvatarUrl").mockReturnValue("http://placekitten.com/400/400");
|
||||
const { container } = render(
|
||||
getComponent({
|
||||
member,
|
||||
fallbackUserId: "Fallback User ID",
|
||||
title: "Hover title",
|
||||
style: {
|
||||
color: "pink",
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("shows an avatar for useOnlyCurrentProfiles", () => {
|
||||
jest.spyOn(member, "getMxcAvatarUrl").mockReturnValue("http://placekitten.com/400/400");
|
||||
|
||||
SettingsStore.setValue("useOnlyCurrentProfiles", null, SettingLevel.DEVICE, true);
|
||||
it("shows an avatar for useOnlyCurrentProfiles", async () => {
|
||||
jest.spyOn(SettingsStore, "getValue").mockImplementation((settingName: string) => {
|
||||
return settingName === "useOnlyCurrentProfiles";
|
||||
});
|
||||
|
||||
const { container } = render(getComponent({}));
|
||||
|
||||
const avatar = getByTestId<HTMLImageElement>(container, "avatar-img");
|
||||
expect(avatar).toBeInTheDocument();
|
||||
expect(avatar.getAttribute("src")).not.toBe("");
|
||||
});
|
||||
|
||||
it("uses the member's configured avatar", () => {
|
||||
const mxcUrl = "mxc://example.com/avatars/user.tiff";
|
||||
jest.spyOn(member, "getMxcAvatarUrl").mockReturnValue(mxcUrl);
|
||||
|
||||
const { container } = render(getComponent({ member }));
|
||||
|
||||
const img = container.querySelector("img");
|
||||
expect(img).not.toBeNull();
|
||||
expect(img!.src).toBe(mediaFromMxc(mxcUrl).srcHttp);
|
||||
});
|
||||
|
||||
it("uses a fallback when the member has no avatar", () => {
|
||||
jest.spyOn(member, "getMxcAvatarUrl").mockReturnValue(undefined);
|
||||
|
||||
const { container } = render(getComponent({ member }));
|
||||
|
||||
const img = container.querySelector(".mx_BaseAvatar_image");
|
||||
expect(img).not.toBeNull();
|
||||
});
|
||||
|
||||
it("dispatches on click", () => {
|
||||
const { container } = render(getComponent({ member, viewUserOnClick: true }));
|
||||
|
||||
const spy = jest.spyOn(defaultDispatcher, "dispatch");
|
||||
|
||||
act(() => {
|
||||
fireEvent.click(container.querySelector(".mx_BaseAvatar")!);
|
||||
let avatar: HTMLElement;
|
||||
await waitFor(() => {
|
||||
avatar = getByTestId(container, "avatar-img");
|
||||
expect(avatar).toBeInTheDocument();
|
||||
});
|
||||
|
||||
expect(spy).toHaveBeenCalled();
|
||||
const [payload] = spy.mock.lastCall!;
|
||||
expect(payload).toStrictEqual<ViewUserPayload>({
|
||||
action: Action.ViewUser,
|
||||
member,
|
||||
push: false,
|
||||
});
|
||||
expect(avatar!.getAttribute("src")).not.toBe("");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -39,7 +39,7 @@ describe("RoomAvatar", () => {
|
|||
const dmRoomMap = new DMRoomMap(client);
|
||||
jest.spyOn(dmRoomMap, "getUserIdForRoomId");
|
||||
jest.spyOn(DMRoomMap, "shared").mockReturnValue(dmRoomMap);
|
||||
jest.spyOn(AvatarModule, "getColorForString");
|
||||
jest.spyOn(AvatarModule, "defaultAvatarUrlForString");
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
|
@ -48,14 +48,14 @@ describe("RoomAvatar", () => {
|
|||
|
||||
afterEach(() => {
|
||||
mocked(DMRoomMap.shared().getUserIdForRoomId).mockReset();
|
||||
mocked(AvatarModule.getColorForString).mockClear();
|
||||
mocked(AvatarModule.defaultAvatarUrlForString).mockClear();
|
||||
});
|
||||
|
||||
it("should render as expected for a Room", () => {
|
||||
const room = new Room("!room:example.com", client, client.getSafeUserId());
|
||||
room.name = "test room";
|
||||
expect(render(<RoomAvatar room={room} />).container).toMatchSnapshot();
|
||||
expect(AvatarModule.getColorForString).toHaveBeenCalledWith(room.roomId);
|
||||
expect(AvatarModule.defaultAvatarUrlForString).toHaveBeenCalledWith(room.roomId);
|
||||
});
|
||||
|
||||
it("should render as expected for a DM room", () => {
|
||||
|
@ -64,7 +64,7 @@ describe("RoomAvatar", () => {
|
|||
room.name = "DM room";
|
||||
mocked(DMRoomMap.shared().getUserIdForRoomId).mockReturnValue(userId);
|
||||
expect(render(<RoomAvatar room={room} />).container).toMatchSnapshot();
|
||||
expect(AvatarModule.getColorForString).toHaveBeenCalledWith(userId);
|
||||
expect(AvatarModule.defaultAvatarUrlForString).toHaveBeenCalledWith(userId);
|
||||
});
|
||||
|
||||
it("should render as expected for a LocalRoom", () => {
|
||||
|
@ -73,6 +73,6 @@ describe("RoomAvatar", () => {
|
|||
localRoom.name = "local test room";
|
||||
localRoom.targets.push(new DirectoryMember({ user_id: userId }));
|
||||
expect(render(<RoomAvatar room={localRoom} />).container).toMatchSnapshot();
|
||||
expect(AvatarModule.getColorForString).toHaveBeenCalledWith(userId);
|
||||
expect(AvatarModule.defaultAvatarUrlForString).toHaveBeenCalledWith(userId);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,72 +0,0 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`<BaseAvatar /> matches snapshot (avatar + click) 1`] = `
|
||||
<div>
|
||||
<img
|
||||
alt="Avatar"
|
||||
class="mx_AccessibleButton mx_BaseAvatar mx_BaseAvatar_image mx_SomethingArbitrary"
|
||||
data-testid="avatar-img"
|
||||
role="button"
|
||||
src="https://example.com/images/avatar.gif"
|
||||
style="width: 40px; height: 40px;"
|
||||
tabindex="0"
|
||||
title="Hover title"
|
||||
/>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`<BaseAvatar /> matches snapshot (avatar) 1`] = `
|
||||
<div>
|
||||
<img
|
||||
alt=""
|
||||
class="mx_BaseAvatar mx_BaseAvatar_image mx_SomethingArbitrary"
|
||||
data-testid="avatar-img"
|
||||
src="https://example.com/images/avatar.gif"
|
||||
style="width: 40px; height: 40px;"
|
||||
title="Hover title"
|
||||
/>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`<BaseAvatar /> matches snapshot (no avatar + click) 1`] = `
|
||||
<div>
|
||||
<span
|
||||
aria-label="Avatar"
|
||||
aria-live="off"
|
||||
class="mx_AccessibleButton mx_BaseAvatar big-and-bold"
|
||||
role="button"
|
||||
style="width: 40px; height: 40px;"
|
||||
tabindex="0"
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image mx_BaseAvatar_initial"
|
||||
data-testid="avatar-img"
|
||||
style="background-color: rgb(13, 189, 139); width: 40px; height: 40px; font-size: 26px; line-height: 40px;"
|
||||
title=":kiss:"
|
||||
>
|
||||
X
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`<BaseAvatar /> matches snapshot (no avatar) 1`] = `
|
||||
<div>
|
||||
<span
|
||||
class="mx_BaseAvatar big-and-bold"
|
||||
role="presentation"
|
||||
style="width: 40px; height: 40px;"
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image mx_BaseAvatar_initial"
|
||||
data-testid="avatar-img"
|
||||
style="background-color: rgb(13, 189, 139); width: 40px; height: 40px; font-size: 26px; line-height: 40px;"
|
||||
title=":kiss:"
|
||||
>
|
||||
X
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
`;
|
|
@ -1,14 +0,0 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`MemberAvatar matches the snapshot 1`] = `
|
||||
<div>
|
||||
<img
|
||||
alt=""
|
||||
class="mx_BaseAvatar mx_BaseAvatar_image"
|
||||
data-testid="avatar-img"
|
||||
src="http://this.is.a.url//placekitten.com/400/400"
|
||||
style="color: pink; width: 35px; height: 35px;"
|
||||
title="Hover title"
|
||||
/>
|
||||
</div>
|
||||
`;
|
|
@ -5,16 +5,22 @@ exports[`RoomAvatar should render as expected for a DM room 1`] = `
|
|||
<span
|
||||
class="mx_BaseAvatar"
|
||||
role="presentation"
|
||||
style="width: 36px; height: 36px;"
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image mx_BaseAvatar_initial"
|
||||
data-testid="avatar-img"
|
||||
style="background-color: rgb(13, 189, 139); width: 36px; height: 36px; font-size: 23.400000000000002px; line-height: 36px;"
|
||||
class="mx_BaseAvatar_initial"
|
||||
style="font-size: 23.400000000000002px; width: 36px; line-height: 36px;"
|
||||
>
|
||||
D
|
||||
</span>
|
||||
<img
|
||||
alt=""
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image"
|
||||
data-testid="avatar-img"
|
||||
src="data:image/png;base64,00"
|
||||
style="width: 36px; height: 36px;"
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
`;
|
||||
|
@ -24,16 +30,22 @@ exports[`RoomAvatar should render as expected for a LocalRoom 1`] = `
|
|||
<span
|
||||
class="mx_BaseAvatar"
|
||||
role="presentation"
|
||||
style="width: 36px; height: 36px;"
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image mx_BaseAvatar_initial"
|
||||
data-testid="avatar-img"
|
||||
style="background-color: rgb(172, 59, 168); width: 36px; height: 36px; font-size: 23.400000000000002px; line-height: 36px;"
|
||||
class="mx_BaseAvatar_initial"
|
||||
style="font-size: 23.400000000000002px; width: 36px; line-height: 36px;"
|
||||
>
|
||||
L
|
||||
</span>
|
||||
<img
|
||||
alt=""
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image"
|
||||
data-testid="avatar-img"
|
||||
src="data:image/png;base64,00"
|
||||
style="width: 36px; height: 36px;"
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
`;
|
||||
|
@ -43,16 +55,22 @@ exports[`RoomAvatar should render as expected for a Room 1`] = `
|
|||
<span
|
||||
class="mx_BaseAvatar"
|
||||
role="presentation"
|
||||
style="width: 36px; height: 36px;"
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image mx_BaseAvatar_initial"
|
||||
data-testid="avatar-img"
|
||||
style="background-color: rgb(172, 59, 168); width: 36px; height: 36px; font-size: 23.400000000000002px; line-height: 36px;"
|
||||
class="mx_BaseAvatar_initial"
|
||||
style="font-size: 23.400000000000002px; width: 36px; line-height: 36px;"
|
||||
>
|
||||
T
|
||||
</span>
|
||||
<img
|
||||
alt=""
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image"
|
||||
data-testid="avatar-img"
|
||||
src="data:image/png;base64,00"
|
||||
style="width: 36px; height: 36px;"
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
`;
|
||||
|
|
|
@ -13,17 +13,23 @@ exports[`<BeaconMarker /> renders marker when beacon has location 1`] = `
|
|||
<span
|
||||
class="mx_BaseAvatar"
|
||||
role="presentation"
|
||||
style="width: 36px; height: 36px;"
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image mx_BaseAvatar_initial"
|
||||
data-testid="avatar-img"
|
||||
style="background-color: rgb(172, 59, 168); width: 36px; height: 36px; font-size: 23.400000000000002px; line-height: 36px;"
|
||||
title="@alice:server"
|
||||
class="mx_BaseAvatar_initial"
|
||||
style="font-size: 23.400000000000002px; width: 36px; line-height: 36px;"
|
||||
>
|
||||
A
|
||||
</span>
|
||||
<img
|
||||
alt=""
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image"
|
||||
data-testid="avatar-img"
|
||||
src="data:image/png;base64,00"
|
||||
style="width: 36px; height: 36px;"
|
||||
title="@alice:server"
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -22,16 +22,22 @@ exports[`<RoomSummaryCard /> renders the room summary 1`] = `
|
|||
<span
|
||||
class="mx_BaseAvatar"
|
||||
role="presentation"
|
||||
style="width: 54px; height: 54px;"
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image mx_BaseAvatar_initial"
|
||||
data-testid="avatar-img"
|
||||
style="background-color: rgb(13, 189, 139); width: 54px; height: 54px; font-size: 35.1px; line-height: 54px;"
|
||||
class="mx_BaseAvatar_initial"
|
||||
style="font-size: 35.1px; width: 54px; line-height: 54px;"
|
||||
>
|
||||
!
|
||||
</span>
|
||||
<img
|
||||
alt=""
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image"
|
||||
data-testid="avatar-img"
|
||||
src="data:image/png;base64,00"
|
||||
style="width: 54px; height: 54px;"
|
||||
/>
|
||||
</span>
|
||||
<div
|
||||
class="mx_TextWithTooltip_target mx_RoomSummaryCard_e2ee"
|
||||
|
|
|
@ -72,7 +72,7 @@ describe("RoomHeader (Enzyme)", () => {
|
|||
|
||||
// And there is no image avatar (because it's not set on this room)
|
||||
const image = findImg(rendered, ".mx_BaseAvatar_image");
|
||||
expect(image).toBeTruthy();
|
||||
expect(image.prop("src")).toEqual("data:image/png;base64,00");
|
||||
});
|
||||
|
||||
it("shows the room avatar in a room with 2 people", () => {
|
||||
|
@ -86,7 +86,7 @@ describe("RoomHeader (Enzyme)", () => {
|
|||
|
||||
// And there is no image avatar (because it's not set on this room)
|
||||
const image = findImg(rendered, ".mx_BaseAvatar_image");
|
||||
expect(image).toBeTruthy();
|
||||
expect(image.prop("src")).toEqual("data:image/png;base64,00");
|
||||
});
|
||||
|
||||
it("shows the room avatar in a room with >2 people", () => {
|
||||
|
@ -100,7 +100,7 @@ describe("RoomHeader (Enzyme)", () => {
|
|||
|
||||
// And there is no image avatar (because it's not set on this room)
|
||||
const image = findImg(rendered, ".mx_BaseAvatar_image");
|
||||
expect(image).toBeTruthy();
|
||||
expect(image.prop("src")).toEqual("data:image/png;base64,00");
|
||||
});
|
||||
|
||||
it("shows the room avatar in a DM with only ourselves", () => {
|
||||
|
@ -114,7 +114,7 @@ describe("RoomHeader (Enzyme)", () => {
|
|||
|
||||
// And there is no image avatar (because it's not set on this room)
|
||||
const image = findImg(rendered, ".mx_BaseAvatar_image");
|
||||
expect(image).toBeTruthy();
|
||||
expect(image.prop("src")).toEqual("data:image/png;base64,00");
|
||||
});
|
||||
|
||||
it("shows the user avatar in a DM with 2 people", () => {
|
||||
|
@ -148,7 +148,7 @@ describe("RoomHeader (Enzyme)", () => {
|
|||
|
||||
// And there is no image avatar (because it's not set on this room)
|
||||
const image = findImg(rendered, ".mx_BaseAvatar_image");
|
||||
expect(image).toBeTruthy();
|
||||
expect(image.prop("src")).toEqual("data:image/png;base64,00");
|
||||
});
|
||||
|
||||
it("renders call buttons normally", () => {
|
||||
|
|
|
@ -161,16 +161,22 @@ exports[`<RoomPreviewBar /> with an invite without an invited email for a dm roo
|
|||
<span
|
||||
class="mx_BaseAvatar"
|
||||
role="presentation"
|
||||
style="width: 36px; height: 36px;"
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image mx_BaseAvatar_initial"
|
||||
data-testid="avatar-img"
|
||||
style="background-color: rgb(172, 59, 168); width: 36px; height: 36px; font-size: 23.400000000000002px; line-height: 36px;"
|
||||
class="mx_BaseAvatar_initial"
|
||||
style="font-size: 23.400000000000002px; width: 36px; line-height: 36px;"
|
||||
>
|
||||
R
|
||||
</span>
|
||||
<img
|
||||
alt=""
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image"
|
||||
data-testid="avatar-img"
|
||||
src="data:image/png;base64,00"
|
||||
style="width: 36px; height: 36px;"
|
||||
/>
|
||||
</span>
|
||||
</p>
|
||||
<p>
|
||||
|
@ -230,16 +236,22 @@ exports[`<RoomPreviewBar /> with an invite without an invited email for a non-dm
|
|||
<span
|
||||
class="mx_BaseAvatar"
|
||||
role="presentation"
|
||||
style="width: 36px; height: 36px;"
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image mx_BaseAvatar_initial"
|
||||
data-testid="avatar-img"
|
||||
style="background-color: rgb(172, 59, 168); width: 36px; height: 36px; font-size: 23.400000000000002px; line-height: 36px;"
|
||||
class="mx_BaseAvatar_initial"
|
||||
style="font-size: 23.400000000000002px; width: 36px; line-height: 36px;"
|
||||
>
|
||||
R
|
||||
</span>
|
||||
<img
|
||||
alt=""
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image"
|
||||
data-testid="avatar-img"
|
||||
src="data:image/png;base64,00"
|
||||
style="width: 36px; height: 36px;"
|
||||
/>
|
||||
</span>
|
||||
</p>
|
||||
<p>
|
||||
|
|
|
@ -15,16 +15,22 @@ exports[`RoomTile should render the room 1`] = `
|
|||
<span
|
||||
class="mx_BaseAvatar"
|
||||
role="presentation"
|
||||
style="width: 32px; height: 32px;"
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image mx_BaseAvatar_initial"
|
||||
data-testid="avatar-img"
|
||||
style="background-color: rgb(172, 59, 168); width: 32px; height: 32px; font-size: 20.8px; line-height: 32px;"
|
||||
class="mx_BaseAvatar_initial"
|
||||
style="font-size: 20.8px; width: 32px; line-height: 32px;"
|
||||
>
|
||||
!
|
||||
</span>
|
||||
<img
|
||||
alt=""
|
||||
aria-hidden="true"
|
||||
class="mx_BaseAvatar_image"
|
||||
data-testid="avatar-img"
|
||||
src="data:image/png;base64,00"
|
||||
style="width: 32px; height: 32px;"
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`RoomPillPart matches snapshot (avatar) 1`] = `
|
||||
<span
|
||||
class="mx_Pill mx_RoomPill"
|
||||
contenteditable="false"
|
||||
spellcheck="false"
|
||||
style="--avatar-background: url('http://this.is.a.url/www.example.com/avatars/room1.jpeg'); --avatar-letter: '';"
|
||||
>
|
||||
!room:example.com
|
||||
</span>
|
||||
`;
|
||||
|
||||
exports[`RoomPillPart matches snapshot (no avatar) 1`] = `
|
||||
<span
|
||||
class="mx_Pill mx_RoomPill"
|
||||
contenteditable="false"
|
||||
spellcheck="false"
|
||||
style="--avatar-background: #ac3ba8; --avatar-letter: '!';"
|
||||
>
|
||||
!room:example.com
|
||||
</span>
|
||||
`;
|
||||
|
||||
exports[`UserPillPart matches snapshot (avatar) 1`] = `
|
||||
<span
|
||||
class="mx_UserPill mx_Pill"
|
||||
contenteditable="false"
|
||||
spellcheck="false"
|
||||
style="--avatar-background: url('http://this.is.a.url/www.example.com/avatar.png'); --avatar-letter: '';"
|
||||
>
|
||||
DisplayName
|
||||
</span>
|
||||
`;
|
||||
|
||||
exports[`UserPillPart matches snapshot (no avatar) 1`] = `
|
||||
<span
|
||||
class="mx_UserPill mx_Pill"
|
||||
contenteditable="false"
|
||||
spellcheck="false"
|
||||
style="--avatar-background: #ac3ba8; --avatar-letter: 'U';"
|
||||
>
|
||||
DisplayName
|
||||
</span>
|
||||
`;
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2022 - 2023 The Matrix.org Foundation C.I.C.
|
||||
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.
|
||||
|
@ -14,11 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { MatrixClient, Room, RoomMember } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { EmojiPart, PartCreator, PlainPart } from "../../src/editor/parts";
|
||||
import DMRoomMap from "../../src/utils/DMRoomMap";
|
||||
import { stubClient } from "../test-utils";
|
||||
import { EmojiPart, PlainPart } from "../../src/editor/parts";
|
||||
import { createPartCreator } from "./mock";
|
||||
|
||||
describe("editor/parts", () => {
|
||||
|
@ -44,67 +40,3 @@ describe("editor/parts", () => {
|
|||
expect(() => part.toDOMNode()).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe("UserPillPart", () => {
|
||||
const roomId = "!room:example.com";
|
||||
let client: MatrixClient;
|
||||
let room: Room;
|
||||
let creator: PartCreator;
|
||||
|
||||
beforeEach(() => {
|
||||
client = stubClient();
|
||||
room = new Room(roomId, client, "@me:example.com");
|
||||
creator = new PartCreator(room, client);
|
||||
});
|
||||
|
||||
it("matches snapshot (no avatar)", () => {
|
||||
jest.spyOn(room, "getMember").mockReturnValue(new RoomMember(room.roomId, "@user:example.com"));
|
||||
const pill = creator.userPill("DisplayName", "@user:example.com");
|
||||
const el = pill.toDOMNode();
|
||||
|
||||
expect(el).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("matches snapshot (avatar)", () => {
|
||||
const member = new RoomMember(room.roomId, "@user:example.com");
|
||||
jest.spyOn(room, "getMember").mockReturnValue(member);
|
||||
jest.spyOn(member, "getMxcAvatarUrl").mockReturnValue("mxc://www.example.com/avatar.png");
|
||||
|
||||
const pill = creator.userPill("DisplayName", "@user:example.com");
|
||||
const el = pill.toDOMNode();
|
||||
|
||||
expect(el).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
describe("RoomPillPart", () => {
|
||||
const roomId = "!room:example.com";
|
||||
let client: jest.Mocked<MatrixClient>;
|
||||
let room: Room;
|
||||
let creator: PartCreator;
|
||||
|
||||
beforeEach(() => {
|
||||
client = stubClient() as jest.Mocked<MatrixClient>;
|
||||
DMRoomMap.makeShared();
|
||||
|
||||
room = new Room(roomId, client, "@me:example.com");
|
||||
client.getRoom.mockReturnValue(room);
|
||||
creator = new PartCreator(room, client);
|
||||
});
|
||||
|
||||
it("matches snapshot (no avatar)", () => {
|
||||
jest.spyOn(room, "getMxcAvatarUrl").mockReturnValue(null);
|
||||
const pill = creator.roomPill("super-secret clubhouse");
|
||||
const el = pill.toDOMNode();
|
||||
|
||||
expect(el).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("matches snapshot (avatar)", () => {
|
||||
jest.spyOn(room, "getMxcAvatarUrl").mockReturnValue("mxc://www.example.com/avatars/room1.jpeg");
|
||||
const pill = creator.roomPill("cool chat club");
|
||||
const el = pill.toDOMNode();
|
||||
|
||||
expect(el).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue