forked from inspirehep/inspirehep
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ui: connect delete button in new holdingpen
* ref: cern-sis/issues-inspire#533
- Loading branch information
1 parent
2db006d
commit a3a5bb2
Showing
9 changed files
with
487 additions
and
274 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
5 changes: 5 additions & 0 deletions
5
ui/src/holdingpen-new/components/DeleteWorkflow/DeleteWorkflow.less
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,5 @@ | ||
.delete-modal { | ||
.ant-modal-footer { | ||
border-top: none; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
ui/src/holdingpen-new/components/DeleteWorkflow/DeleteWorkflow.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,48 @@ | ||
import React, { useState } from 'react'; | ||
import { Button, Modal } from 'antd'; | ||
import { Action, ActionCreator } from 'redux'; | ||
|
||
import './DeleteWorkflow.less'; | ||
import { deleteWorkflow } from '../../../actions/holdingpen'; | ||
|
||
const DeleteWorkflow: React.FC<{ | ||
dispatch: ActionCreator<Action>; | ||
id: string; | ||
}> = ({ dispatch, id }) => { | ||
const [open, setOpen] = useState(false); | ||
|
||
const showModal = () => { | ||
setOpen(true); | ||
}; | ||
|
||
const hideModal = () => { | ||
setOpen(false); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Button className="font-white bg-error" onClick={showModal}> | ||
Delete | ||
</Button> | ||
<Modal | ||
title="Modal" | ||
open={open} | ||
onOk={() => { | ||
dispatch(deleteWorkflow(id)); | ||
hideModal(); | ||
}} | ||
onCancel={hideModal} | ||
okText="Confirm" | ||
cancelText="Cancel" | ||
className="delete-modal" | ||
> | ||
<p> | ||
Are you sure you want to delete workflow? This operation is | ||
unreversable. | ||
</p> | ||
</Modal> | ||
</> | ||
); | ||
}; | ||
|
||
export default DeleteWorkflow; |
56 changes: 56 additions & 0 deletions
56
ui/src/holdingpen-new/components/__tests__/DeleteWorkflow.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,56 @@ | ||
import React from 'react'; | ||
import { fireEvent, render, screen, waitFor } from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
import DeleteWorkflow from '../DeleteWorkflow/DeleteWorkflow'; | ||
|
||
jest.mock('../../../actions/holdingpen', () => ({ | ||
deleteWorkflow: jest.fn((id) => ({ | ||
type: 'HOLDINGPEN_DELETE_REQUEST', | ||
payload: id, | ||
})), | ||
})); | ||
|
||
describe('DeleteWorkflow component', () => { | ||
const mockDispatch = jest.fn(); | ||
const mockId = 'test-id'; | ||
|
||
beforeEach(() => { | ||
mockDispatch.mockClear(); | ||
}); | ||
|
||
it('should render delete button', () => { | ||
render(<DeleteWorkflow dispatch={mockDispatch} id={mockId} />); | ||
expect(screen.getByText('Delete')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should open the modal when the delete button is clicked', async () => { | ||
render(<DeleteWorkflow dispatch={mockDispatch} id={mockId} />); | ||
|
||
await waitFor(() => userEvent.click(screen.getByText('Delete'))); | ||
|
||
await waitFor(() => | ||
expect( | ||
screen.getByText( | ||
'Are you sure you want to delete workflow? This operation is unreversable.' | ||
) | ||
).toBeVisible() | ||
); | ||
}); | ||
|
||
it('should call dispatch with deleteWorkflow and close the modal on confirm', async () => { | ||
render(<DeleteWorkflow dispatch={mockDispatch} id={mockId} />); | ||
|
||
await waitFor(() => userEvent.click(screen.getByText('Delete'))); | ||
|
||
await waitFor(() => userEvent.click(screen.getByText('Confirm'))); | ||
|
||
await waitFor(() => | ||
expect(mockDispatch).toHaveBeenCalledWith({ | ||
type: 'HOLDINGPEN_DELETE_REQUEST', | ||
payload: mockId, | ||
}) | ||
); | ||
}); | ||
}); |
Oops, something went wrong.