Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2040 After back to homepage or change map, notifications don't clear #2044

Merged
merged 3 commits into from
Jul 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docma-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
"web/client/epics/fullscreen.js",
"web/client/epics/globeswitcher.js",
"web/client/epics/maptype.js",
"web/client/epics/notifications.js",
"web/client/epics/search.js",
"web/client/epics/tutorial.js",
"web/client/epics/wfsquery.js",
Expand Down
46 changes: 46 additions & 0 deletions web/client/epics/__tests__/notifications-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2017, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

var expect = require('expect');

const configureMockStore = require('redux-mock-store').default;
const {createEpicMiddleware, combineEpics } = require('redux-observable');
const {CLEAR_NOTIFICATIONS} = require('../../actions/notifications');

const {clearNotificationOnLocationChange} = require('../notifications');
const rootEpic = combineEpics(clearNotificationOnLocationChange);
const epicMiddleware = createEpicMiddleware(rootEpic);
const mockStore = configureMockStore([epicMiddleware]);

describe('notifications Epics', () => {
let store;
beforeEach(() => {
store = mockStore();
});

afterEach(() => {
epicMiddleware.replaceEpic(rootEpic);
});

it('test clear notifications on location change', (done) => {

store.dispatch({type: '@@router/LOCATION_CHANGE'});

setTimeout( () => {
try {
const actions = store.getActions();
expect(actions.length).toBe(2);
expect(actions[1].type).toBe(CLEAR_NOTIFICATIONS);
} catch (e) {
return done(e);
}
done();
}, 500);

});
});
30 changes: 30 additions & 0 deletions web/client/epics/notifications.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2017, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
const Rx = require('rxjs');
const {clear} = require('../actions/notifications');
const {LOCATION_CHANGE} = require('react-router-redux');

/**
* Clear all notifications on LOCATION_CHANGE.
* @param {external:Observable} action$ manages `LOCATION_CHANGE`.
* @memberof epics.notifications
* @return {external:Observable}
*/
const clearNotificationOnLocationChange = action$ =>
action$.ofType(LOCATION_CHANGE)
.switchMap(() => Rx.Observable.of(clear()));

/**
* Epics for notifications
* @name epics.notifications
* @type {Object}
*/

module.exports = {
clearNotificationOnLocationChange
};
4 changes: 4 additions & 0 deletions web/client/plugins/Notifications.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

const {hide} = require('../actions/notifications');
const {clearNotificationOnLocationChange} = require('../epics/notifications');
const {connect} = require('react-redux');


Expand All @@ -26,5 +27,8 @@ module.exports = {
)(require('../components/notifications/NotificationContainer')),
reducers: {
notifications: require('../reducers/notifications')
},
epics: {
clearNotificationOnLocationChange
}
};