Skip to content

Commit 0392008

Browse files
committed
added test
1 parent 4a5aa9c commit 0392008

File tree

2 files changed

+82
-1
lines changed

2 files changed

+82
-1
lines changed

src/components/ControlPlane/ManagedResources.cy.tsx

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,3 +336,84 @@ describe('ManagedResources - Edit Resource', () => {
336336
cy.then(() => cy.wrap(patchedItem).should('not.be.null'));
337337
});
338338
});
339+
340+
describe('ManagedResources - Without Admin Rights', () => {
341+
const fakeUseHasMcpAdminRights = () => {
342+
return false;
343+
};
344+
345+
const fakeUseApiResource: typeof useApiResource = (): any => {
346+
return {
347+
data: mockManagedResources,
348+
error: undefined,
349+
isLoading: false,
350+
isValidating: false,
351+
mutate: async () => undefined,
352+
};
353+
};
354+
355+
const fakeUseResourcePluralNames: typeof useResourcePluralNames = (): any => {
356+
return {
357+
getPluralKind: (kind: string) => `${kind.toLowerCase()}s`,
358+
isLoading: false,
359+
error: undefined,
360+
};
361+
};
362+
363+
const mockManagedResources: ManagedResourceGroup[] = [
364+
{
365+
items: [
366+
{
367+
apiVersion: 'account.btp.sap.crossplane.io/v1alpha1',
368+
kind: 'Subaccount',
369+
metadata: {
370+
name: 'test-subaccount',
371+
namespace: 'test-namespace',
372+
creationTimestamp: '2024-01-01T00:00:00Z',
373+
resourceVersion: '1',
374+
labels: {},
375+
},
376+
spec: {},
377+
status: {
378+
conditions: [
379+
{
380+
type: 'Ready',
381+
status: 'True',
382+
lastTransitionTime: '2024-01-01T00:00:00Z',
383+
},
384+
{
385+
type: 'Synced',
386+
status: 'True',
387+
lastTransitionTime: '2024-01-01T00:00:00Z',
388+
},
389+
],
390+
},
391+
} as any,
392+
],
393+
},
394+
];
395+
396+
it('disables Edit and Delete actions when user has no admin rights', () => {
397+
cy.mount(
398+
<MemoryRouter>
399+
<SplitterProvider>
400+
<ManagedResources
401+
useApiResource={fakeUseApiResource}
402+
useResourcePluralNames={fakeUseResourcePluralNames}
403+
useHasMcpAdminRights={fakeUseHasMcpAdminRights}
404+
/>
405+
</SplitterProvider>
406+
</MemoryRouter>,
407+
);
408+
409+
// Expand resource group
410+
cy.get('button[aria-label*="xpand"]').first().click({ force: true });
411+
cy.contains('test-subaccount').should('be.visible');
412+
413+
// Open actions menu
414+
cy.get('[data-testid="ActionsMenu-opener"]').first().click({ force: true });
415+
416+
// Verify Delete action is disabled by checking the ui5-menu-item element
417+
cy.get('ui5-menu-item[data-action-key="delete"]').should('have.attr', 'disabled');
418+
});
419+
});

src/components/ControlPlane/ManagedResources.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ export function ManagedResources({
242242
key: 'edit',
243243
text: t('ManagedResources.editAction', 'Edit'),
244244
icon: 'edit',
245-
disabled: isFluxManaged,
245+
disabled: isFluxManaged || !hasMCPAdminRights,
246246
onClick: openEditPanel,
247247
tooltip: isFluxManaged && hasMCPAdminRights ? t('yaml.fluxManaged') : undefined,
248248
},

0 commit comments

Comments
 (0)