mirror of
https://github.com/ansible/awx.git
synced 2026-01-13 02:50:02 -03:30
Merge pull request #139 from AlexSCorey/138-updateFunctionName
Fixes function naming
This commit is contained in:
commit
ae622c4875
@ -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);
|
||||
|
||||
@ -44,11 +44,11 @@ describe('<OrganizationNotifications />', () => {
|
||||
/>
|
||||
</MemoryRouter>
|
||||
).find('OrganizationNotifications');
|
||||
wrapper.instance().getOrgNotifications(1, { foo: 'bar' });
|
||||
wrapper.instance().readOrgNotifications(1, { foo: 'bar' });
|
||||
expect(getOrganizationNotifications).toHaveBeenCalledWith(1, { foo: 'bar' });
|
||||
wrapper.instance().getOrgNotificationSuccess(1, { foo: 'bar' });
|
||||
wrapper.instance().readOrgNotificationSuccess(1, { foo: 'bar' });
|
||||
expect(getOrganizationNotificationSuccess).toHaveBeenCalledWith(1, { foo: 'bar' });
|
||||
wrapper.instance().getOrgNotificationError(1, { foo: 'bar' });
|
||||
wrapper.instance().readOrgNotificationError(1, { foo: 'bar' });
|
||||
expect(getOrganizationNotificationError).toHaveBeenCalledWith(1, { foo: 'bar' });
|
||||
wrapper.instance().createOrgNotificationSuccess(1, { id: 2 });
|
||||
expect(createOrganizationNotificationSuccess).toHaveBeenCalledWith(1, { id: 2 });
|
||||
|
||||
@ -49,27 +49,21 @@ class Notifications extends Component {
|
||||
errorTemplateIds: []
|
||||
};
|
||||
|
||||
this.onSearch = this.onSearch.bind(this);
|
||||
this.handleSearch = this.handleSearch.bind(this);
|
||||
this.getQueryParams = this.getQueryParams.bind(this);
|
||||
this.onSort = this.onSort.bind(this);
|
||||
this.onSetPage = this.onSetPage.bind(this);
|
||||
this.onSelectAll = this.onSelectAll.bind(this);
|
||||
this.handleSort = this.handleSort.bind(this);
|
||||
this.handleSetPage = this.handleSetPage.bind(this);
|
||||
this.handleSelectAll = this.handleSelectAll.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);
|
||||
this.fetchNotifications = this.fetchNotifications.bind(this);
|
||||
this.createError = this.createError.bind(this);
|
||||
this.createSuccess = this.createSuccess.bind(this);
|
||||
this.readNotifications = this.readNotifications.bind(this);
|
||||
}
|
||||
|
||||
componentDidMount () {
|
||||
const queryParams = this.getQueryParams();
|
||||
this.fetchNotifications(queryParams);
|
||||
}
|
||||
|
||||
onSearch () {
|
||||
const { sortedColumnKey, sortOrder } = this.state;
|
||||
|
||||
this.onSort(sortedColumnKey, sortOrder);
|
||||
this.readNotifications(queryParams);
|
||||
}
|
||||
|
||||
getQueryParams (overrides = {}) {
|
||||
@ -81,7 +75,7 @@ class Notifications extends Component {
|
||||
return Object.assign({}, this.defaultParams, searchParams, overrides);
|
||||
}
|
||||
|
||||
onSort = (sortedColumnKey, sortOrder) => {
|
||||
handleSort = (sortedColumnKey, sortOrder) => {
|
||||
const { page_size } = this.state;
|
||||
|
||||
let order_by = sortedColumnKey;
|
||||
@ -92,19 +86,19 @@ class Notifications extends Component {
|
||||
|
||||
const queryParams = this.getQueryParams({ order_by, page_size });
|
||||
|
||||
this.fetchNotifications(queryParams);
|
||||
this.readNotifications(queryParams);
|
||||
};
|
||||
|
||||
onSetPage = (pageNumber, pageSize) => {
|
||||
handleSetPage = (pageNumber, pageSize) => {
|
||||
const page = parseInt(pageNumber, 10);
|
||||
const page_size = parseInt(pageSize, 10);
|
||||
|
||||
const queryParams = this.getQueryParams({ page, page_size });
|
||||
|
||||
this.fetchNotifications(queryParams);
|
||||
this.readNotifications(queryParams);
|
||||
};
|
||||
|
||||
onSelectAll = isSelected => {
|
||||
handleSelectAll = isSelected => {
|
||||
const { results } = this.state;
|
||||
|
||||
const selected = isSelected ? results.map(o => o.id) : [];
|
||||
@ -114,12 +108,18 @@ class Notifications extends Component {
|
||||
|
||||
toggleNotification = (id, isCurrentlyOn, status) => {
|
||||
if (status === 'success') {
|
||||
this.postToSuccess(id, isCurrentlyOn);
|
||||
this.createSuccess(id, isCurrentlyOn);
|
||||
} else if (status === 'error') {
|
||||
this.postToError(id, isCurrentlyOn);
|
||||
this.createError(id, isCurrentlyOn);
|
||||
}
|
||||
};
|
||||
|
||||
handleSearch () {
|
||||
const { sortedColumnKey, sortOrder } = this.state;
|
||||
|
||||
this.handleSort(sortedColumnKey, sortOrder);
|
||||
}
|
||||
|
||||
updateUrl (queryParams) {
|
||||
const { history, location, match } = this.props;
|
||||
const pathname = match.url;
|
||||
@ -130,14 +130,14 @@ class Notifications extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
async postToError (id, isCurrentlyOn) {
|
||||
const { postError, match } = this.props;
|
||||
async createError (id, isCurrentlyOn) {
|
||||
const { onCreateError, match } = this.props;
|
||||
const postParams = { id };
|
||||
if (isCurrentlyOn) {
|
||||
postParams.disassociate = true;
|
||||
}
|
||||
try {
|
||||
await postError(match.params.id, postParams);
|
||||
await onCreateError(match.params.id, postParams);
|
||||
} catch (err) {
|
||||
this.setState({ error: true });
|
||||
} finally {
|
||||
@ -155,14 +155,14 @@ class Notifications extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
async postToSuccess (id, isCurrentlyOn) {
|
||||
const { postSuccess, match } = this.props;
|
||||
async createSuccess (id, isCurrentlyOn) {
|
||||
const { onCreateSuccess, match } = this.props;
|
||||
const postParams = { id };
|
||||
if (isCurrentlyOn) {
|
||||
postParams.disassociate = true;
|
||||
}
|
||||
try {
|
||||
await postSuccess(match.params.id, postParams);
|
||||
await onCreateSuccess(match.params.id, postParams);
|
||||
} catch (err) {
|
||||
this.setState({ error: true });
|
||||
} finally {
|
||||
@ -180,9 +180,9 @@ class Notifications extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
async fetchNotifications (queryParams) {
|
||||
async readNotifications (queryParams) {
|
||||
const { noInitialResults } = this.state;
|
||||
const { getNotifications, getSuccess, getError, match } = this.props;
|
||||
const { onReadNotifications, onReadSuccess, onReadError, match } = this.props;
|
||||
const { page, page_size, order_by } = queryParams;
|
||||
|
||||
let sortOrder = 'ascending';
|
||||
@ -196,7 +196,7 @@ class Notifications extends Component {
|
||||
this.setState({ error: false, loading: true });
|
||||
|
||||
try {
|
||||
const { data } = await getNotifications(match.params.id, queryParams);
|
||||
const { data } = await onReadNotifications(match.params.id, queryParams);
|
||||
const { count, results } = data;
|
||||
|
||||
const pageCount = Math.ceil(count / page_size);
|
||||
@ -231,10 +231,10 @@ class Notifications extends Component {
|
||||
let errorTemplateIds = [];
|
||||
|
||||
if (results.length > 0) {
|
||||
const successTemplatesPromise = getSuccess(match.params.id, {
|
||||
const successTemplatesPromise = onReadSuccess(match.params.id, {
|
||||
id__in: notificationTemplateIds
|
||||
});
|
||||
const errorTemplatesPromise = getError(match.params.id, {
|
||||
const errorTemplatesPromise = onReadError(match.params.id, {
|
||||
id__in: notificationTemplateIds
|
||||
});
|
||||
const successTemplatesResult = await successTemplatesPromise;
|
||||
@ -297,9 +297,9 @@ class Notifications extends Component {
|
||||
sortedColumnKey={sortedColumnKey}
|
||||
sortOrder={sortOrder}
|
||||
columns={this.columns}
|
||||
onSearch={this.onSearch}
|
||||
onSort={this.onSort}
|
||||
onSelectAll={this.onSelectAll}
|
||||
onSearch={this.handleSearch}
|
||||
onSort={this.handleSort}
|
||||
onSelectAll={this.handleSelectAll}
|
||||
/>
|
||||
<I18n>
|
||||
{({ i18n }) => (
|
||||
@ -324,7 +324,7 @@ class Notifications extends Component {
|
||||
page={page}
|
||||
pageCount={pageCount}
|
||||
page_size={page_size}
|
||||
onSetPage={this.onSetPage}
|
||||
onSetPage={this.handleSetPage}
|
||||
/>
|
||||
</Fragment>
|
||||
)}
|
||||
@ -336,11 +336,11 @@ class Notifications extends Component {
|
||||
}
|
||||
|
||||
Notifications.propTypes = {
|
||||
getError: PropTypes.func.isRequired,
|
||||
getNotifications: PropTypes.func.isRequired,
|
||||
getSuccess: PropTypes.func.isRequired,
|
||||
postError: PropTypes.func.isRequired,
|
||||
postSuccess: PropTypes.func.isRequired,
|
||||
onReadError: PropTypes.func.isRequired,
|
||||
onReadNotifications: PropTypes.func.isRequired,
|
||||
onReadSuccess: PropTypes.func.isRequired,
|
||||
onCreateError: PropTypes.func.isRequired,
|
||||
onCreateSuccess: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
export default Notifications;
|
||||
|
||||
@ -6,24 +6,24 @@ class OrganizationNotifications extends Component {
|
||||
constructor (props) {
|
||||
super(props);
|
||||
|
||||
this.getOrgNotifications = this.getOrgNotifications.bind(this);
|
||||
this.getOrgNotificationSuccess = this.getOrgNotificationSuccess.bind(this);
|
||||
this.getOrgNotificationError = this.getOrgNotificationError.bind(this);
|
||||
this.readOrgNotifications = this.readOrgNotifications.bind(this);
|
||||
this.readOrgNotificationSuccess = this.readOrgNotificationSuccess.bind(this);
|
||||
this.readOrgNotificationError = this.readOrgNotificationError.bind(this);
|
||||
this.createOrgNotificationSuccess = this.createOrgNotificationSuccess.bind(this);
|
||||
this.createOrgNotificationError = this.createOrgNotificationError.bind(this);
|
||||
}
|
||||
|
||||
getOrgNotifications (id, reqParams) {
|
||||
readOrgNotifications (id, reqParams) {
|
||||
const { api } = this.props;
|
||||
return api.getOrganizationNotifications(id, reqParams);
|
||||
}
|
||||
|
||||
getOrgNotificationSuccess (id, reqParams) {
|
||||
readOrgNotificationSuccess (id, reqParams) {
|
||||
const { api } = this.props;
|
||||
return api.getOrganizationNotificationSuccess(id, reqParams);
|
||||
}
|
||||
|
||||
getOrgNotificationError (id, reqParams) {
|
||||
readOrgNotificationError (id, reqParams) {
|
||||
const { api } = this.props;
|
||||
return api.getOrganizationNotificationError(id, reqParams);
|
||||
}
|
||||
@ -47,11 +47,11 @@ class OrganizationNotifications extends Component {
|
||||
|
||||
return (
|
||||
<NotificationsList
|
||||
getNotifications={this.getOrgNotifications}
|
||||
getSuccess={this.getOrgNotificationSuccess}
|
||||
getError={this.getOrgNotificationError}
|
||||
postSuccess={this.createOrgNotificationSuccess}
|
||||
postError={this.createOrgNotificationError}
|
||||
onReadNotifications={this.readOrgNotifications}
|
||||
onReadSuccess={this.readOrgNotificationSuccess}
|
||||
onReadError={this.readOrgNotificationError}
|
||||
onCreateSuccess={this.createOrgNotificationSuccess}
|
||||
onCreateError={this.createOrgNotificationError}
|
||||
match={match}
|
||||
location={location}
|
||||
history={history}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user