jest tests for ownershipCard improved

Signed-off-by: Jan Vilimek <jan.vilimek@oriflame.com>
This commit is contained in:
Jan Vilimek
2021-12-11 12:49:39 +01:00
committed by Jan Vilimek
parent 26b04d2341
commit 455da34c98
@@ -108,6 +108,22 @@ describe('OwnershipCard', () => {
},
],
},
{
kind: 'system',
metadata: {
name: 'my-systen',
},
relations: [
{
type: 'ownedBy',
target: {
name: 'my-team',
namespace: 'default',
kind: 'Group',
},
},
],
},
] as any;
it('displays entity counts', async () => {
@@ -144,6 +160,7 @@ describe('OwnershipCard', () => {
expect(
queryByText(getByText('LIBRARY').parentElement!, '1'),
).toBeInTheDocument();
expect(getByText('SYSTEM')).not.toBeInTheDocument();
});
it('links to the catalog with the group filter', async () => {
@@ -222,3 +239,138 @@ describe('OwnershipCard', () => {
);
});
});
describe('OwnershipCardWithCustomFilterDefinition', () => {
const groupEntity: GroupEntity = {
apiVersion: 'backstage.io/v1alpha1',
kind: 'Group',
metadata: {
name: 'my-team',
},
spec: {
type: 'team',
children: [],
},
relations: [
{
type: 'memberOf',
target: {
kind: 'group',
name: 'ExampleGroup',
namespace: 'default',
},
},
],
};
const items = [
{
kind: 'API',
metadata: {
name: 'my-api',
},
spec: {
type: 'openapi',
},
relations: [
{
type: 'ownedBy',
target: {
name: 'my-team',
namespace: 'default',
kind: 'Group',
},
},
],
},
{
kind: 'Component',
metadata: {
name: 'my-service',
},
spec: {
type: 'service',
},
relations: [
{
type: 'ownedBy',
target: {
name: 'my-team',
namespace: 'default',
kind: 'Group',
},
},
],
},
{
kind: 'Component',
metadata: {
name: 'my-library',
namespace: 'other-namespace',
},
spec: {
type: 'library',
},
relations: [
{
type: 'ownedBy',
target: {
name: 'my-team',
namespace: 'default',
kind: 'Group',
},
},
],
},
{
kind: 'system',
metadata: {
name: 'my-systen',
},
relations: [
{
type: 'ownedBy',
target: {
name: 'my-team',
namespace: 'default',
kind: 'Group',
},
},
],
},
] as any;
it('displays entity counts', async () => {
const catalogApi: jest.Mocked<CatalogApi> = {
getEntities: jest.fn(),
} as any;
catalogApi.getEntities.mockResolvedValue({
items,
});
const { getByText } = await renderInTestApp(
<TestApiProvider apis={[[catalogApiRef, catalogApi]]}>
<EntityProvider entity={groupEntity}>
<OwnershipCard entityFilterKind={['API','system']} />
</EntityProvider>
</TestApiProvider>,
{
mountedRoutes: {
'/create': catalogRouteRef,
},
},
);
expect(getByText('OPENAPI')).toBeInTheDocument();
expect(
queryByText(getByText('OPENAPI').parentElement!, '1'),
).toBeInTheDocument();
expect(getByText('SERVICE')).not.toBeInTheDocument();
expect(getByText('LIBRARY')).not.toBeInTheDocument();
expect(getByText('SYSTEM')).toBeInTheDocument();
expect(
queryByText(getByText('SYSTEM').parentElement!, '1'),
).toBeInTheDocument();
});
});