diff --git a/packages/ui/src/components/Visualization/Canvas/Canvas.test.tsx b/packages/ui/src/components/Visualization/Canvas/Canvas.test.tsx index c32c333e6..72e643fc3 100644 --- a/packages/ui/src/components/Visualization/Canvas/Canvas.test.tsx +++ b/packages/ui/src/components/Visualization/Canvas/Canvas.test.tsx @@ -1,12 +1,13 @@ -import { render, waitFor, fireEvent, screen} from '@testing-library/react'; +import { fireEvent, render, screen, waitFor } from '@testing-library/react'; +import { act } from 'react-dom/test-utils'; +import { CamelRouteResource, KameletResource } from '../../../models/camel'; import { CamelRouteVisualEntity } from '../../../models/visualization/flows'; +import { EntitiesContext } from '../../../providers'; import { CatalogModalContext } from '../../../providers/catalog-modal.provider'; -import { VisibleFLowsContextResult } from '../../../providers/visible-flows.provider'; -import { CamelRouteResource, KameletResource } from '../../../models/camel'; +import { VisibleFLowsContextResult, VisibleFlowsContext } from '../../../providers/visible-flows.provider'; +import { TestProvidersWrapper } from '../../../stubs'; import { camelRouteJson } from '../../../stubs/camel-route'; import { kameletJson } from '../../../stubs/kamelet-route'; -import { TestProvidersWrapper } from '../../../stubs'; -import { act } from 'react-dom/test-utils'; import { Canvas } from './Canvas'; describe('Canvas', () => { @@ -43,32 +44,44 @@ describe('Canvas', () => { }); it('should be able to delete the routes', async () => { - const camelRouteResource = new CamelRouteResource(camelRouteJson); - const routeEntity = camelRouteResource.getVisualEntities(); - const removeSpy = jest.spyOn(camelRouteResource, 'removeEntity'); + const camelResource = new CamelRouteResource(camelRouteJson); + const routeEntity = camelResource.getVisualEntities(); + const removeSpy = jest.spyOn(camelResource, 'removeEntity'); + const setCurrentSchemaTypeSpy = jest.fn(); + const updateEntitiesFromCamelResourceSpy = jest.fn(); + const updateSourceCodeFromEntitiesSpy = jest.fn(); render( - - - , + + + + + , ); // Right click anywhere on the container label const route = screen.getByText('route-8888'); - // const route = document.querySelectorAll('.pf-topology__group'); - await act(async() => { + await act(async () => { fireEvent.contextMenu(route); }); - // click the Delete ContextMenuItem - const deleteRoute = screen.getByRole('menuitem', {name: 'Delete'}); + // Click the Delete ContextMenuItem + const deleteRoute = screen.getByRole('menuitem', { name: 'Delete' }); expect(deleteRoute).toBeInTheDocument(); - await act(() => { + await act(async () => { fireEvent.click(deleteRoute); }); @@ -81,33 +94,45 @@ describe('Canvas', () => { const kameletResource = new KameletResource(kameletJson); const kameletEntity = kameletResource.getVisualEntities(); const removeSpy = jest.spyOn(kameletResource, 'removeEntity'); + const setCurrentSchemaTypeSpy = jest.fn(); + const updateEntitiesFromCamelResourceSpy = jest.fn(); + const updateSourceCodeFromEntitiesSpy = jest.fn(); render( - - - , + + + + + , ); // Right click anywhere on the container label const kamelet = screen.getByText('user-source'); // const route = document.querySelectorAll('.pf-topology__group'); - await act(async() => { + await act(async () => { fireEvent.contextMenu(kamelet); }); // click the Delete ContextMenuItem - const deleteKamelet = screen.getByRole('menuitem', {name: 'Delete'}); + const deleteKamelet = screen.getByRole('menuitem', { name: 'Delete' }); expect(deleteKamelet).toBeInTheDocument(); - await act(() => { + await act(async () => { fireEvent.click(deleteKamelet); }); - screen.debug(); // Check if the remove function is called expect(removeSpy).toHaveBeenCalled(); }); diff --git a/packages/ui/src/components/Visualization/Canvas/__snapshots__/Canvas.test.tsx.snap b/packages/ui/src/components/Visualization/Canvas/__snapshots__/Canvas.test.tsx.snap index ddf9dd0c3..f1b215a2f 100644 --- a/packages/ui/src/components/Visualization/Canvas/__snapshots__/Canvas.test.tsx.snap +++ b/packages/ui/src/components/Visualization/Canvas/__snapshots__/Canvas.test.tsx.snap @@ -84,10 +84,10 @@ exports[`Canvas Empty state should render empty state when there is no visible f >