use renderInTestApp

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2023-09-14 21:22:11 +02:00
parent 8a6a66f621
commit ab6474579f
72 changed files with 2587 additions and 2982 deletions
@@ -23,12 +23,7 @@ import {
StarredEntitiesApi,
starredEntitiesApiRef,
} from '@backstage/plugin-catalog-react';
import {
renderInTestApp,
renderWithEffects,
TestApiProvider,
wrapInTestApp,
} from '@backstage/test-utils';
import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import React from 'react';
import { MembersListCard } from './MembersListCard';
import {
@@ -117,56 +112,50 @@ describe('MemberTab Test', () => {
};
it('Display Profile Card', async () => {
const rendered = await renderWithEffects(
wrapInTestApp(
<TestApiProvider apis={[[catalogApiRef, catalogApi]]}>
<EntityProvider entity={groupEntity}>
<MembersListCard />
</EntityProvider>
,
</TestApiProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
await renderInTestApp(
<TestApiProvider apis={[[catalogApiRef, catalogApi]]}>
<EntityProvider entity={groupEntity}>
<MembersListCard />
</EntityProvider>
,
</TestApiProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
),
},
);
expect(rendered.getByAltText('Tara MacGovern')).toHaveAttribute(
expect(screen.getByAltText('Tara MacGovern')).toHaveAttribute(
'src',
'https://example.com/staff/tara.jpeg',
);
expect(
rendered.getByText('tara-macgovern@example.com'),
).toBeInTheDocument();
expect(rendered.getByText('Tara MacGovern').closest('a')).toHaveAttribute(
expect(screen.getByText('tara-macgovern@example.com')).toBeInTheDocument();
expect(screen.getByText('Tara MacGovern').closest('a')).toHaveAttribute(
'href',
'/catalog/foo-bar/user/tara.macgovern',
);
expect(rendered.getByText('Super Awesome Developer')).toBeInTheDocument();
expect(screen.getByText('Super Awesome Developer')).toBeInTheDocument();
expect(rendered.getByText('Members (1)')).toBeInTheDocument();
expect(screen.getByText('Members (1)')).toBeInTheDocument();
});
it('Can render different member display title', async () => {
const rendered = await renderWithEffects(
wrapInTestApp(
<TestApiProvider apis={[[catalogApiRef, catalogApi]]}>
<EntityProvider entity={groupEntity}>
<MembersListCard memberDisplayTitle="Testers" />
</EntityProvider>
</TestApiProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
await renderInTestApp(
<TestApiProvider apis={[[catalogApiRef, catalogApi]]}>
<EntityProvider entity={groupEntity}>
<MembersListCard memberDisplayTitle="Testers" />
</EntityProvider>
</TestApiProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
),
},
);
expect(rendered.getByText('Testers (1)')).toBeInTheDocument();
expect(screen.getByText('Testers (1)')).toBeInTheDocument();
});
describe('Aggregate members toggle', () => {
@@ -196,6 +185,7 @@ describe('MemberTab Test', () => {
const toggleSwitch = screen.queryByRole('checkbox');
expect(toggleSwitch).toBeNull();
});
it('Shows the aggregate members toggle if the showAggregateMembersToggle prop is true', async () => {
await renderInTestApp(
<TestApiProvider
@@ -254,6 +244,7 @@ describe('MemberTab Test', () => {
duplicatedUserText.compareDocumentPosition(groupAUserOneText),
).toBe(Node.DOCUMENT_POSITION_FOLLOWING);
});
it('Shows only direct members if the aggregate members switch is turned off', async () => {
await renderInTestApp(
<TestApiProvider
@@ -287,6 +278,7 @@ describe('MemberTab Test', () => {
duplicatedUserText.compareDocumentPosition(groupAUserOneText),
).toBe(Node.DOCUMENT_POSITION_FOLLOWING);
});
it('Shows all descendant members of the group when the aggregate users switch is turned on, showing duplicated members only once', async () => {
await renderInTestApp(
<TestApiProvider
@@ -19,9 +19,10 @@ import {
EntityProvider,
entityRouteRef,
} from '@backstage/plugin-catalog-react';
import { renderWithEffects, wrapInTestApp } from '@backstage/test-utils';
import { renderInTestApp } from '@backstage/test-utils';
import React from 'react';
import { UserProfileCard } from './UserProfileCard';
import { screen } from '@testing-library/react';
describe('UserSummary Test', () => {
const userEntity: UserEntity = {
@@ -48,29 +49,27 @@ describe('UserSummary Test', () => {
};
it('Display Profile Card', async () => {
const rendered = await renderWithEffects(
wrapInTestApp(
<EntityProvider entity={userEntity}>
<UserProfileCard variant="gridItem" />
</EntityProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
await renderInTestApp(
<EntityProvider entity={userEntity}>
<UserProfileCard variant="gridItem" />
</EntityProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
),
},
);
expect(rendered.getByText('calum-leavy@example.com')).toBeInTheDocument();
expect(rendered.getByAltText('Calum Leavy')).toHaveAttribute(
expect(screen.getByText('calum-leavy@example.com')).toBeInTheDocument();
expect(screen.getByAltText('Calum Leavy')).toHaveAttribute(
'src',
'https://example.com/staff/calum.jpeg',
);
expect(rendered.getByText('examplegroup')).toHaveAttribute(
expect(screen.getByText('examplegroup')).toHaveAttribute(
'href',
'/catalog/default/group/examplegroup',
);
expect(rendered.getByText('Super awesome human')).toBeInTheDocument();
expect(screen.getByText('Super awesome human')).toBeInTheDocument();
});
});
@@ -98,20 +97,18 @@ describe('Edit Button', () => {
],
};
const rendered = await renderWithEffects(
wrapInTestApp(
<EntityProvider entity={userEntity}>
<UserProfileCard variant="gridItem" />
</EntityProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
await renderInTestApp(
<EntityProvider entity={userEntity}>
<UserProfileCard variant="gridItem" />
</EntityProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
),
},
);
expect(rendered.queryByTitle('Edit Metadata')).not.toBeInTheDocument();
expect(screen.queryByTitle('Edit Metadata')).not.toBeInTheDocument();
});
it('Should be visible when edit URL annotation is present', async () => {
@@ -141,19 +138,17 @@ describe('Edit Button', () => {
],
};
const rendered = await renderWithEffects(
wrapInTestApp(
<EntityProvider entity={userEntity}>
<UserProfileCard variant="gridItem" />
</EntityProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
await renderInTestApp(
<EntityProvider entity={userEntity}>
<UserProfileCard variant="gridItem" />
</EntityProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
),
},
);
expect(rendered.getByRole('button')).toBeInTheDocument();
expect(screen.getByRole('button')).toBeInTheDocument();
});
it('Should not show links by default', async () => {
@@ -194,20 +189,18 @@ describe('Edit Button', () => {
],
};
const rendered = await renderWithEffects(
wrapInTestApp(
<EntityProvider entity={userEntity}>
<UserProfileCard variant="gridItem" />
</EntityProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
await renderInTestApp(
<EntityProvider entity={userEntity}>
<UserProfileCard variant="gridItem" />
</EntityProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
),
},
);
expect(rendered.queryByText('Slack')).toBeNull();
expect(rendered.queryByText('Google')).toBeNull();
expect(screen.queryByText('Slack')).toBeNull();
expect(screen.queryByText('Google')).toBeNull();
});
it('Should show the links if showLinks is set', async () => {
@@ -248,19 +241,17 @@ describe('Edit Button', () => {
],
};
const rendered = await renderWithEffects(
wrapInTestApp(
<EntityProvider entity={userEntity}>
<UserProfileCard showLinks variant="gridItem" />
</EntityProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
await renderInTestApp(
<EntityProvider entity={userEntity}>
<UserProfileCard showLinks variant="gridItem" />
</EntityProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
),
},
);
expect(rendered.getByText('Slack')).toBeInTheDocument();
expect(rendered.getByText('Google')).toBeInTheDocument();
expect(screen.getByText('Slack')).toBeInTheDocument();
expect(screen.getByText('Google')).toBeInTheDocument();
});
});