-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(content-explorer): Migrate deleteConfirmationDialog
- Loading branch information
1 parent
1850977
commit f09447c
Showing
12 changed files
with
201 additions
and
111 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
README.md | ||
flow-typed/* |
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
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
src/elements/content-explorer/DeleteConfirmationDialog.js.flow
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,51 @@ | ||
// @flow | ||
import * as React from 'react'; | ||
import { FormattedMessage, useIntl } from 'react-intl'; | ||
import { Modal } from '@box/blueprint-web'; | ||
import type { BoxItem } from '../../common/types/core'; | ||
|
||
import { TYPE_FOLDER } from '../../constants'; | ||
|
||
import messages from '../common/messages'; | ||
|
||
type Props = { | ||
isLoading: boolean, | ||
isOpen: boolean, | ||
item: BoxItem, | ||
onCancel: any, | ||
onDelete: any, | ||
parentElement: HTMLElement, | ||
}; | ||
|
||
const DeleteConfirmationDialog = ({ isOpen, onDelete, onCancel, item, isLoading, parentElement }: Props) => { | ||
const { formatMessage } = useIntl(); | ||
const message = item.type === TYPE_FOLDER ? messages.deleteDialogFolderText : messages.deleteDialogFileText; | ||
return ( | ||
<Modal onOpenChange={onCancel} open={isOpen}> | ||
<Modal.Content | ||
aria-label={formatMessage(messages.deleteDialogLabel)} | ||
className="bce-DeleteConfirmationDialog" | ||
container={parentElement} | ||
size="small" | ||
> | ||
<Modal.Body> | ||
<FormattedMessage {...message} values={{ name: item.name }} /> | ||
</Modal.Body> | ||
<Modal.Footer> | ||
<Modal.Footer.SecondaryButton disabled={isLoading} onClick={onCancel}> | ||
{formatMessage(messages.cancel)} | ||
</Modal.Footer.SecondaryButton> | ||
<Modal.Footer.PrimaryButton | ||
loading={isLoading} | ||
loadingAriaLabel={formatMessage(messages.loading)} | ||
onClick={onDelete} | ||
> | ||
{formatMessage(messages.delete)} | ||
</Modal.Footer.PrimaryButton> | ||
</Modal.Footer> | ||
</Modal.Content> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default DeleteConfirmationDialog; |
This file was deleted.
Oops, something went wrong.
58 changes: 58 additions & 0 deletions
58
src/elements/content-explorer/DeleteConfirmationDialog.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,58 @@ | ||
import * as React from 'react'; | ||
import { FormattedMessage, useIntl } from 'react-intl'; | ||
import { Modal } from '@box/blueprint-web'; | ||
import type { BoxItem } from '../../common/types/core'; | ||
|
||
import { TYPE_FOLDER } from '../../constants'; | ||
|
||
import messages from '../common/messages'; | ||
|
||
export interface DeleteConfirmationDialogProps { | ||
isLoading: boolean; | ||
isOpen: boolean; | ||
item: BoxItem; | ||
onCancel: () => void; | ||
onDelete: () => void; | ||
parentElement: HTMLElement; | ||
} | ||
|
||
const DeleteConfirmationDialog = ({ | ||
isLoading, | ||
isOpen, | ||
item, | ||
onCancel, | ||
onDelete, | ||
parentElement, | ||
}: DeleteConfirmationDialogProps) => { | ||
const { formatMessage } = useIntl(); | ||
const message = item.type === TYPE_FOLDER ? messages.deleteDialogFolderText : messages.deleteDialogFileText; | ||
return ( | ||
<Modal onOpenChange={onCancel} open={isOpen}> | ||
<Modal.Content | ||
aria-label={formatMessage(messages.deleteDialogLabel)} | ||
container={parentElement} | ||
size="small" | ||
> | ||
<Modal.Header>{formatMessage(messages.deleteDialogHeader)}</Modal.Header> | ||
<Modal.Body> | ||
<FormattedMessage {...message} values={{ name: item.name }} /> | ||
</Modal.Body> | ||
<Modal.Footer> | ||
<Modal.Footer.SecondaryButton disabled={isLoading} onClick={onCancel}> | ||
{formatMessage(messages.cancel)} | ||
</Modal.Footer.SecondaryButton> | ||
<Modal.Footer.PrimaryButton | ||
loading={isLoading} | ||
loadingAriaLabel={formatMessage(messages.loading)} | ||
onClick={onDelete} | ||
> | ||
{formatMessage(messages.delete)} | ||
</Modal.Footer.PrimaryButton> | ||
</Modal.Footer> | ||
<Modal.Close aria-label={formatMessage(messages.close)} /> | ||
</Modal.Content> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default DeleteConfirmationDialog; |
67 changes: 67 additions & 0 deletions
67
src/elements/content-explorer/__tests__/DeleteConfirmation.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,67 @@ | ||
import * as React from 'react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { render, screen } from '../../../test-utils/testing-library'; | ||
import DeleteConfirmationDialog, { DeleteConfirmationDialogProps } from '../DeleteConfirmationDialog'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
import { TYPE_FOLDER } from '../../../constants'; | ||
|
||
const mockItem = { type: 'pdf', name: 'Test File' }; | ||
const mockFolderItem = { type: TYPE_FOLDER, name: 'Test Folder' }; | ||
const mockOnCancel = jest.fn(); | ||
const mockOnDelete = jest.fn(); | ||
|
||
const defaultProps = { | ||
errorCode: '', | ||
isLoading: false, | ||
isOpen: false, | ||
item: mockItem, | ||
onCancel: jest.fn(), | ||
onDelete: jest.fn(), | ||
parentElement: document.body, | ||
}; | ||
|
||
const renderComponent = (props: Partial<DeleteConfirmationDialogProps>) => | ||
render(<DeleteConfirmationDialog {...defaultProps} {...props} />); | ||
|
||
describe('elements/content-explorer/DeleteConfirmationDialog', () => { | ||
test('should render the dialog with file message', async () => { | ||
renderComponent({ isOpen: true }); | ||
|
||
expect(await screen.findByText('Are you sure you want to delete Test File?')).toBeInTheDocument(); | ||
}); | ||
|
||
test('should render the dialog with folder message', async () => { | ||
renderComponent({ isOpen: true, item: mockFolderItem }); | ||
|
||
expect( | ||
await screen.findByText('Are you sure you want to delete Test Folder and all its contents?'), | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
test('should call onCancel when cancel button is clicked', async () => { | ||
renderComponent({ isOpen: true, onCancel: mockOnCancel }); | ||
|
||
const cancelButton = screen.getByRole('button', { name: 'Cancel' }); | ||
await userEvent.click(cancelButton); | ||
expect(mockOnCancel).toBeCalledTimes(1); | ||
}); | ||
|
||
test('should call onDelete when delete button is clicked', async () => { | ||
renderComponent({ isOpen: true, onDelete: mockOnDelete }); | ||
|
||
const deleteButton = screen.getByRole('button', { name: 'Delete' }); | ||
await userEvent.click(deleteButton); | ||
expect(mockOnDelete).toBeCalledTimes(1); | ||
}); | ||
|
||
test('should disable buttons when isLoading is true', () => { | ||
renderComponent({ isOpen: true, isLoading: true }); | ||
|
||
const cancelButton = screen.getByRole('button', { name: 'Cancel' }); | ||
expect(cancelButton).toBeDisabled(); | ||
const loadingIndicator = screen.getByRole('status', { name: 'Loading' }); | ||
expect(loadingIndicator).toBeInTheDocument(); | ||
}); | ||
}); |
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