From 340148b100bf9432ed468ba689cab975fb4fde21 Mon Sep 17 00:00:00 2001 From: Andreas Kienle Date: Fri, 31 Oct 2025 11:25:39 +0100 Subject: [PATCH 1/3] test: added tests for mcp and workspace deletion --- .../ControlPlaneCard/ControlPlaneCard.cy.tsx | 54 +++++++ .../ControlPlaneCard/ControlPlaneCard.tsx | 33 ++-- .../ControlPlaneCard/ControlPlaneCardMenu.tsx | 8 +- .../ControlPlanes/ControlPlanesListMenu.tsx | 2 +- .../ControlPlaneListWorkspaceGridTile.cy.tsx | 144 ++++++++++++++++++ .../ControlPlaneListWorkspaceGridTile.tsx | 15 +- .../useDeleteManagedControlPlane.spec.ts | 88 +++++++++++ src/hooks/useDeleteManagedControlPlane.ts | 27 ++++ src/hooks/useDeleteWorkspace.ts | 3 +- src/hooks/useManagedControlPlanesQuery.ts | 16 ++ 10 files changed, 358 insertions(+), 32 deletions(-) create mode 100644 src/components/ControlPlanes/ControlPlaneCard/ControlPlaneCard.cy.tsx create mode 100644 src/components/ControlPlanes/List/ControlPlaneListWorkspaceGridTile.cy.tsx create mode 100644 src/hooks/useDeleteManagedControlPlane.spec.ts create mode 100644 src/hooks/useDeleteManagedControlPlane.ts create mode 100644 src/hooks/useManagedControlPlanesQuery.ts diff --git a/src/components/ControlPlanes/ControlPlaneCard/ControlPlaneCard.cy.tsx b/src/components/ControlPlanes/ControlPlaneCard/ControlPlaneCard.cy.tsx new file mode 100644 index 00000000..8763a43e --- /dev/null +++ b/src/components/ControlPlanes/ControlPlaneCard/ControlPlaneCard.cy.tsx @@ -0,0 +1,54 @@ +import { SplitterProvider } from '../../Splitter/SplitterContext.tsx'; +import { ListControlPlanesType } from '../../../lib/api/types/crate/controlPlanes.ts'; +import { MemoryRouter } from 'react-router-dom'; +import '@ui5/webcomponents-cypress-commands'; +import { ControlPlaneCard } from './ControlPlaneCard.tsx'; +import { useDeleteManagedControlPlane } from '../../../hooks/useDeleteManagedControlPlane.ts'; +import { ListWorkspacesType } from '../../../lib/api/types/crate/listWorkspaces.ts'; + +describe('ControlPlaneCard', () => { + let deleteManagedControlPlaneCalled = false; + const fakeUseDeleteManagedControlPlane: typeof useDeleteManagedControlPlane = () => ({ + deleteManagedControlPlane: async (): Promise => { + deleteManagedControlPlaneCalled = true; + }, + }); + + beforeEach(() => { + deleteManagedControlPlaneCalled = false; + }); + + it('deletes the workspace', () => { + const managedControlPlane: ListControlPlanesType = { + metadata: { + name: 'mcp-name', + }, + } as unknown as ListControlPlanesType; + + const workspace: ListWorkspacesType = { + metadata: { + name: 'workspaceName', + }, + } as unknown as ListWorkspacesType; + + cy.mount( + + + + + , + ); + + cy.get("[data-testid='ControlPlaneCardMenu-opener']").click(); + cy.contains('Delete ManagedControlPlane').click({ force: true }); + cy.get('ui5-dialog[open]').find('ui5-input').typeIntoUi5Input('mcp-name'); + cy.then(() => cy.wrap(deleteManagedControlPlaneCalled).should('equal', false)); + cy.get('ui5-dialog[open]').find('ui5-button').contains('Delete').click(); + cy.then(() => cy.wrap(deleteManagedControlPlaneCalled).should('equal', true)); + }); +}); diff --git a/src/components/ControlPlanes/ControlPlaneCard/ControlPlaneCard.tsx b/src/components/ControlPlanes/ControlPlaneCard/ControlPlaneCard.tsx index 22dab2d5..0a9e11e0 100644 --- a/src/components/ControlPlanes/ControlPlaneCard/ControlPlaneCard.tsx +++ b/src/components/ControlPlanes/ControlPlaneCard/ControlPlaneCard.tsx @@ -14,16 +14,7 @@ import styles from './ControlPlaneCard.module.css'; import { KubectlDeleteMcp } from '../../Dialogs/KubectlCommandInfo/Controllers/KubectlDeleteMcp.tsx'; import { ListControlPlanesType, ReadyStatus } from '../../../lib/api/types/crate/controlPlanes.ts'; import { ListWorkspacesType } from '../../../lib/api/types/crate/listWorkspaces.ts'; -import { useApiResourceMutation } from '../../../lib/api/useApiResource.ts'; -import { - DeleteMCPResource, - DeleteMCPType, - PatchMCPResourceForDeletion, - PatchMCPResourceForDeletionBody, -} from '../../../lib/api/types/crate/deleteMCP.ts'; - import { YamlViewButton } from '../../Yaml/YamlViewButton.tsx'; -import { useToast } from '../../../context/ToastContext.tsx'; import { canConnectToMCP } from '../controlPlanes.ts'; import { Infobox } from '../../Ui/Infobox/Infobox.tsx'; @@ -31,20 +22,26 @@ import { Infobox } from '../../Ui/Infobox/Infobox.tsx'; import { ControlPlaneCardMenu } from './ControlPlaneCardMenu.tsx'; import { EditManagedControlPlaneWizardDataLoader } from '../../Wizards/CreateManagedControlPlane/EditManagedControlPlaneWizardDataLoader.tsx'; import { DISPLAY_NAME_ANNOTATION } from '../../../lib/api/types/shared/keyNames.ts'; +import { useDeleteManagedControlPlane as _useDeleteManagedControlPlane } from '../../../hooks/useDeleteManagedControlPlane.ts'; interface Props { controlPlane: ListControlPlanesType; workspace: ListWorkspacesType; projectName: string; + useDeleteManagedControlPlane?: typeof _useDeleteManagedControlPlane; } type MCPWizardState = { isOpen: boolean; mode?: 'edit' | 'duplicate'; }; -export const ControlPlaneCard = ({ controlPlane, workspace, projectName }: Props) => { +export const ControlPlaneCard = ({ + controlPlane, + workspace, + projectName, + useDeleteManagedControlPlane = _useDeleteManagedControlPlane, +}: Props) => { const [dialogDeleteMcpIsOpen, setDialogDeleteMcpIsOpen] = useState(false); - const toast = useToast(); const { t } = useTranslation(); const [managedControlPlaneWizardState, setManagedControlPlaneWizardState] = useState({ isOpen: false, @@ -54,11 +51,9 @@ export const ControlPlaneCard = ({ controlPlane, workspace, projectName }: Props const handleIsManagedControlPlaneWizardOpen = (isOpen: boolean, mode?: 'edit' | 'duplicate') => { setManagedControlPlaneWizardState({ isOpen, mode }); }; - const { trigger: patchTrigger } = useApiResourceMutation( - PatchMCPResourceForDeletion(controlPlane.metadata.namespace, controlPlane.metadata.name), - ); - const { trigger: deleteTrigger } = useApiResourceMutation( - DeleteMCPResource(controlPlane.metadata.namespace, controlPlane.metadata.name), + const { deleteManagedControlPlane } = useDeleteManagedControlPlane( + controlPlane.metadata.namespace, + controlPlane.metadata.name, ); const name = controlPlane.metadata.name; @@ -135,11 +130,7 @@ export const ControlPlaneCard = ({ controlPlane, workspace, projectName }: Props } isOpen={dialogDeleteMcpIsOpen} setIsOpen={setDialogDeleteMcpIsOpen} - onDeletionConfirmed={async () => { - await patchTrigger(PatchMCPResourceForDeletionBody); - await deleteTrigger(); - toast.show(t('ControlPlaneCard.deleteConfirmationDialog')); - }} + onDeletionConfirmed={deleteManagedControlPlane} /> = ({ return ( <> -