-
Notifications
You must be signed in to change notification settings - Fork 8
feat(HMS-2994): delete domain confirmation #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
avisiedo
merged 1 commit into
podengo-project:main
from
avisiedo:hms-2994-delete-confirm
Apr 26, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
@import '~@redhat-cloud-services/frontend-components-utilities/styles/variables'; |
50 changes: 50 additions & 0 deletions
50
src/Components/ConfirmDeleteDomain/ConfirmDeleteDomain.test.tsx
This file contains hidden or 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,50 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import ConfirmDeleteDomain from './ConfirmDeleteDomain'; | ||
import '@testing-library/jest-dom'; | ||
import { Domain } from '../../Api'; | ||
|
||
const domain: Domain = { | ||
domain_name: 'mydomain.test', | ||
} as unknown as Domain; | ||
|
||
test('expect empty when isOpen is false', () => { | ||
const root = render(<ConfirmDeleteDomain domain={domain} isOpen={false} />); | ||
expect(root.container).toBeEmptyDOMElement(); | ||
}); | ||
|
||
test('expect modal displayed', () => { | ||
render(<ConfirmDeleteDomain domain={domain} isOpen={true} />); | ||
expect(screen.getByRole('heading')).toHaveTextContent(/^Warning alert:Delete identity domain registration\?$/); | ||
expect(screen.getByRole('button', { name: 'Close' })).toHaveTextContent(/^$/); | ||
expect(screen.getByRole('button', { name: 'Delete' })).toHaveTextContent(/^Delete$/); | ||
expect(screen.getByRole('button', { name: 'Cancel' })).toHaveTextContent(/^Cancel$/); | ||
}); | ||
|
||
test('expect handler onDelete to be called', () => { | ||
// given | ||
const confirmHandler = jest.fn(); | ||
const cancelHandler = jest.fn(); | ||
render(<ConfirmDeleteDomain domain={domain} isOpen={true} onDelete={confirmHandler} onCancel={cancelHandler} />); | ||
|
||
// when the OK button is clicked | ||
screen.getByRole('button', { name: 'Delete' }).click(); | ||
|
||
// then the confirmHandler should be called with the domain as argument and cancelHandler should not | ||
expect(confirmHandler).toBeCalledWith(domain); | ||
expect(cancelHandler).toBeCalledTimes(0); | ||
}); | ||
|
||
test('expect handler onCancel to be called', () => { | ||
// given | ||
const confirmHandler = jest.fn(); | ||
const cancelHandler = jest.fn(); | ||
render(<ConfirmDeleteDomain domain={domain} isOpen={true} onDelete={confirmHandler} onCancel={cancelHandler} />); | ||
|
||
// when the OK button is clicked | ||
screen.getByRole('button', { name: 'Cancel' }).click(); | ||
|
||
// then the confirmHandler should be called with the domain as argument and cancelHandler should not | ||
expect(cancelHandler).toBeCalledTimes(1); | ||
expect(confirmHandler).toBeCalledTimes(0); | ||
}); |
44 changes: 44 additions & 0 deletions
44
src/Components/ConfirmDeleteDomain/ConfirmDeleteDomain.tsx
This file contains hidden or 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,44 @@ | ||
import { Button, Modal } from '@patternfly/react-core'; | ||
import './ConfirmDeleteDomain.scss'; | ||
import React from 'react'; | ||
import { Domain } from '../../Api/api'; | ||
|
||
interface ConfirmDeleteDomainProps { | ||
domain?: Domain; | ||
isOpen?: boolean; | ||
onDelete?: (domain?: Domain) => void; | ||
onCancel?: () => void; | ||
} | ||
|
||
/** | ||
* Modal dialog to confirm a domain deletion. | ||
* | ||
* @param props the props given by the smart component. | ||
*/ | ||
const ConfirmDeleteDomain: React.FC<ConfirmDeleteDomainProps> = (props) => { | ||
const onDeleteWrapper = () => { | ||
props.onDelete && props.onDelete(props.domain); | ||
}; | ||
return ( | ||
<Modal | ||
isOpen={props.isOpen} | ||
titleIconVariant={'warning'} | ||
variant="small" | ||
title="Delete identity domain registration?" | ||
ouiaId="ModalConfirmDeletion" | ||
onClose={props.onCancel} | ||
actions={[ | ||
<Button key="delete" variant="danger" onClick={onDeleteWrapper} ouiaId="ButtonModalConfirmDeletionDelete"> | ||
Delete | ||
</Button>, | ||
<Button key="cancel" variant="link" onClick={props.onCancel} ouiaId="ButtonModalConfirmDeletionCancel"> | ||
Cancel | ||
</Button>, | ||
]} | ||
> | ||
No new host enrollment from HCC will be allowed on <b>{props.domain?.title || ''}</b> domain after registration deletion. | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default ConfirmDeleteDomain; |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.