-
Notifications
You must be signed in to change notification settings - Fork 3
Tests for resources #360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Tests for resources #360
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ export type ActionsMenuProps<T> = { | |
| buttonIcon?: string; | ||
| }; | ||
|
|
||
| export function ActionsMenu<T>({ item, actions, buttonIcon = 'overflow' }: ActionsMenuProps<T>) { | ||
| export function ActionsMenu<T>({ item, actions }: ActionsMenuProps<T>) { | ||
| const popoverRef = useRef<MenuDomRef>(null); | ||
| const [open, setOpen] = useState(false); | ||
|
|
||
|
|
@@ -30,10 +30,11 @@ export function ActionsMenu<T>({ item, actions, buttonIcon = 'overflow' }: Actio | |
|
|
||
| return ( | ||
| <> | ||
| <Button icon={buttonIcon} design="Transparent" onClick={handleOpenerClick} /> | ||
| <Button icon="overflow" design="Transparent" data-testid="ActionsMenu-opener" onClick={handleOpenerClick} /> | ||
| <Menu | ||
| ref={popoverRef} | ||
| open={open} | ||
| data-component-name="ActionsMenu" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use |
||
| onItemClick={(event) => { | ||
| const element = event.detail.item as HTMLElement & { disabled?: boolean }; | ||
| const actionKey = element.dataset.actionKey; | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,328 @@ | ||||||||||||||||||||||||||||||||
| /* eslint-disable @typescript-eslint/no-explicit-any */ | ||||||||||||||||||||||||||||||||
| import { ManagedResources } from './ManagedResources.tsx'; | ||||||||||||||||||||||||||||||||
| import { SplitterProvider } from '../Splitter/SplitterContext.tsx'; | ||||||||||||||||||||||||||||||||
| import { ManagedResourceGroup } from '../../lib/shared/types.ts'; | ||||||||||||||||||||||||||||||||
| import { MemoryRouter } from 'react-router-dom'; | ||||||||||||||||||||||||||||||||
| import { useApiResourceMutation } from '../../lib/api/useApiResource.ts'; | ||||||||||||||||||||||||||||||||
| import '@ui5/webcomponents-cypress-commands'; | ||||||||||||||||||||||||||||||||
| import { useHandleResourcePatch } from '../../lib/api/types/crossplane/useHandleResourcePatch.ts'; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| describe('ManagedResources - Delete Resource', () => { | ||||||||||||||||||||||||||||||||
| let deleteCalled = false; | ||||||||||||||||||||||||||||||||
| let patchCalled = false; | ||||||||||||||||||||||||||||||||
| let triggerCallCount = 0; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| const fakeUseApiResourceMutation: typeof useApiResourceMutation = (): any => { | ||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||
| data: undefined, | ||||||||||||||||||||||||||||||||
| error: undefined, | ||||||||||||||||||||||||||||||||
| reset: () => {}, | ||||||||||||||||||||||||||||||||
| trigger: async (): Promise<any> => { | ||||||||||||||||||||||||||||||||
| const currentTriggerCall = triggerCallCount++; | ||||||||||||||||||||||||||||||||
| if (currentTriggerCall === 0) { | ||||||||||||||||||||||||||||||||
| deleteCalled = true; | ||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||
| patchCalled = true; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| return undefined; | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| isMutating: false, | ||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| const mockManagedResources: ManagedResourceGroup[] = [ | ||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||
| items: [ | ||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||
| apiVersion: 'account.btp.sap.crossplane.io/v1alpha1', | ||||||||||||||||||||||||||||||||
| kind: 'Subaccount', | ||||||||||||||||||||||||||||||||
| metadata: { | ||||||||||||||||||||||||||||||||
| name: 'test-subaccount', | ||||||||||||||||||||||||||||||||
| namespace: 'test-namespace', | ||||||||||||||||||||||||||||||||
| creationTimestamp: '2024-01-01T00:00:00Z', | ||||||||||||||||||||||||||||||||
| resourceVersion: '1', | ||||||||||||||||||||||||||||||||
| labels: {}, | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| spec: {}, | ||||||||||||||||||||||||||||||||
| status: { | ||||||||||||||||||||||||||||||||
| conditions: [ | ||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||
| type: 'Ready', | ||||||||||||||||||||||||||||||||
| status: 'True', | ||||||||||||||||||||||||||||||||
| lastTransitionTime: '2024-01-01T00:00:00Z', | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||
| type: 'Synced', | ||||||||||||||||||||||||||||||||
| status: 'True', | ||||||||||||||||||||||||||||||||
| lastTransitionTime: '2024-01-01T00:00:00Z', | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| } as any, | ||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| before(() => { | ||||||||||||||||||||||||||||||||
| // Set up interceptors once for all tests | ||||||||||||||||||||||||||||||||
| cy.intercept('GET', '**/managed', { | ||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason for switching to |
||||||||||||||||||||||||||||||||
| statusCode: 200, | ||||||||||||||||||||||||||||||||
| body: mockManagedResources, | ||||||||||||||||||||||||||||||||
| }).as('getManagedResources'); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| cy.intercept('GET', '**/customresourcedefinitions*', { | ||||||||||||||||||||||||||||||||
| statusCode: 200, | ||||||||||||||||||||||||||||||||
| body: { | ||||||||||||||||||||||||||||||||
| items: [ | ||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||
| spec: { | ||||||||||||||||||||||||||||||||
| names: { | ||||||||||||||||||||||||||||||||
| kind: 'Subaccount', | ||||||||||||||||||||||||||||||||
| plural: 'subaccounts', | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| }).as('getCRDs'); | ||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| beforeEach(() => { | ||||||||||||||||||||||||||||||||
| deleteCalled = false; | ||||||||||||||||||||||||||||||||
| patchCalled = false; | ||||||||||||||||||||||||||||||||
| triggerCallCount = 0; | ||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| it('deletes a managed resource', () => { | ||||||||||||||||||||||||||||||||
| cy.mount( | ||||||||||||||||||||||||||||||||
| <MemoryRouter> | ||||||||||||||||||||||||||||||||
| <SplitterProvider> | ||||||||||||||||||||||||||||||||
| <ManagedResources useApiResourceMutation={fakeUseApiResourceMutation} /> | ||||||||||||||||||||||||||||||||
| </SplitterProvider> | ||||||||||||||||||||||||||||||||
| </MemoryRouter>, | ||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| cy.wait('@getManagedResources'); | ||||||||||||||||||||||||||||||||
| cy.wait('@getCRDs'); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| cy.get('button[aria-label*="xpand"]').first().click({ force: true }); | ||||||||||||||||||||||||||||||||
| cy.wait(500); | ||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are all these There is a section in the cypress documentation about this: https://docs.cypress.io/app/core-concepts/best-practices#Unnecessary-Waiting Please check if this is needed. |
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| cy.contains('test-subaccount').should('be.visible'); | ||||||||||||||||||||||||||||||||
| cy.get('[data-testid="ActionsMenu-opener"]').first().click({ force: true }); | ||||||||||||||||||||||||||||||||
| cy.contains('Delete').click({ force: true }); | ||||||||||||||||||||||||||||||||
| cy.get('ui5-dialog[open]').find('ui5-input').typeIntoUi5Input('test-subaccount'); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| cy.then(() => cy.wrap(deleteCalled).should('equal', false)); | ||||||||||||||||||||||||||||||||
| cy.get('ui5-dialog[open]').find('ui5-button').contains('Delete').click(); | ||||||||||||||||||||||||||||||||
| cy.then(() => cy.wrap(deleteCalled).should('equal', true)); | ||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| it('force deletes a managed resource', () => { | ||||||||||||||||||||||||||||||||
| cy.mount( | ||||||||||||||||||||||||||||||||
| <MemoryRouter> | ||||||||||||||||||||||||||||||||
| <SplitterProvider> | ||||||||||||||||||||||||||||||||
| <ManagedResources useApiResourceMutation={fakeUseApiResourceMutation} /> | ||||||||||||||||||||||||||||||||
| </SplitterProvider> | ||||||||||||||||||||||||||||||||
| </MemoryRouter>, | ||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| cy.wait(1000); | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
| cy.wait(1000); | |
| cy.wait('@getManagedResources'); | |
| cy.wait('@getCRDs'); |
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider reducing or removing the hardcoded waits (cy.wait(500), cy.wait(2000)) throughout the test file. Cypress generally handles element availability automatically with built-in retry logic. If waits are necessary, consider using more specific assertions or cy.waitUntil() to wait for specific conditions rather than arbitrary time periods, which can make tests slower and more brittle.
| cy.wait(2000); | |
| cy.then(() => { | |
| cy.log(`deleteCalled: ${deleteCalled}, patchCalled: ${patchCalled}`); | |
| }); | |
| cy.then(() => cy.wrap(deleteCalled).should('equal', true)); | |
| cy.then(() => cy.wrap(patchCalled).should('equal', true)); | |
| cy.then(() => { | |
| cy.log(`deleteCalled: ${deleteCalled}, patchCalled: ${patchCalled}`); | |
| }); | |
| cy.wrap(() => deleteCalled).should('equal', true); | |
| cy.wrap(() => patchCalled).should('equal', true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
buttonIconparameter is still defined in theActionsMenuPropstype (line 17) but has been removed from the function destructuring. This creates an inconsistency where the type declares a parameter that is no longer used. ThebuttonIconproperty should be removed from theActionsMenuPropstype definition to match the implementation.