From f6dfc61d2707c85621c0b8a1ecf1dcc918279606 Mon Sep 17 00:00:00 2001 From: Kiss Miklos Date: Mon, 13 Jun 2022 10:00:22 +0200 Subject: [PATCH] add test Signed-off-by: Kiss Miklos --- .../General/UserSettingsIdentityCard.test.tsx | 53 +++++++++++++++++++ .../General/UserSettingsIdentityCard.tsx | 3 +- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 plugins/user-settings/src/components/General/UserSettingsIdentityCard.test.tsx diff --git a/plugins/user-settings/src/components/General/UserSettingsIdentityCard.test.tsx b/plugins/user-settings/src/components/General/UserSettingsIdentityCard.test.tsx new file mode 100644 index 0000000000..19c3eb2182 --- /dev/null +++ b/plugins/user-settings/src/components/General/UserSettingsIdentityCard.test.tsx @@ -0,0 +1,53 @@ +/* + * Copyright 2022 The Backstage Authors + * + * 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. + */ + +import { + renderWithEffects, + wrapInTestApp, + TestApiRegistry, +} from '@backstage/test-utils'; +import { screen } from '@testing-library/react'; +import React from 'react'; +import { UserSettingsIdentityCard } from './UserSettingsIdentityCard'; +import { ApiProvider } from '@backstage/core-app-api'; +import { identityApiRef } from '@backstage/core-plugin-api'; + +const apiRegistry = TestApiRegistry.from([ + identityApiRef, + { + getProfileInfo: jest.fn(async () => ({})), + getBackstageIdentity: jest.fn(async () => ({ + type: 'user' as const, + userEntityRef: 'foo:bar/foobar', + ownershipEntityRefs: ['test-ownership'], + })), + }, +]); + +describe('', () => { + it('displays an identity card', async () => { + await renderWithEffects( + wrapInTestApp( + + + , + ), + ); + + expect(screen.getByText('test-ownership')).toBeInTheDocument(); + expect(screen.getByText('foo:bar/foobar')).toBeInTheDocument(); + }); +}); diff --git a/plugins/user-settings/src/components/General/UserSettingsIdentityCard.tsx b/plugins/user-settings/src/components/General/UserSettingsIdentityCard.tsx index b656c6b861..908cda1423 100644 --- a/plugins/user-settings/src/components/General/UserSettingsIdentityCard.tsx +++ b/plugins/user-settings/src/components/General/UserSettingsIdentityCard.tsx @@ -14,10 +14,11 @@ * limitations under the License. */ import { InfoCard } from '@backstage/core-components'; -import { Grid, Typography } from '@material-ui/core'; import React from 'react'; import { useUserProfile } from '../useUserProfileInfo'; import Chip from '@material-ui/core/Chip'; +import Grid from '@material-ui/core/Grid'; +import Typography from '@material-ui/core/Typography'; export const UserSettingsIdentityCard = () => { const { backstageIdentity } = useUserProfile();