diff --git a/__tests__/components/NotificationList.test.jsx b/__tests__/components/NotificationList.test.jsx
index bbe6a912dc..893f7a58a0 100644
--- a/__tests__/components/NotificationList.test.jsx
+++ b/__tests__/components/NotificationList.test.jsx
@@ -43,7 +43,7 @@ describe('', () => {
).find('Notifications');
- wrapper.instance().toggleSuccess(1, true);
+ wrapper.instance().toggleNotification(1, true, 'success');
expect(spy).toHaveBeenCalledWith(1, true);
});
test('post success makes request and updates state properly', async () => {
@@ -79,7 +79,7 @@ describe('', () => {
).find('Notifications');
- wrapper.instance().toggleError(1, true);
+ wrapper.instance().toggleNotification(1, true, 'error');
expect(spy).toHaveBeenCalledWith(1, true);
});
test('post error makes request and updates state properly', async () => {
diff --git a/__tests__/components/NotificationListItem.test.jsx b/__tests__/components/NotificationListItem.test.jsx
index d184b0a28e..f162782338 100644
--- a/__tests__/components/NotificationListItem.test.jsx
+++ b/__tests__/components/NotificationListItem.test.jsx
@@ -26,78 +26,70 @@ describe('', () => {
});
test('handles success click when toggle is on', () => {
- const successToggleClickSpy = jest.spyOn(NotificationListItem.prototype, 'successToggleClick');
- const toggleSuccessPropFn = jest.fn();
+ const toggleNotification = jest.fn();
wrapper = mount(
);
wrapper.find('Switch').first().find('input').simulate('change');
- expect(successToggleClickSpy).toHaveBeenCalledWith(true);
- expect(toggleSuccessPropFn).toHaveBeenCalledWith(9000, true);
+ expect(toggleNotification).toHaveBeenCalledWith(9000, true, 'success');
});
test('handles success click when toggle is off', () => {
- const successToggleClickSpy = jest.spyOn(NotificationListItem.prototype, 'successToggleClick');
- const toggleSuccessPropFn = jest.fn();
+ const toggleNotification = jest.fn();
wrapper = mount(
);
wrapper.find('Switch').first().find('input').simulate('change');
- expect(successToggleClickSpy).toHaveBeenCalledWith(false);
- expect(toggleSuccessPropFn).toHaveBeenCalledWith(9000, false);
+ expect(toggleNotification).toHaveBeenCalledWith(9000, false, 'success');
});
test('handles error click when toggle is on', () => {
- const errorToggleClickSpy = jest.spyOn(NotificationListItem.prototype, 'errorToggleClick');
- const toggleErrorPropFn = jest.fn();
+ const toggleNotification = jest.fn();
wrapper = mount(
);
wrapper.find('Switch').at(1).find('input').simulate('change');
- expect(errorToggleClickSpy).toHaveBeenCalledWith(true);
- expect(toggleErrorPropFn).toHaveBeenCalledWith(9000, true);
+ expect(toggleNotification).toHaveBeenCalledWith(9000, true, 'error');
});
test('handles error click when toggle is off', () => {
- const errorToggleClickSpy = jest.spyOn(NotificationListItem.prototype, 'errorToggleClick');
- const toggleErrorPropFn = jest.fn();
+ const toggleNotification = jest.fn();
wrapper = mount(
);
wrapper.find('Switch').at(1).find('input').simulate('change');
- expect(errorToggleClickSpy).toHaveBeenCalledWith(false);
- expect(toggleErrorPropFn).toHaveBeenCalledWith(9000, false);
+ expect(toggleNotification).toHaveBeenCalledWith(9000, false, 'error');
});
});
diff --git a/__tests__/pages/Organizations/screens/Organization/OrganizationNotifications.jsx b/__tests__/pages/Organizations/screens/Organization/OrganizationNotifications.jsx
new file mode 100644
index 0000000000..9716eadf8a
--- /dev/null
+++ b/__tests__/pages/Organizations/screens/Organization/OrganizationNotifications.jsx
@@ -0,0 +1,58 @@
+import React from 'react';
+import { mount } from 'enzyme';
+import { MemoryRouter } from 'react-router-dom';
+import OrganizationNotifications from '../../../../../src/pages/Organizations/screens/Organization/OrganizationNotifications';
+
+describe('', () => {
+ test('initially renders succesfully', () => {
+ mount(
+
+
+
+ );
+ });
+ test('handles api requests', () => {
+ const getOrganizationNotifications = jest.fn();
+ const getOrganizationNotificationSuccess = jest.fn();
+ const getOrganizationNotificationError = jest.fn();
+ const createOrganizationNotificationSuccess = jest.fn();
+ const createOrganizationNotificationError = jest.fn();
+ const wrapper = mount(
+
+
+
+ ).find('OrganizationNotifications');
+ wrapper.instance().getOrgNotifications(1, { foo: 'bar' });
+ expect(getOrganizationNotifications).toHaveBeenCalledWith(1, { foo: 'bar' });
+ wrapper.instance().getOrgNotificationSuccess(1, { foo: 'bar' });
+ expect(getOrganizationNotificationSuccess).toHaveBeenCalledWith(1, { foo: 'bar' });
+ wrapper.instance().getOrgNotificationError(1, { foo: 'bar' });
+ expect(getOrganizationNotificationError).toHaveBeenCalledWith(1, { foo: 'bar' });
+ wrapper.instance().createOrgNotificationSuccess(1, { id: 2 });
+ expect(createOrganizationNotificationSuccess).toHaveBeenCalledWith(1, { id: 2 });
+ wrapper.instance().createOrgNotificationError(1, { id: 2 });
+ expect(createOrganizationNotificationError).toHaveBeenCalledWith(1, { id: 2 });
+ });
+});
diff --git a/src/components/NotificationsList/NotificationListItem.jsx b/src/components/NotificationsList/NotificationListItem.jsx
index caf95b9998..9535a4c1e4 100644
--- a/src/components/NotificationsList/NotificationListItem.jsx
+++ b/src/components/NotificationsList/NotificationListItem.jsx
@@ -10,31 +10,15 @@ import {
} from '@patternfly/react-core';
class NotificationListItem extends React.Component {
- constructor (props) {
- super(props);
- this.errorToggleClick = this.errorToggleClick.bind(this);
- this.successToggleClick = this.successToggleClick.bind(this);
- }
-
- errorToggleClick (flag) {
- const { itemId, toggleError } = this.props;
- toggleError(itemId, flag);
- }
-
- successToggleClick (flag) {
- const { itemId, toggleSuccess } = this.props;
- toggleSuccess(itemId, flag);
- }
-
render () {
const {
itemId,
name,
notificationType,
detailUrl,
- parentBreadcrumb,
successTurnedOn,
- errorTurnedOn
+ errorTurnedOn,
+ toggleNotification
} = this.props;
const capText = {
@@ -49,8 +33,7 @@ class NotificationListItem extends React.Component {
{name}
@@ -69,13 +52,13 @@ class NotificationListItem extends React.Component {
this.successToggleClick(successTurnedOn)}
+ onChange={() => toggleNotification(itemId, successTurnedOn, 'success')}
aria-label={i18n._(t`Notification success toggle`)}
/>
this.errorToggleClick(errorTurnedOn)}
+ onChange={() => toggleNotification(itemId, errorTurnedOn, 'error')}
aria-label={i18n._(t`Notification failure toggle`)}
/>
diff --git a/src/components/NotificationsList/Notifications.list.jsx b/src/components/NotificationsList/Notifications.list.jsx
index 695b672c02..5b3cbb8635 100644
--- a/src/components/NotificationsList/Notifications.list.jsx
+++ b/src/components/NotificationsList/Notifications.list.jsx
@@ -56,8 +56,7 @@ class Notifications extends Component {
this.onSetPage = this.onSetPage.bind(this);
this.onSelectAll = this.onSelectAll.bind(this);
this.onSelect = this.onSelect.bind(this);
- this.toggleError = this.toggleError.bind(this);
- this.toggleSuccess = this.toggleSuccess.bind(this);
+ this.toggleNotification = this.toggleNotification.bind(this);
this.updateUrl = this.updateUrl.bind(this);
this.postToError = this.postToError.bind(this);
this.postToSuccess = this.postToSuccess.bind(this);
@@ -131,12 +130,12 @@ class Notifications extends Component {
}
};
- toggleError = (id, isCurrentlyOn) => {
- this.postToError(id, isCurrentlyOn);
- };
-
- toggleSuccess = (id, isCurrentlyOn) => {
- this.postToSuccess(id, isCurrentlyOn);
+ toggleNotification = (id, isCurrentlyOn, status) => {
+ if (status === 'success') {
+ this.postToSuccess(id, isCurrentlyOn);
+ } else if (status === 'error') {
+ this.postToError(id, isCurrentlyOn);
+ }
};
updateUrl (queryParams) {
@@ -293,8 +292,6 @@ class Notifications extends Component {
successTemplateIds,
errorTemplateIds
} = this.state;
- const { match } = this.props;
- const parentBreadcrumb = { name: i18nMark('Organizations'), url: match.url };
return (
@@ -335,13 +332,11 @@ class Notifications extends Component {
name={o.name}
notificationType={o.notification_type}
detailUrl={`notifications/${o.id}`}
- parentBreadcrumb={parentBreadcrumb}
isSelected={selected.includes(o.id)}
onSelect={() => this.onSelect(o.id)}
+ toggleNotification={this.toggleNotification}
errorTurnedOn={errorTemplateIds.includes(o.id)}
- toggleError={this.toggleError}
successTurnedOn={successTemplateIds.includes(o.id)}
- toggleSuccess={this.toggleSuccess}
/>
))}
diff --git a/src/pages/Organizations/screens/Organization/OrganizationDetail.jsx b/src/pages/Organizations/screens/Organization/OrganizationDetail.jsx
index 54c8bc79a6..4c9b4727e7 100644
--- a/src/pages/Organizations/screens/Organization/OrganizationDetail.jsx
+++ b/src/pages/Organizations/screens/Organization/OrganizationDetail.jsx
@@ -12,7 +12,7 @@ import {
Route
} from 'react-router-dom';
-import NotificationsList from '../../../../components/NotificationsList/Notifications.list';
+import OrganizationNotifications from './OrganizationNotifications';
import Tab from '../../../../components/Tabs/Tab';
import Tabs from '../../../../components/Tabs/Tabs';
@@ -54,12 +54,8 @@ const OrganizationDetail = ({
switch (currentTab) {
case 'notifications':
relatedTemplate = (
- api.getOrganizationNotifications(id, reqParams)}
- getSuccess={(id, reqParams) => api.getOrganizationNotificationSuccess(id, reqParams)}
- getError={(id, reqParams) => api.getOrganizationNotificationError(id, reqParams)}
- postSuccess={(id, data) => api.createOrganizationNotificationSuccess(id, data)}
- postError={(id, data) => api.createOrganizationNotificationError(id, data)}
+
+ );
+ }
+}
+
+export default OrganizationNotifications;