mirror of
https://github.com/ansible/awx.git
synced 2026-02-15 10:10:01 -03:30
fixes function naming to match our naming convention in the org. notifications.
This commit is contained in:
@@ -12,29 +12,29 @@ describe('<Notifications />', () => {
|
||||
<Notifications
|
||||
match={{ path: '/organizations/:id/?tab=notifications', url: '/organizations/:id/?tab=notifications' }}
|
||||
location={{ search: '', pathname: '/organizations/:id/?tab=notifications' }}
|
||||
getError={jest.fn()}
|
||||
getNotifications={jest.fn()}
|
||||
getSuccess={jest.fn()}
|
||||
postError={jest.fn()}
|
||||
postSuccess={jest.fn()}
|
||||
onReadError={jest.fn()}
|
||||
onReadNotifications={jest.fn()}
|
||||
onReadSuccess={jest.fn()}
|
||||
onCreateError={jest.fn()}
|
||||
onCreateSuccess={jest.fn()}
|
||||
/>
|
||||
</I18nProvider>
|
||||
</MemoryRouter>
|
||||
);
|
||||
});
|
||||
test('fetches notifications on mount', () => {
|
||||
const spy = jest.spyOn(Notifications.prototype, 'fetchNotifications');
|
||||
const spy = jest.spyOn(Notifications.prototype, 'readNotifications');
|
||||
mount(
|
||||
<MemoryRouter>
|
||||
<I18nProvider>
|
||||
<Notifications
|
||||
match={{ path: '/organizations/:id/?tab=notifications', url: '/organizations/:id/?tab=notifications' }}
|
||||
location={{ search: '', pathname: '/organizations/:id/?tab=notifications' }}
|
||||
getError={jest.fn()}
|
||||
getNotifications={jest.fn()}
|
||||
getSuccess={jest.fn()}
|
||||
postError={jest.fn()}
|
||||
postSuccess={jest.fn()}
|
||||
onReadError={jest.fn()}
|
||||
onReadNotifications={jest.fn()}
|
||||
onReadSuccess={jest.fn()}
|
||||
onCreateError={jest.fn()}
|
||||
onCreateSuccess={jest.fn()}
|
||||
/>
|
||||
</I18nProvider>
|
||||
</MemoryRouter>
|
||||
@@ -42,18 +42,18 @@ describe('<Notifications />', () => {
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
test('toggle success calls post', () => {
|
||||
const spy = jest.spyOn(Notifications.prototype, 'postToSuccess');
|
||||
const spy = jest.spyOn(Notifications.prototype, 'createSuccess');
|
||||
const wrapper = mount(
|
||||
<MemoryRouter>
|
||||
<I18nProvider>
|
||||
<Notifications
|
||||
match={{ path: '/organizations/:id/?tab=notifications', url: '/organizations/:id/?tab=notifications' }}
|
||||
location={{ search: '', pathname: '/organizations/:id/?tab=notifications' }}
|
||||
getError={jest.fn()}
|
||||
getNotifications={jest.fn()}
|
||||
getSuccess={jest.fn()}
|
||||
postError={jest.fn()}
|
||||
postSuccess={jest.fn()}
|
||||
onReadError={jest.fn()}
|
||||
onReadNotifications={jest.fn()}
|
||||
onReadSuccess={jest.fn()}
|
||||
onCreateError={jest.fn()}
|
||||
onCreateSuccess={jest.fn()}
|
||||
/>
|
||||
</I18nProvider>
|
||||
</MemoryRouter>
|
||||
@@ -62,43 +62,43 @@ describe('<Notifications />', () => {
|
||||
expect(spy).toHaveBeenCalledWith(1, true);
|
||||
});
|
||||
test('post success makes request and updates state properly', async () => {
|
||||
const postSuccessFn = jest.fn();
|
||||
const createSuccess = jest.fn();
|
||||
const wrapper = mount(
|
||||
<MemoryRouter>
|
||||
<I18nProvider>
|
||||
<Notifications
|
||||
match={{ path: '/organizations/:id/?tab=notifications', url: '/organizations/:id/?tab=notifications', params: { id: 1 } }}
|
||||
location={{ search: '', pathname: '/organizations/:id/?tab=notifications' }}
|
||||
getError={jest.fn()}
|
||||
getNotifications={jest.fn()}
|
||||
getSuccess={jest.fn()}
|
||||
postError={jest.fn()}
|
||||
postSuccess={postSuccessFn}
|
||||
onReadError={jest.fn()}
|
||||
onReadNotifications={jest.fn()}
|
||||
onReadSuccess={jest.fn()}
|
||||
onCreateError={jest.fn()}
|
||||
onCreateSuccess={createSuccess}
|
||||
/>
|
||||
</I18nProvider>
|
||||
</MemoryRouter>
|
||||
).find('Notifications');
|
||||
wrapper.setState({ successTemplateIds: [44] });
|
||||
await wrapper.instance().postToSuccess(44, true);
|
||||
expect(postSuccessFn).toHaveBeenCalledWith(1, { id: 44, disassociate: true });
|
||||
await wrapper.instance().createSuccess(44, true);
|
||||
expect(createSuccess).toHaveBeenCalledWith(1, { id: 44, disassociate: true });
|
||||
expect(wrapper.state('successTemplateIds')).not.toContain(44);
|
||||
await wrapper.instance().postToSuccess(44, false);
|
||||
expect(postSuccessFn).toHaveBeenCalledWith(1, { id: 44 });
|
||||
await wrapper.instance().createSuccess(44, false);
|
||||
expect(createSuccess).toHaveBeenCalledWith(1, { id: 44 });
|
||||
expect(wrapper.state('successTemplateIds')).toContain(44);
|
||||
});
|
||||
test('toggle error calls post', () => {
|
||||
const spy = jest.spyOn(Notifications.prototype, 'postToError');
|
||||
const spy = jest.spyOn(Notifications.prototype, 'createError');
|
||||
const wrapper = mount(
|
||||
<MemoryRouter>
|
||||
<I18nProvider>
|
||||
<Notifications
|
||||
match={{ path: '/organizations/:id/?tab=notifications', url: '/organizations/:id/?tab=notifications' }}
|
||||
location={{ search: '', pathname: '/organizations/:id/?tab=notifications' }}
|
||||
getError={jest.fn()}
|
||||
getNotifications={jest.fn()}
|
||||
getSuccess={jest.fn()}
|
||||
postError={jest.fn()}
|
||||
postSuccess={jest.fn()}
|
||||
onReadError={jest.fn()}
|
||||
onReadNotifications={jest.fn()}
|
||||
onReadSuccess={jest.fn()}
|
||||
onCreateError={jest.fn()}
|
||||
onCreateSuccess={jest.fn()}
|
||||
/>
|
||||
</I18nProvider>
|
||||
</MemoryRouter>
|
||||
@@ -107,28 +107,28 @@ describe('<Notifications />', () => {
|
||||
expect(spy).toHaveBeenCalledWith(1, true);
|
||||
});
|
||||
test('post error makes request and updates state properly', async () => {
|
||||
const postErrorFn = jest.fn();
|
||||
const createError = jest.fn();
|
||||
const wrapper = mount(
|
||||
<MemoryRouter>
|
||||
<I18nProvider>
|
||||
<Notifications
|
||||
match={{ path: '/organizations/:id/?tab=notifications', url: '/organizations/:id/?tab=notifications', params: { id: 1 } }}
|
||||
location={{ search: '', pathname: '/organizations/:id/?tab=notifications' }}
|
||||
getError={jest.fn()}
|
||||
getNotifications={jest.fn()}
|
||||
getSuccess={jest.fn()}
|
||||
postError={postErrorFn}
|
||||
postSuccess={jest.fn()}
|
||||
onReadError={jest.fn()}
|
||||
onReadNotifications={jest.fn()}
|
||||
onReadSuccess={jest.fn()}
|
||||
onCreateError={createError}
|
||||
onCreateSuccess={jest.fn()}
|
||||
/>
|
||||
</I18nProvider>
|
||||
</MemoryRouter>
|
||||
).find('Notifications');
|
||||
wrapper.setState({ errorTemplateIds: [44] });
|
||||
await wrapper.instance().postToError(44, true);
|
||||
expect(postErrorFn).toHaveBeenCalledWith(1, { id: 44, disassociate: true });
|
||||
await wrapper.instance().createError(44, true);
|
||||
expect(createError).toHaveBeenCalledWith(1, { id: 44, disassociate: true });
|
||||
expect(wrapper.state('errorTemplateIds')).not.toContain(44);
|
||||
await wrapper.instance().postToError(44, false);
|
||||
expect(postErrorFn).toHaveBeenCalledWith(1, { id: 44 });
|
||||
await wrapper.instance().createError(44, false);
|
||||
expect(createError).toHaveBeenCalledWith(1, { id: 44 });
|
||||
expect(wrapper.state('errorTemplateIds')).toContain(44);
|
||||
});
|
||||
test('fetchNotifications', async () => {
|
||||
@@ -137,7 +137,7 @@ describe('<Notifications />', () => {
|
||||
page_size: 10,
|
||||
order_by: 'name'
|
||||
};
|
||||
const getNotificationsFn = jest.fn().mockResolvedValue({
|
||||
const onReadNotifications = jest.fn().mockResolvedValue({
|
||||
data: {
|
||||
results: [
|
||||
{ id: 1, notification_type: 'slack' },
|
||||
@@ -146,14 +146,14 @@ describe('<Notifications />', () => {
|
||||
]
|
||||
}
|
||||
});
|
||||
const getSuccessFn = jest.fn().mockResolvedValue({
|
||||
const onReadSuccess = jest.fn().mockResolvedValue({
|
||||
data: {
|
||||
results: [
|
||||
{ id: 1 }
|
||||
]
|
||||
}
|
||||
});
|
||||
const getErrorFn = jest.fn().mockResolvedValue({
|
||||
const readError = jest.fn().mockResolvedValue({
|
||||
data: {
|
||||
results: [
|
||||
{ id: 2 }
|
||||
@@ -166,22 +166,22 @@ describe('<Notifications />', () => {
|
||||
<Notifications
|
||||
match={{ path: '/organizations/:id/?tab=notifications', url: '/organizations/:id/?tab=notifications', params: { id: 1 } }}
|
||||
location={{ search: '', pathname: '/organizations/:id/?tab=notifications' }}
|
||||
getNotifications={getNotificationsFn}
|
||||
getSuccess={getSuccessFn}
|
||||
getError={getErrorFn}
|
||||
postError={jest.fn()}
|
||||
postSuccess={jest.fn()}
|
||||
onReadNotifications={onReadNotifications}
|
||||
onReadSuccess={onReadSuccess}
|
||||
onReadError={readError}
|
||||
onCreateError={jest.fn()}
|
||||
onCreateSuccess={jest.fn()}
|
||||
/>
|
||||
</I18nProvider>
|
||||
</MemoryRouter>
|
||||
).find('Notifications');
|
||||
wrapper.instance().updateUrl = jest.fn();
|
||||
await wrapper.instance().fetchNotifications(mockQueryParams);
|
||||
expect(getNotificationsFn).toHaveBeenCalledWith(1, mockQueryParams);
|
||||
expect(getSuccessFn).toHaveBeenCalledWith(1, {
|
||||
await wrapper.instance().readNotifications(mockQueryParams);
|
||||
expect(onReadNotifications).toHaveBeenCalledWith(1, mockQueryParams);
|
||||
expect(onReadSuccess).toHaveBeenCalledWith(1, {
|
||||
id__in: '1,2,3'
|
||||
});
|
||||
expect(getErrorFn).toHaveBeenCalledWith(1, {
|
||||
expect(readError).toHaveBeenCalledWith(1, {
|
||||
id__in: '1,2,3'
|
||||
});
|
||||
expect(wrapper.state('successTemplateIds')).toContain(1);
|
||||
|
||||
Reference in New Issue
Block a user