Skip to content

Commit a7eb54b

Browse files
committed
Merge pull request #973
* refactor(32892): add a prompt to the props * refactor(32892): redesign the delete modal * refactor(32892): update translations * test(32892): add tests * test(32892): fix tests
1 parent 70cd5e4 commit a7eb54b

File tree

5 files changed

+88
-8
lines changed

5 files changed

+88
-8
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import ConfirmationDialog from './ConfirmationDialog'
2+
3+
describe('ConfirmationDialog', () => {
4+
beforeEach(() => {
5+
cy.viewport(800, 600)
6+
})
7+
8+
it.only('should render properly', () => {
9+
const onClose = cy.stub().as('onClose')
10+
const onSubmit = cy.stub().as('onSubmit')
11+
cy.mountWithProviders(
12+
<ConfirmationDialog
13+
isOpen={true}
14+
onClose={onClose}
15+
onSubmit={onSubmit}
16+
header="Hello"
17+
message="The nice long message"
18+
prompt="Are you sure?"
19+
/>
20+
)
21+
22+
cy.get('header').should('have.text', 'Hello')
23+
cy.getByTestId('confirmation-message').should('have.text', 'The nice long message')
24+
cy.getByTestId('confirmation-prompt').should('have.text', 'Are you sure?')
25+
cy.getByTestId('confirmation-submit').should('have.text', 'Delete')
26+
cy.getByTestId('confirmation-cancel').should('have.text', 'Cancel')
27+
28+
cy.get('@onClose').should('have.not.been.called')
29+
cy.getByTestId('confirmation-cancel').click()
30+
cy.get('@onClose').should('have.been.called')
31+
32+
cy.get('@onSubmit').should('have.not.been.called')
33+
cy.getByTestId('confirmation-submit').click()
34+
cy.get('@onSubmit').should('have.been.called')
35+
})
36+
37+
it.only('should render alternative submit', () => {
38+
cy.mountWithProviders(
39+
<ConfirmationDialog
40+
isOpen={true}
41+
onClose={cy.stub}
42+
header="Hello"
43+
message="The nice long message"
44+
action="Alternative Text"
45+
/>
46+
)
47+
48+
cy.get('header').should('have.text', 'Hello')
49+
cy.getByTestId('confirmation-submit').should('have.text', 'Alternative Text')
50+
})
51+
52+
it('should be accessible ', () => {
53+
cy.injectAxe()
54+
cy.mountWithProviders(
55+
<ConfirmationDialog isOpen={true} onClose={cy.stub} header="Hello" message="sssss" prompt="sss" />
56+
)
57+
cy.get('header').should('be.visible')
58+
59+
cy.checkAccessibility()
60+
})
61+
})

hivemq-edge-frontend/src/components/Modal/ConfirmationDialog.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
AlertDialogHeader,
99
AlertDialogOverlay,
1010
Button,
11+
Text,
1112
} from '@chakra-ui/react'
1213
import { useTranslation } from 'react-i18next'
1314
import type { FocusableElement } from '@chakra-ui/utils'
@@ -17,11 +18,20 @@ interface ConfirmationDialogProps {
1718
onClose: () => void
1819
header: string
1920
message: string
21+
prompt?: string
2022
action?: string | null
2123
onSubmit?: () => void
2224
}
2325

24-
const ConfirmationDialog: FC<ConfirmationDialogProps> = ({ isOpen, onClose, header, message, action, onSubmit }) => {
26+
const ConfirmationDialog: FC<ConfirmationDialogProps> = ({
27+
isOpen,
28+
onClose,
29+
header,
30+
message,
31+
prompt,
32+
action,
33+
onSubmit,
34+
}) => {
2535
const { t } = useTranslation()
2636
const cancelRef = useRef<HTMLButtonElement>()
2737

@@ -33,7 +43,10 @@ const ConfirmationDialog: FC<ConfirmationDialogProps> = ({ isOpen, onClose, head
3343
{header}
3444
</AlertDialogHeader>
3545

36-
<AlertDialogBody>{message}</AlertDialogBody>
46+
<AlertDialogBody>
47+
<Text data-testid="confirmation-message">{message}</Text>
48+
{prompt && <Text data-testid="confirmation-prompt">{prompt}</Text>}
49+
</AlertDialogBody>
3750

3851
<AlertDialogFooter>
3952
<Button ref={cancelRef as LegacyRef<HTMLButtonElement>} onClick={onClose} data-testid="confirmation-cancel">

hivemq-edge-frontend/src/extensions/datahub/components/pages/DataHubListings.spec.cy.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ describe('DataHubListings', () => {
5353
cy.getByTestId('list-action-delete').click()
5454

5555
cy.get("[role='alertdialog']").as('modal').should('be.visible')
56-
cy.get('@modal').find('header').should('have.text', 'Delete Item')
57-
cy.get('@modal').find('header').should('have.text', 'Delete Item')
56+
cy.get('@modal').find('header').should('have.text', 'Delete Schema')
5857
cy.get('@modal').find('footer').find('button').as('actions')
5958
cy.get('@actions').eq(0).click()
6059
cy.get("[role='alertdialog']").should('not.exist')

hivemq-edge-frontend/src/extensions/datahub/components/pages/DataHubListings.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ const DataHubListings: FC = () => {
9494
isOpen={isConfirmDeleteOpen}
9595
onClose={handleConfirmOnClose}
9696
onSubmit={handleConfirmOnSubmit}
97-
message={t('Listings.modal.delete.message')}
98-
header={t('Listings.modal.delete.header')}
97+
header={t('Listings.modal.delete.header', { context: deleteItem?.type })}
98+
message={t('Listings.modal.delete.message', { context: deleteItem?.type })}
99+
prompt={t('Listings.modal.delete.prompt')}
99100
/>
100101
</Tabs>
101102
)

hivemq-edge-frontend/src/extensions/datahub/locales/en/datahub.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,14 @@
5656
},
5757
"modal": {
5858
"delete": {
59-
"header": "Delete Item",
60-
"message": "Are you sure? You can't undo this action afterward."
59+
"header_SCHEMA": "Delete Schema",
60+
"header_FUNCTION": "Delete Script",
61+
"header_DATA_POLICY": "Delete Data Policy",
62+
"header_BEHAVIOR_POLICY": "Delete Behaviour Policy",
63+
"message": "The policy will be deleted.",
64+
"message_SCHEMA": "Schemas are internally stored as a bundle; every version of the schema will be deleted.",
65+
"message_FUNCTION": "Scripts are internally stored as a bundle; every version of the script will be deleted.",
66+
"prompt": "You can't undo this action afterward. Are you sure?"
6167
}
6268
},
6369
"policy": {

0 commit comments

Comments
 (0)