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

Commit 5e76adb

Browse files
Kerry Archibaldsandhose
authored andcommitted
test clientavatar
1 parent 0d726cd commit 5e76adb

File tree

3 files changed

+58
-10
lines changed

3 files changed

+58
-10
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2023 The Matrix.org Foundation C.I.C.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// @vitest-environment happy-dom
16+
17+
import { render, cleanup } from "@testing-library/react";
18+
import { describe, it, expect, afterEach } from "vitest";
19+
20+
import ClientAvatar from "./ClientAvatar";
21+
22+
describe("<ClientAvatar />", () => {
23+
const name = "Test Client";
24+
const logoUri = "https://www.testclient.com/logo.png";
25+
const size = "10px";
26+
27+
afterEach(cleanup);
28+
29+
it("renders client logo", () => {
30+
const { container } = render(
31+
<ClientAvatar name={name} logoUri={logoUri} size={size} />,
32+
);
33+
expect(container).toMatchSnapshot();
34+
});
35+
36+
it("renders nothing when no logoUri is falsy", () => {
37+
const { container } = render(<ClientAvatar name={name} size={size} />);
38+
expect(container).toMatchInlineSnapshot("<div />");
39+
});
40+
});

frontend/src/components/Session/ClientAvatar.tsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,21 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { Avatar } from "@vector-im/compound-web";
1615
import { CSSProperties } from "react";
1716

1817
import styles from "./ClientAvatar.module.css";
1918

19+
/**
20+
* Render a client logo avatar when logoUri is truthy
21+
* Otherwise return null
22+
*/
2023
const ClientAvatar: React.FC<{
2124
name: string;
2225
logoUri?: string;
23-
/**
24-
* Render a fallback avatar using client name when truthy
25-
* Otherwise return null when no logoUri
26-
*/
27-
withFallback?: boolean;
2826
size: string;
29-
}> = ({ name, logoUri, withFallback, size }) => {
27+
}> = ({ name, logoUri, size }) => {
3028
// compound's lazy loading for avatars does not allow CORS requests
29+
// so use our own avatar styled img
3130
if (logoUri) {
3231
return (
3332
<img
@@ -42,9 +41,6 @@ const ClientAvatar: React.FC<{
4241
/>
4342
);
4443
}
45-
if (withFallback) {
46-
return <Avatar size={size} id={name} name={name} src={logoUri} />;
47-
}
4844
return null;
4945
};
5046

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`<ClientAvatar /> > renders client logo 1`] = `
4+
<div>
5+
<img
6+
alt="Test Client"
7+
class="_avatar_39aee3"
8+
src="https://www.testclient.com/logo.png"
9+
style="--mas-avatar-size: 10px;"
10+
/>
11+
</div>
12+
`;

0 commit comments

Comments
 (0)