-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SDESK-4027] Pre-built filters for events and planning view.
- Loading branch information
Mayur Dhamanwala
committed
Apr 7, 2019
1 parent
9b3d0b9
commit 361d423
Showing
45 changed files
with
1,992 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import ui from './ui'; | ||
import api from './api'; | ||
import notifications from './notifications'; | ||
|
||
export default { | ||
api, | ||
ui, | ||
notifications, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import eventsPlanningUi from './ui'; | ||
import * as selectors from '../../selectors'; | ||
import {gettext} from '../../utils'; | ||
import {EVENTS_PLANNING, MAIN} from '../../constants'; | ||
|
||
const onEventPlaningFilterCreatedOrUpdated = (_e, data) => ( | ||
(dispatch, getState, {notify}) => { | ||
if (data && data.item) { | ||
return dispatch(eventsPlanningUi.fetchFilterById(data.item)) | ||
.then(() => { | ||
const currentFilter = selectors.eventsPlanning.currentFilter(getState()); | ||
const currentView = selectors.main.activeFilter(getState()); | ||
|
||
if (currentFilter === data.item && MAIN.FILTERS.COMBINED === currentView) { | ||
notify.warning( | ||
gettext('The Event and Planning filter you were viewing is modified!') | ||
); | ||
return dispatch(eventsPlanningUi.scheduleRefetch(true)); | ||
} | ||
return Promise.resolve(); | ||
}); | ||
} | ||
} | ||
); | ||
|
||
|
||
const onEventPlaningFilterDeleted = (_e, data) => ( | ||
(dispatch, getState, {notify}) => { | ||
if (data && data.item) { | ||
return dispatch(eventsPlanningUi.fetchFilters()) | ||
.then(() => { | ||
const currentFilter = selectors.eventsPlanning.currentFilter(getState()); | ||
const currentView = selectors.main.activeFilter(getState()); | ||
|
||
dispatch(eventsPlanningUi.storeFilter(EVENTS_PLANNING.FILTER.ALL_EVENTS_PLANNING)); | ||
|
||
if (currentFilter === data.item && MAIN.FILTERS.COMBINED === currentView) { | ||
notify.warning( | ||
gettext('The Event and Planning filter you were viewing is deleted!') | ||
); | ||
|
||
return dispatch(eventsPlanningUi.scheduleRefetch(true)); | ||
} | ||
return Promise.resolve(); | ||
}); | ||
} | ||
} | ||
); | ||
|
||
// eslint-disable-next-line consistent-this | ||
const self = { | ||
onEventPlaningFilterCreatedOrUpdated, | ||
onEventPlaningFilterDeleted, | ||
}; | ||
|
||
|
||
// Map of notification name and Action Event to execute | ||
self.events = { | ||
'event_planning_filters:created': () => (self.onEventPlaningFilterCreatedOrUpdated), | ||
'event_planning_filters:updated': () => (self.onEventPlaningFilterCreatedOrUpdated), | ||
'event_planning_filters:deleted': () => (self.onEventPlaningFilterDeleted), | ||
}; | ||
|
||
export default self; |
157 changes: 157 additions & 0 deletions
157
client/actions/eventsPlanning/tests/notifications_test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
import sinon from 'sinon'; | ||
import {getTestActionStore, restoreSinonStub} from '../../../utils/testUtils'; | ||
import {registerNotifications} from '../../../utils'; | ||
import notifications from '../notifications'; | ||
import eventsPlanningUi from '../ui'; | ||
import {MAIN} from '../../../constants'; | ||
|
||
|
||
describe('actions.eventsplanning.notifications', () => { | ||
let store; | ||
let data; | ||
let services; | ||
|
||
beforeEach(() => { | ||
store = getTestActionStore(); | ||
data = store.data; | ||
services = store.services; | ||
store.init(); | ||
}); | ||
|
||
describe('websocket', () => { | ||
const delay = 0; | ||
let $rootScope; | ||
|
||
beforeEach(inject((_$rootScope_) => { | ||
sinon.stub(notifications, 'onEventPlaningFilterCreatedOrUpdated').callsFake( | ||
() => (Promise.resolve()) | ||
); | ||
|
||
sinon.stub(notifications, 'onEventPlaningFilterDeleted').callsFake( | ||
() => (Promise.resolve()) | ||
); | ||
|
||
$rootScope = _$rootScope_; | ||
registerNotifications($rootScope, store); | ||
$rootScope.$digest(); | ||
})); | ||
|
||
afterEach(() => { | ||
restoreSinonStub(notifications.onEventPlaningFilterCreatedOrUpdated); | ||
restoreSinonStub(notifications.onEventPlaningFilterDeleted); | ||
}); | ||
|
||
it('on filter created', (done) => { | ||
$rootScope.$broadcast('event_planning_filters:created', {item: 'finance', user: 'user1'}); | ||
|
||
setTimeout(() => { | ||
expect(notifications.onEventPlaningFilterCreatedOrUpdated.callCount).toBe(1); | ||
expect(notifications.onEventPlaningFilterCreatedOrUpdated.args[0][1]).toEqual( | ||
{item: 'finance', user: 'user1'} | ||
); | ||
done(); | ||
}, delay); | ||
}); | ||
|
||
it('on filter updated', (done) => { | ||
$rootScope.$broadcast('event_planning_filters:updated', {item: 'finance', user: 'user1'}); | ||
|
||
setTimeout(() => { | ||
expect(notifications.onEventPlaningFilterCreatedOrUpdated.callCount).toBe(1); | ||
expect(notifications.onEventPlaningFilterCreatedOrUpdated.args[0][1]).toEqual( | ||
{item: 'finance', user: 'user1'} | ||
); | ||
done(); | ||
}, delay); | ||
}); | ||
|
||
it('on filter deleted', (done) => { | ||
$rootScope.$broadcast('event_planning_filters:deleted', {item: 'finance', user: 'user1'}); | ||
|
||
setTimeout(() => { | ||
expect(notifications.onEventPlaningFilterDeleted.callCount).toBe(1); | ||
expect(notifications.onEventPlaningFilterDeleted.args[0][1]).toEqual( | ||
{item: 'finance', user: 'user1'} | ||
); | ||
done(); | ||
}, delay); | ||
}); | ||
}); | ||
|
||
|
||
describe('on filter create', () => { | ||
beforeEach(() => { | ||
sinon.stub(eventsPlanningUi, 'fetchFilterById').callsFake( | ||
() => Promise.resolve(data.events_planning_filters[0]) | ||
); | ||
sinon.stub(eventsPlanningUi, 'scheduleRefetch').callsFake( | ||
() => Promise.resolve([]) | ||
); | ||
sinon.stub(eventsPlanningUi, 'fetchFilters').callsFake( | ||
() => Promise.resolve([]) | ||
); | ||
}); | ||
|
||
afterEach(() => { | ||
restoreSinonStub(eventsPlanningUi.fetchFilterById); | ||
restoreSinonStub(eventsPlanningUi.scheduleRefetch); | ||
restoreSinonStub(eventsPlanningUi.fetchFilters); | ||
}); | ||
|
||
it('create new filter', (done) => { | ||
store.test(done, notifications.onEventPlaningFilterCreatedOrUpdated({}, {item: 'finance', user: 'user1'})) | ||
.then(() => { | ||
expect(eventsPlanningUi.fetchFilterById.callCount).toBe(1); | ||
expect(eventsPlanningUi.scheduleRefetch.callCount).toBe(0); | ||
expect(services.notify.warning.callCount).toBe(0); | ||
done(); | ||
}) | ||
.catch(done.fail); | ||
}); | ||
|
||
it('update filter', (done) => { | ||
store.initialState.eventsPlanning.currentFilter = 'finance'; | ||
store.initialState.main.filter = MAIN.FILTERS.COMBINED; | ||
store.test(done, notifications.onEventPlaningFilterCreatedOrUpdated({}, {item: 'finance', user: 'user1'})) | ||
.then(() => { | ||
expect(eventsPlanningUi.fetchFilterById.callCount).toBe(1); | ||
expect(eventsPlanningUi.scheduleRefetch.callCount).toBe(1); | ||
expect(services.notify.warning.callCount).toBe(1); | ||
expect(services.notify.warning.args[0][0]).toEqual( | ||
'The Event and Planning filter you were viewing is modified!' | ||
); | ||
done(); | ||
}) | ||
.catch(done.fail); | ||
}); | ||
|
||
it('delete filter with current filter different', (done) => { | ||
store.initialState.eventsPlanning.currentFilter = 'xxx'; | ||
store.initialState.main.filter = MAIN.FILTERS.COMBINED; | ||
store.test(done, notifications.onEventPlaningFilterDeleted({}, {item: 'finance', user: 'user1'})) | ||
.then(() => { | ||
expect(eventsPlanningUi.fetchFilters.callCount).toBe(1); | ||
expect(eventsPlanningUi.scheduleRefetch.callCount).toBe(0); | ||
expect(services.notify.warning.callCount).toBe(0); | ||
done(); | ||
}) | ||
.catch(done.fail); | ||
}); | ||
|
||
it('delete filter with current filter different', (done) => { | ||
store.initialState.eventsPlanning.currentFilter = 'finance'; | ||
store.initialState.main.filter = MAIN.FILTERS.COMBINED; | ||
store.test(done, notifications.onEventPlaningFilterDeleted({}, {item: 'finance', user: 'user1'})) | ||
.then(() => { | ||
expect(eventsPlanningUi.fetchFilters.callCount).toBe(1); | ||
expect(eventsPlanningUi.scheduleRefetch.callCount).toBe(1); | ||
expect(services.notify.warning.callCount).toBe(1); | ||
expect(services.notify.warning.args[0][0]).toEqual( | ||
'The Event and Planning filter you were viewing is deleted!' | ||
); | ||
done(); | ||
}) | ||
.catch(done.fail); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.