mirror of
https://github.com/ansible/awx.git
synced 2026-02-18 03:30:02 -03:30
More cleanup based on pr feedback. Adds org notif list page and tests
This commit is contained in:
@@ -43,7 +43,7 @@ describe('<Notifications />', () => {
|
||||
</I18nProvider>
|
||||
</MemoryRouter>
|
||||
).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('<Notifications />', () => {
|
||||
</I18nProvider>
|
||||
</MemoryRouter>
|
||||
).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 () => {
|
||||
|
||||
@@ -26,78 +26,70 @@ describe('<NotificationListItem />', () => {
|
||||
});
|
||||
|
||||
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(
|
||||
<I18nProvider>
|
||||
<MemoryRouter>
|
||||
<NotificationListItem
|
||||
itemId={9000}
|
||||
successTurnedOn
|
||||
toggleSuccess={toggleSuccessPropFn}
|
||||
toggleNotification={toggleNotification}
|
||||
/>
|
||||
</MemoryRouter>
|
||||
</I18nProvider>
|
||||
);
|
||||
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(
|
||||
<I18nProvider>
|
||||
<MemoryRouter>
|
||||
<NotificationListItem
|
||||
itemId={9000}
|
||||
successTurnedOn={false}
|
||||
toggleSuccess={toggleSuccessPropFn}
|
||||
toggleNotification={toggleNotification}
|
||||
/>
|
||||
</MemoryRouter>
|
||||
</I18nProvider>
|
||||
);
|
||||
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(
|
||||
<I18nProvider>
|
||||
<MemoryRouter>
|
||||
<NotificationListItem
|
||||
itemId={9000}
|
||||
errorTurnedOn
|
||||
toggleError={toggleErrorPropFn}
|
||||
toggleNotification={toggleNotification}
|
||||
/>
|
||||
</MemoryRouter>
|
||||
</I18nProvider>
|
||||
);
|
||||
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(
|
||||
<I18nProvider>
|
||||
<MemoryRouter>
|
||||
<NotificationListItem
|
||||
itemId={9000}
|
||||
errorTurnedOn={false}
|
||||
toggleError={toggleErrorPropFn}
|
||||
toggleNotification={toggleNotification}
|
||||
/>
|
||||
</MemoryRouter>
|
||||
</I18nProvider>
|
||||
);
|
||||
wrapper.find('Switch').at(1).find('input').simulate('change');
|
||||
expect(errorToggleClickSpy).toHaveBeenCalledWith(false);
|
||||
expect(toggleErrorPropFn).toHaveBeenCalledWith(9000, false);
|
||||
expect(toggleNotification).toHaveBeenCalledWith(9000, false, 'error');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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('<OrganizationNotifications />', () => {
|
||||
test('initially renders succesfully', () => {
|
||||
mount(
|
||||
<MemoryRouter initialEntries={['/organizations/1']} initialIndex={0}>
|
||||
<OrganizationNotifications
|
||||
match={{ path: '/organizations/:id/notifications', url: '/organizations/1/notifications' }}
|
||||
location={{ search: '', pathname: '/organizations/1/notifications' }}
|
||||
params={{}}
|
||||
api={{
|
||||
getOrganizationNotifications: jest.fn(),
|
||||
getOrganizationNotificationSuccess: jest.fn(),
|
||||
getOrganizationNotificationError: jest.fn(),
|
||||
createOrganizationNotificationSuccess: jest.fn(),
|
||||
createOrganizationNotificationError: jest.fn()
|
||||
}}
|
||||
/>
|
||||
</MemoryRouter>
|
||||
);
|
||||
});
|
||||
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(
|
||||
<MemoryRouter initialEntries={['/organizations/1']} initialIndex={0}>
|
||||
<OrganizationNotifications
|
||||
match={{ path: '/organizations/:id/notifications', url: '/organizations/1/notifications' }}
|
||||
location={{ search: '', pathname: '/organizations/1/notifications' }}
|
||||
params={{}}
|
||||
api={{
|
||||
getOrganizationNotifications,
|
||||
getOrganizationNotificationSuccess,
|
||||
getOrganizationNotificationError,
|
||||
createOrganizationNotificationSuccess,
|
||||
createOrganizationNotificationError
|
||||
}}
|
||||
/>
|
||||
</MemoryRouter>
|
||||
).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 });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user