diff --git a/awx/ui_next/src/components/DeleteButton/DeleteButton.jsx b/awx/ui_next/src/components/DeleteButton/DeleteButton.jsx
index 760e94f62e..2810854e64 100644
--- a/awx/ui_next/src/components/DeleteButton/DeleteButton.jsx
+++ b/awx/ui_next/src/components/DeleteButton/DeleteButton.jsx
@@ -70,56 +70,55 @@ function DeleteButton({
>
{children || i18n._(t`Delete`)}
- {!deleteMessageError && (
- toggleModal(false)}
- actions={[
- ,
- ,
- ]}
- >
- {i18n._(t`Are you sure you want to delete:`)}
-
- {name}
- {Object.values(deleteDetails).length > 0 && (
-
- {deleteMessage}
-
- {Object.entries(deleteDetails).map(([key, value]) => (
-
- {key} {value}
-
- ))}
-
- }
- />
- )}
-
- )}
+
+ toggleModal(false)}
+ actions={[
+ ,
+ ,
+ ]}
+ >
+ {i18n._(t`Are you sure you want to delete:`)}
+
+ {name}
+ {Object.values(deleteDetails).length > 0 && (
+
+ {deleteMessage}
+
+ {Object.entries(deleteDetails).map(([key, value]) => (
+
+ {key} {value}
+
+ ))}
+
+ }
+ />
+ )}
+
>
);
}
diff --git a/awx/ui_next/src/components/DeleteButton/DeleteButton.test.jsx b/awx/ui_next/src/components/DeleteButton/DeleteButton.test.jsx
index 2bc6b2f243..966fd9b74b 100644
--- a/awx/ui_next/src/components/DeleteButton/DeleteButton.test.jsx
+++ b/awx/ui_next/src/components/DeleteButton/DeleteButton.test.jsx
@@ -38,7 +38,6 @@ describe('', () => {
);
});
- // expect(wrapper.find('Modal')).toHaveLength(0);
await act(async () => {
wrapper.find('button').prop('onClick')();
});
diff --git a/awx/ui_next/src/components/PaginatedDataList/ToolbarDeleteButton.jsx b/awx/ui_next/src/components/PaginatedDataList/ToolbarDeleteButton.jsx
index 8819d8871e..2f5d4e4ac0 100644
--- a/awx/ui_next/src/components/PaginatedDataList/ToolbarDeleteButton.jsx
+++ b/awx/ui_next/src/components/PaginatedDataList/ToolbarDeleteButton.jsx
@@ -112,7 +112,11 @@ function ToolbarDeleteButton({
};
const toggleModal = async isOpen => {
- if (itemsToDelete.length === 1 && deleteDetailsRequests?.length > 0) {
+ if (
+ isOpen &&
+ itemsToDelete.length === 1 &&
+ deleteDetailsRequests?.length > 0
+ ) {
const { results, error } = await getRelatedResourceDeleteCounts(
deleteDetailsRequests
);
@@ -195,7 +199,7 @@ function ToolbarDeleteButton({
variant="secondary"
aria-label={i18n._(t`Delete`)}
onClick={() => toggleModal(true)}
- isAriaDisabled={isDisabled}
+ isDisabled={isDisabled}
>
{i18n._(t`Delete`)}
@@ -203,7 +207,7 @@ function ToolbarDeleteButton({
)}
- {isModalOpen && !deleteMessageError && (
+ {isModalOpen && (
', () => {
beforeEach(() => {
deleteDetailsRequests = [
{
- label: 'job',
+ label: 'Workflow Job Template Node',
request: CredentialsAPI.read.mockResolvedValue({ data: { count: 1 } }),
},
];
@@ -62,10 +62,55 @@ describe('', () => {
wrapper.find('button').prop('onClick')();
});
await waitForElement(wrapper, 'Modal', el => el.length > 0);
+ expect(CredentialsAPI.read).toBeCalled();
expect(wrapper.find('Modal')).toHaveLength(1);
+ expect(
+ wrapper.find('span[aria-label="Workflow Job Template Node: 1"]')
+ ).toHaveLength(1);
expect(wrapper.find('div[aria-label="Delete this?"]')).toHaveLength(1);
});
+ test('should open delete error modal', async () => {
+ const request = [
+ {
+ label: 'Workflow Job Template Node',
+ request: CredentialsAPI.read.mockRejectedValue(
+ new Error({
+ response: {
+ config: {
+ method: 'get',
+ url: '/api/v2/credentals',
+ },
+ data: 'An error occurred',
+ status: 403,
+ },
+ })
+ ),
+ },
+ ];
+ let wrapper;
+ await act(async () => {
+ wrapper = mountWithContexts(
+ {}}
+ itemsToDelete={[itemA]}
+ deleteDetailsRequests={request}
+ deleteMessage="Delete this?"
+ warningMessage="Are you sure to want to delete this"
+ />
+ );
+ });
+
+ expect(wrapper.find('Modal')).toHaveLength(0);
+ await act(async () => wrapper.find('button').simulate('click'));
+ await waitForElement(wrapper, 'Modal', el => el.length > 0);
+ expect(CredentialsAPI.read).toBeCalled();
+
+ wrapper.update();
+
+ expect(wrapper.find('AlertModal[title="Error!"]')).toHaveLength(1);
+ });
+
test('should invoke onDelete prop', () => {
const onDelete = jest.fn();
const wrapper = mountWithContexts(
diff --git a/awx/ui_next/src/components/PaginatedDataList/__snapshots__/ToolbarDeleteButton.test.jsx.snap b/awx/ui_next/src/components/PaginatedDataList/__snapshots__/ToolbarDeleteButton.test.jsx.snap
index bd772719cb..fc24195951 100644
--- a/awx/ui_next/src/components/PaginatedDataList/__snapshots__/ToolbarDeleteButton.test.jsx.snap
+++ b/awx/ui_next/src/components/PaginatedDataList/__snapshots__/ToolbarDeleteButton.test.jsx.snap
@@ -74,7 +74,7 @@ exports[` should render button 1`] = `
>