From 01672ef64dda99d9efd6008c30b2aeb83165f243 Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Tue, 12 Sep 2023 10:35:35 +1200 Subject: [PATCH] test compatsessiondetail --- .../CompatSessionDetail.test.tsx | 79 +++++++ .../SessionDetail/CompatSessionDetail.tsx | 18 +- .../CompatSessionDetail.test.tsx.snap | 222 ++++++++++++++++++ 3 files changed, 309 insertions(+), 10 deletions(-) create mode 100644 frontend/src/components/SessionDetail/CompatSessionDetail.test.tsx create mode 100644 frontend/src/components/SessionDetail/__snapshots__/CompatSessionDetail.test.tsx.snap diff --git a/frontend/src/components/SessionDetail/CompatSessionDetail.test.tsx b/frontend/src/components/SessionDetail/CompatSessionDetail.test.tsx new file mode 100644 index 000000000..e1e40ba61 --- /dev/null +++ b/frontend/src/components/SessionDetail/CompatSessionDetail.test.tsx @@ -0,0 +1,79 @@ +// 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, expect, it, afterEach } from "vitest"; + +import { makeFragmentData } from "../../gql/fragment-masking"; +import { COMPAT_SESSION_FRAGMENT } from "../CompatSession"; + +import CompatSessionDetail from "./CompatSessionDetail"; + +describe("", () => { + const baseSession = { + id: "session-id", + deviceId: "abcd1234", + createdAt: "2023-06-29T03:35:17.451292+00:00", + ssoLogin: { + id: "test-id", + redirectUri: "https://element.io", + }, + }; + afterEach(cleanup); + + it("renders a compatability session details", () => { + const data = makeFragmentData(baseSession, COMPAT_SESSION_FRAGMENT); + + const { container } = render(); + + expect(container).toMatchSnapshot(); + }); + + it("renders a compatability session without an ssoLogin redirectUri", () => { + const data = makeFragmentData( + { + ...baseSession, + ssoLogin: { + id: "dfsdjfdk", + redirectUri: undefined, + }, + }, + COMPAT_SESSION_FRAGMENT, + ); + + const { container } = render(); + + expect(container).toMatchSnapshot(); + }); + + it("renders a finished compatability session details", () => { + const data = makeFragmentData( + { + ...baseSession, + finishedAt: "2023-07-29T03:35:17.451292+00:00", + }, + COMPAT_SESSION_FRAGMENT, + ); + + const { getByText, queryByText } = render( + , + ); + + expect(getByText("Finished")).toBeTruthy(); + // no end session button + expect(queryByText("End session")).toBeFalsy(); + }); +}); diff --git a/frontend/src/components/SessionDetail/CompatSessionDetail.tsx b/frontend/src/components/SessionDetail/CompatSessionDetail.tsx index fa1efde6d..df148dc53 100644 --- a/frontend/src/components/SessionDetail/CompatSessionDetail.tsx +++ b/frontend/src/components/SessionDetail/CompatSessionDetail.tsx @@ -68,16 +68,14 @@ const CompatSessionDetail: React.FC = ({ session }) => { } return ( -
- -

{data.deviceId || data.id}

- - {clientDetails.length > 0 ? ( - - ) : null} - {!data.finishedAt && } -
-
+ +

{data.deviceId || data.id}

+ + {clientDetails.length > 0 ? ( + + ) : null} + {!data.finishedAt && } +
); }; diff --git a/frontend/src/components/SessionDetail/__snapshots__/CompatSessionDetail.test.tsx.snap b/frontend/src/components/SessionDetail/__snapshots__/CompatSessionDetail.test.tsx.snap new file mode 100644 index 000000000..c04134140 --- /dev/null +++ b/frontend/src/components/SessionDetail/__snapshots__/CompatSessionDetail.test.tsx.snap @@ -0,0 +1,222 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[` > renders a compatability session details 1`] = ` +
+
+

+ abcd1234 +

+
+
+ Session +
+
    +
  • +

    + ID +

    +

    + + session-id + +

    +
  • +
  • +

    + Device ID +

    +

    + + abcd1234 + +

    +
  • +
  • +

    + Signed in +

    +

    + +

    +
  • +
+
+
+
+ Client +
+ +
+ +
+
+`; + +exports[` > renders a compatability session without an ssoLogin redirectUri 1`] = ` +
+
+

+ abcd1234 +

+
+
+ Session +
+
    +
  • +

    + ID +

    +

    + + session-id + +

    +
  • +
  • +

    + Device ID +

    +

    + + abcd1234 + +

    +
  • +
  • +

    + Signed in +

    +

    + +

    +
  • +
+
+ +
+
+`;