1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-08-09 04:22:45 +03:00
Files
authentication-service/frontend/src/components/OAuth2Session.test.tsx
Quentin Gliech 597482d4d8 Cleanup the session details fragments & load last active IP
This also cleans up the GraphQL scalar types, by making sure we always parse dates correctly
2023-09-21 12:47:45 +02:00

72 lines
2.1 KiB
TypeScript

// 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 { create } from "react-test-renderer";
import { describe, expect, it, beforeAll } from "vitest";
import { makeFragmentData } from "../gql";
import { WithLocation } from "../test-utils/WithLocation";
import { mockLocale } from "../test-utils/mockLocale";
import OAuth2Session, { FRAGMENT } from "./OAuth2Session";
describe("<OAuth2Session />", () => {
const defaultSession = {
id: "session-id",
scope:
"openid urn:matrix:org.matrix.msc2967.client:api:* urn:matrix:org.matrix.msc2967.client:device:abcd1234",
createdAt: "2023-06-29T03:35:17.451292+00:00",
lastActiveIp: "1.2.3.4",
client: {
id: "test-id",
clientId: "test-client-id",
clientName: "Element",
clientUri: "https://element.io",
},
};
const finishedAt = "2023-06-29T03:35:19.451292+00:00";
beforeAll(() => mockLocale());
it("renders an active session", () => {
const session = makeFragmentData(defaultSession, FRAGMENT);
const component = create(
<WithLocation>
<OAuth2Session session={session} />
</WithLocation>,
);
expect(component.toJSON()).toMatchSnapshot();
});
it("renders a finished session", () => {
const session = makeFragmentData(
{
...defaultSession,
finishedAt,
},
FRAGMENT,
);
const component = create(
<WithLocation>
<OAuth2Session session={session} />
</WithLocation>,
);
expect(component.toJSON()).toMatchSnapshot();
});
});