-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix(canvas): Show confirmation dialog for replacing a step with children
- Loading branch information
1 parent
6eb1529
commit 97fe010
Showing
18 changed files
with
394 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/ui/src/components/Visualization/Custom/ContextMenu/ItemDeleteGroup.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { fireEvent, render } from '@testing-library/react'; | ||
import { createVisualizationNode } from '../../../../models'; | ||
import { ActionConfirmationModalContext } from '../../../../providers/action-confirmation-modal.provider'; | ||
import { ItemDeleteGroup } from './ItemDeleteGroup'; | ||
|
||
describe('ItemDeleteGroup', () => { | ||
const vizNode = createVisualizationNode('test', {}); | ||
|
||
const mockDeleteModalContext = { | ||
actionConfirmation: jest.fn(), | ||
}; | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should render delete ContextMenuItem', () => { | ||
const { container } = render(<ItemDeleteGroup vizNode={vizNode} />); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it('should open delete confirmation modal on click', async () => { | ||
const wrapper = render( | ||
<ActionConfirmationModalContext.Provider value={mockDeleteModalContext}> | ||
<ItemDeleteGroup vizNode={vizNode} /> | ||
</ActionConfirmationModalContext.Provider>, | ||
); | ||
|
||
fireEvent.click(wrapper.getByText('Delete')); | ||
|
||
expect(mockDeleteModalContext.actionConfirmation).toHaveBeenCalledWith({ | ||
title: 'Permanently delete flow?', | ||
text: 'All steps will be lost.', | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/ui/src/components/Visualization/Custom/ContextMenu/ItemDeleteStep.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { fireEvent, render, waitFor } from '@testing-library/react'; | ||
import { createVisualizationNode, IVisualizationNode } from '../../../../models'; | ||
import { ItemDeleteStep } from './ItemDeleteStep'; | ||
import { ActionConfirmationModalContext } from '../../../../providers/action-confirmation-modal.provider'; | ||
|
||
describe('ItemDeleteStep', () => { | ||
const vizNode = createVisualizationNode('test', {}); | ||
const mockVizNode = { | ||
removeChild: jest.fn(), | ||
} as unknown as IVisualizationNode; | ||
|
||
const mockDeleteModalContext = { | ||
actionConfirmation: jest.fn(), | ||
}; | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should render delete ContextMenuItem', () => { | ||
const { container } = render(<ItemDeleteStep vizNode={vizNode} loadActionConfirmationModal={false} />); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it('should open delete confirmation modal on click', async () => { | ||
const wrapper = render( | ||
<ActionConfirmationModalContext.Provider value={mockDeleteModalContext}> | ||
<ItemDeleteStep vizNode={vizNode} loadActionConfirmationModal={true} /> | ||
</ActionConfirmationModalContext.Provider>, | ||
); | ||
|
||
fireEvent.click(wrapper.getByText('Delete')); | ||
|
||
expect(mockDeleteModalContext.actionConfirmation).toHaveBeenCalledWith({ | ||
title: 'Permanently delete step?', | ||
text: 'Step and its children will be lost.', | ||
}); | ||
}); | ||
|
||
it('should call removechild if deletion is confirmed', async () => { | ||
mockDeleteModalContext.actionConfirmation.mockResolvedValueOnce(true); | ||
const wrapper = render( | ||
<ActionConfirmationModalContext.Provider value={mockDeleteModalContext}> | ||
<ItemDeleteStep vizNode={mockVizNode} loadActionConfirmationModal={true} /> | ||
</ActionConfirmationModalContext.Provider>, | ||
); | ||
fireEvent.click(wrapper.getByText('Delete')); | ||
|
||
await waitFor(() => { | ||
expect(mockVizNode.removeChild).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
packages/ui/src/components/Visualization/Custom/ContextMenu/ItemReplaceStep.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { fireEvent, render } from '@testing-library/react'; | ||
import { createVisualizationNode } from '../../../../models'; | ||
import { ActionConfirmationModalContext } from '../../../../providers/action-confirmation-modal.provider'; | ||
import { ItemReplaceStep } from './ItemReplaceStep'; | ||
import { EntitiesContext } from '../../../../providers/entities.provider'; | ||
import { CamelRouteResource } from '../../../../models/camel/camel-route-resource'; | ||
|
||
describe('ItemReplaceStep', () => { | ||
const vizNode = createVisualizationNode('test', {}); | ||
|
||
const camelResource = new CamelRouteResource(); | ||
const mockEntitiesContext = { | ||
camelResource, | ||
entities: camelResource.getEntities(), | ||
visualEntities: camelResource.getVisualEntities(), | ||
currentSchemaType: camelResource.getType(), | ||
updateSourceCodeFromEntities: jest.fn(), | ||
updateEntitiesFromCamelResource: jest.fn(), | ||
setCurrentSchemaType: jest.fn(), | ||
}; | ||
|
||
const mockReplaceModalContext = { | ||
actionConfirmation: jest.fn(), | ||
}; | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should render replace ContextMenuItem', () => { | ||
const { container } = render(<ItemReplaceStep vizNode={vizNode} loadActionConfirmationModal={false} />); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it('should open replace confirmation modal on click', async () => { | ||
const wrapper = render( | ||
<EntitiesContext.Provider value={mockEntitiesContext}> | ||
<ActionConfirmationModalContext.Provider value={mockReplaceModalContext}> | ||
<ItemReplaceStep vizNode={vizNode} loadActionConfirmationModal={true} /> | ||
</ActionConfirmationModalContext.Provider> | ||
</EntitiesContext.Provider>, | ||
); | ||
|
||
fireEvent.click(wrapper.getByText('Replace')); | ||
|
||
expect(mockReplaceModalContext.actionConfirmation).toHaveBeenCalledWith({ | ||
title: 'Replace step?', | ||
text: 'Step and its children will be lost.', | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.