test compatsessiondetail
This commit is contained in:
committed by
Quentin Gliech
parent
7ede6e95b9
commit
01672ef64d
@@ -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("<SessionDetails>", () => {
|
||||
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(<CompatSessionDetail session={data} />);
|
||||
|
||||
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(<CompatSessionDetail session={data} />);
|
||||
|
||||
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(
|
||||
<CompatSessionDetail session={data} />,
|
||||
);
|
||||
|
||||
expect(getByText("Finished")).toBeTruthy();
|
||||
// no end session button
|
||||
expect(queryByText("End session")).toBeFalsy();
|
||||
});
|
||||
});
|
||||
@@ -68,16 +68,14 @@ const CompatSessionDetail: React.FC<Props> = ({ session }) => {
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<BlockList>
|
||||
<H3>{data.deviceId || data.id}</H3>
|
||||
<SessionDetails title="Session" details={sessionDetails} />
|
||||
{clientDetails.length > 0 ? (
|
||||
<SessionDetails title="Client" details={clientDetails} />
|
||||
) : null}
|
||||
{!data.finishedAt && <EndSessionButton endSession={onSessionEnd} />}
|
||||
</BlockList>
|
||||
</div>
|
||||
<BlockList>
|
||||
<H3>{data.deviceId || data.id}</H3>
|
||||
<SessionDetails title="Session" details={sessionDetails} />
|
||||
{clientDetails.length > 0 ? (
|
||||
<SessionDetails title="Client" details={clientDetails} />
|
||||
) : null}
|
||||
{!data.finishedAt && <EndSessionButton endSession={onSessionEnd} />}
|
||||
</BlockList>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,222 @@
|
||||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||
|
||||
exports[`<SessionDetails> > renders a compatability session details 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="_blockList_f8cc7f"
|
||||
>
|
||||
<h3
|
||||
class="_font-heading-md-semibold_1jx6b_121"
|
||||
>
|
||||
abcd1234
|
||||
</h3>
|
||||
<div
|
||||
class="_block_17898c"
|
||||
>
|
||||
<h6
|
||||
class="_font-body-md-semibold_1jx6b_64"
|
||||
>
|
||||
Session
|
||||
</h6>
|
||||
<ul
|
||||
class="_list_040867"
|
||||
>
|
||||
<li
|
||||
class="_detailRow_040867"
|
||||
>
|
||||
<p
|
||||
class="_font-body-sm-semibold_1jx6b_45 _detailLabel_040867"
|
||||
>
|
||||
ID
|
||||
</p>
|
||||
<p
|
||||
class="_font-body-sm-regular_1jx6b_40 _detailValue_040867"
|
||||
>
|
||||
<code>
|
||||
session-id
|
||||
</code>
|
||||
</p>
|
||||
</li>
|
||||
<li
|
||||
class="_detailRow_040867"
|
||||
>
|
||||
<p
|
||||
class="_font-body-sm-semibold_1jx6b_45 _detailLabel_040867"
|
||||
>
|
||||
Device ID
|
||||
</p>
|
||||
<p
|
||||
class="_font-body-sm-regular_1jx6b_40 _detailValue_040867"
|
||||
>
|
||||
<code>
|
||||
abcd1234
|
||||
</code>
|
||||
</p>
|
||||
</li>
|
||||
<li
|
||||
class="_detailRow_040867"
|
||||
>
|
||||
<p
|
||||
class="_font-body-sm-semibold_1jx6b_45 _detailLabel_040867"
|
||||
>
|
||||
Signed in
|
||||
</p>
|
||||
<p
|
||||
class="_font-body-sm-regular_1jx6b_40 _detailValue_040867"
|
||||
>
|
||||
<time
|
||||
datetime="2023-06-29T15:35:17+12:00"
|
||||
>
|
||||
Thu, 29 Jun 2023, 15:35
|
||||
</time>
|
||||
</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div
|
||||
class="_block_17898c"
|
||||
>
|
||||
<h6
|
||||
class="_font-body-md-semibold_1jx6b_64"
|
||||
>
|
||||
Client
|
||||
</h6>
|
||||
<ul
|
||||
class="_list_040867"
|
||||
>
|
||||
<li
|
||||
class="_detailRow_040867"
|
||||
>
|
||||
<p
|
||||
class="_font-body-sm-semibold_1jx6b_45 _detailLabel_040867"
|
||||
>
|
||||
Name
|
||||
</p>
|
||||
<p
|
||||
class="_font-body-sm-regular_1jx6b_40 _detailValue_040867"
|
||||
>
|
||||
element.io
|
||||
</p>
|
||||
</li>
|
||||
<li
|
||||
class="_detailRow_040867"
|
||||
>
|
||||
<p
|
||||
class="_font-body-sm-semibold_1jx6b_45 _detailLabel_040867"
|
||||
>
|
||||
Uri
|
||||
</p>
|
||||
<p
|
||||
class="_font-body-sm-regular_1jx6b_40 _detailValue_040867"
|
||||
>
|
||||
<a
|
||||
class="_link_eqn56_17 _externalLink_a97355"
|
||||
data-kind="primary"
|
||||
href="https://element.io"
|
||||
rel="noreferrer noopener"
|
||||
target="_blank"
|
||||
>
|
||||
https://element.io
|
||||
</a>
|
||||
</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<button
|
||||
class="_button_1raud_17"
|
||||
data-kind="destructive"
|
||||
data-size="sm"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
>
|
||||
End session
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`<SessionDetails> > renders a compatability session without an ssoLogin redirectUri 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="_blockList_f8cc7f"
|
||||
>
|
||||
<h3
|
||||
class="_font-heading-md-semibold_1jx6b_121"
|
||||
>
|
||||
abcd1234
|
||||
</h3>
|
||||
<div
|
||||
class="_block_17898c"
|
||||
>
|
||||
<h6
|
||||
class="_font-body-md-semibold_1jx6b_64"
|
||||
>
|
||||
Session
|
||||
</h6>
|
||||
<ul
|
||||
class="_list_040867"
|
||||
>
|
||||
<li
|
||||
class="_detailRow_040867"
|
||||
>
|
||||
<p
|
||||
class="_font-body-sm-semibold_1jx6b_45 _detailLabel_040867"
|
||||
>
|
||||
ID
|
||||
</p>
|
||||
<p
|
||||
class="_font-body-sm-regular_1jx6b_40 _detailValue_040867"
|
||||
>
|
||||
<code>
|
||||
session-id
|
||||
</code>
|
||||
</p>
|
||||
</li>
|
||||
<li
|
||||
class="_detailRow_040867"
|
||||
>
|
||||
<p
|
||||
class="_font-body-sm-semibold_1jx6b_45 _detailLabel_040867"
|
||||
>
|
||||
Device ID
|
||||
</p>
|
||||
<p
|
||||
class="_font-body-sm-regular_1jx6b_40 _detailValue_040867"
|
||||
>
|
||||
<code>
|
||||
abcd1234
|
||||
</code>
|
||||
</p>
|
||||
</li>
|
||||
<li
|
||||
class="_detailRow_040867"
|
||||
>
|
||||
<p
|
||||
class="_font-body-sm-semibold_1jx6b_45 _detailLabel_040867"
|
||||
>
|
||||
Signed in
|
||||
</p>
|
||||
<p
|
||||
class="_font-body-sm-regular_1jx6b_40 _detailValue_040867"
|
||||
>
|
||||
<time
|
||||
datetime="2023-06-29T15:35:17+12:00"
|
||||
>
|
||||
Thu, 29 Jun 2023, 15:35
|
||||
</time>
|
||||
</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<button
|
||||
class="_button_1raud_17"
|
||||
data-kind="destructive"
|
||||
data-size="sm"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
>
|
||||
End session
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
Reference in New Issue
Block a user