test(MyGroupsSidebarItem): enhance tests to verify displayName for group entities

Signed-off-by: Dhruv Joshi <d.joshi@theaccessgroup.com>
This commit is contained in:
Dhruv Joshi
2025-01-06 15:43:36 +00:00
parent 9cf1260405
commit 5d175bb0e8
@@ -78,6 +78,9 @@ describe('MyGroupsSidebarItem Test', () => {
spec: {
type: 'team',
children: [],
profile: {
displayName: 'Team A',
},
},
},
] as Entity[],
@@ -111,7 +114,94 @@ describe('MyGroupsSidebarItem Test', () => {
});
describe('For users that are members of multiple groups', () => {
it('MyGroupsSidebarItem should display a sub-menu with all their groups and a link to each group', async () => {
it('MyGroupsSidebarItem should display a sub-menu with all their groups, with displaying the title through displayName, and a link to each group', async () => {
const identityApi = mockApis.identity({
userEntityRef: 'user:default/nigel.manning',
ownershipEntityRefs: ['user:default/nigel.manning'],
});
const catalogApi = catalogApiMock.mock({
getEntities: async () => ({
items: [
{
apiVersion: 'backstage.io/v1alpha1',
kind: 'Group',
metadata: {
name: 'team-a',
title: 'Team A',
namespace: 'default',
},
spec: {
type: 'team',
children: [],
profile: {
displayName: 'Team A',
},
},
},
{
apiVersion: 'backstage.io/v1alpha1',
kind: 'Group',
metadata: {
name: 'team-b',
title: 'Team B',
namespace: 'default',
},
spec: {
type: 'team',
children: [],
profile: {
displayName: 'Team B',
},
},
},
{
apiVersion: 'backstage.io/v1alpha1',
kind: 'Group',
metadata: {
name: 'team-c',
title: 'Team C',
namespace: 'default',
},
spec: {
type: 'team',
children: [],
profile: {
displayName: 'Team C',
},
},
},
] as Entity[],
}),
});
const rendered = await renderInTestApp(
<TestApiProvider
apis={[
[identityApiRef, identityApi],
[catalogApiRef, catalogApi],
]}
>
<MyGroupsSidebarItem
singularTitle="My Squad"
pluralTitle="My Squads"
icon={GroupIcon}
/>
</TestApiProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
},
);
expect(rendered.getByLabelText('My Squads')).toBeInTheDocument();
expect(rendered.getByLabelText('Team B')).toBeInTheDocument();
expect(rendered.getByLabelText('Team C')).toHaveAttribute(
'href',
'/catalog/default/Group/team-c',
);
});
it('MyGroupsSidebarItem should display the metadata name when the displayName property is not available in the entity', async () => {
const identityApi = mockApis.identity({
userEntityRef: 'user:default/nigel.manning',
ownershipEntityRefs: ['user:default/nigel.manning'],
@@ -180,86 +270,87 @@ describe('MyGroupsSidebarItem Test', () => {
},
},
);
expect(rendered.getByLabelText('My Squads')).toBeInTheDocument();
});
});
describe('When an additional filter is not provided', () => {
it('catalogApi.getEntities() should be called with the default filter', async () => {
const identityApi = mockApis.identity({
userEntityRef: 'user:default/guest',
ownershipEntityRefs: ['user:default/guest'],
});
const mockCatalogApi = catalogApiMock.mock();
await renderInTestApp(
<TestApiProvider
apis={[
[identityApiRef, identityApi],
[catalogApiRef, mockCatalogApi],
]}
>
<MyGroupsSidebarItem
singularTitle="My Squad"
pluralTitle="My Squads"
icon={GroupIcon}
/>
</TestApiProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
},
);
expect(mockCatalogApi.getEntities).toHaveBeenCalledWith({
filter: [
{
kind: 'group',
'relations.hasMember': 'user:default/guest',
},
],
fields: ['metadata', 'kind'],
});
});
});
describe('When an additional filter is provided', () => {
it('catalogApi.getEntities() should be called with an additional filter item', async () => {
const identityApi = mockApis.identity({
userEntityRef: 'user:default/guest',
ownershipEntityRefs: ['user:default/guest'],
});
const mockCatalogApi = catalogApiMock.mock();
await renderInTestApp(
<TestApiProvider
apis={[
[identityApiRef, identityApi],
[catalogApiRef, mockCatalogApi],
]}
>
<MyGroupsSidebarItem
singularTitle="My Squad"
pluralTitle="My Squads"
icon={GroupIcon}
filter={{ 'spec.type': 'team' }}
/>
</TestApiProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
},
);
expect(mockCatalogApi.getEntities).toHaveBeenCalledWith({
filter: [
{
kind: 'group',
'relations.hasMember': 'user:default/guest',
'spec.type': 'team',
},
],
fields: ['metadata', 'kind'],
});
expect(rendered.getByLabelText('Team-a')).toBeInTheDocument();
expect(rendered.getByLabelText('Team-b')).toBeInTheDocument();
expect(rendered.getByLabelText('Team-c')).toBeInTheDocument();
});
});
});
describe('When an additional filter is not provided', () => {
it('catalogApi.getEntities() should be called with the default filter', async () => {
const identityApi = mockApis.identity({
userEntityRef: 'user:default/guest',
ownershipEntityRefs: ['user:default/guest'],
});
const mockCatalogApi = catalogApiMock.mock();
await renderInTestApp(
<TestApiProvider
apis={[
[identityApiRef, identityApi],
[catalogApiRef, mockCatalogApi],
]}
>
<MyGroupsSidebarItem
singularTitle="My Squad"
pluralTitle="My Squads"
icon={GroupIcon}
/>
</TestApiProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
},
);
expect(mockCatalogApi.getEntities).toHaveBeenCalledWith({
filter: [
{
kind: 'group',
'relations.hasMember': 'user:default/guest',
},
],
fields: ['metadata', 'kind'],
});
});
});
describe('When an additional filter is provided', () => {
it('catalogApi.getEntities() should be called with an additional filter item', async () => {
const identityApi = mockApis.identity({
userEntityRef: 'user:default/guest',
ownershipEntityRefs: ['user:default/guest'],
});
const mockCatalogApi = catalogApiMock.mock();
await renderInTestApp(
<TestApiProvider
apis={[
[identityApiRef, identityApi],
[catalogApiRef, mockCatalogApi],
]}
>
<MyGroupsSidebarItem
singularTitle="My Squad"
pluralTitle="My Squads"
icon={GroupIcon}
filter={{ 'spec.type': 'team' }}
/>
</TestApiProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
},
);
expect(mockCatalogApi.getEntities).toHaveBeenCalledWith({
filter: [
{
kind: 'group',
'relations.hasMember': 'user:default/guest',
'spec.type': 'team',
},
],
fields: ['metadata', 'kind'],
});
});
});