From 5e76adb325f1fabf8ba72a9562d2e96eb45aac82 Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Fri, 8 Sep 2023 13:38:03 +1200 Subject: [PATCH] test clientavatar --- .../components/Session/ClientAvatar.test.tsx | 40 +++++++++++++++++++ .../src/components/Session/ClientAvatar.tsx | 16 +++----- .../__snapshots__/ClientAvatar.test.tsx.snap | 12 ++++++ 3 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 frontend/src/components/Session/ClientAvatar.test.tsx create mode 100644 frontend/src/components/Session/__snapshots__/ClientAvatar.test.tsx.snap diff --git a/frontend/src/components/Session/ClientAvatar.test.tsx b/frontend/src/components/Session/ClientAvatar.test.tsx new file mode 100644 index 00000000..ad65e373 --- /dev/null +++ b/frontend/src/components/Session/ClientAvatar.test.tsx @@ -0,0 +1,40 @@ +// 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. + +// @vitest-environment happy-dom + +import { render, cleanup } from "@testing-library/react"; +import { describe, it, expect, afterEach } from "vitest"; + +import ClientAvatar from "./ClientAvatar"; + +describe("", () => { + const name = "Test Client"; + const logoUri = "https://www.testclient.com/logo.png"; + const size = "10px"; + + afterEach(cleanup); + + it("renders client logo", () => { + const { container } = render( + , + ); + expect(container).toMatchSnapshot(); + }); + + it("renders nothing when no logoUri is falsy", () => { + const { container } = render(); + expect(container).toMatchInlineSnapshot("
"); + }); +}); diff --git a/frontend/src/components/Session/ClientAvatar.tsx b/frontend/src/components/Session/ClientAvatar.tsx index 5172bee2..b5cd13e7 100644 --- a/frontend/src/components/Session/ClientAvatar.tsx +++ b/frontend/src/components/Session/ClientAvatar.tsx @@ -12,22 +12,21 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Avatar } from "@vector-im/compound-web"; import { CSSProperties } from "react"; import styles from "./ClientAvatar.module.css"; +/** + * Render a client logo avatar when logoUri is truthy + * Otherwise return null + */ const ClientAvatar: React.FC<{ name: string; logoUri?: string; - /** - * Render a fallback avatar using client name when truthy - * Otherwise return null when no logoUri - */ - withFallback?: boolean; size: string; -}> = ({ name, logoUri, withFallback, size }) => { +}> = ({ name, logoUri, size }) => { // compound's lazy loading for avatars does not allow CORS requests + // so use our own avatar styled img if (logoUri) { return ( ); } - if (withFallback) { - return ; - } return null; }; diff --git a/frontend/src/components/Session/__snapshots__/ClientAvatar.test.tsx.snap b/frontend/src/components/Session/__snapshots__/ClientAvatar.test.tsx.snap new file mode 100644 index 00000000..60e58da0 --- /dev/null +++ b/frontend/src/components/Session/__snapshots__/ClientAvatar.test.tsx.snap @@ -0,0 +1,12 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[` > renders client logo 1`] = ` +
+ Test Client +
+`;