From 047d99be6d0266da520c3e7a25e7e0b998888f74 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 21 Dec 2018 10:38:35 +0100 Subject: [PATCH] Updated ScrollTop component so that it gets the window object injected as a dependency --- jest.config.js | 1 + src/common/ScrollToTop.js | 14 +++++--------- src/common/services/provideServices.js | 4 +++- src/servers/services/provideServices.js | 1 - 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/jest.config.js b/jest.config.js index a7bdef22..b3126e32 100644 --- a/jest.config.js +++ b/jest.config.js @@ -4,6 +4,7 @@ module.exports = { 'src/**/*.js', '!src/registerServiceWorker.js', '!src/index.js', + '!src/reducers/index.js', '!src/**/provideServices.js', '!src/container/*.js', ], diff --git a/src/common/ScrollToTop.js b/src/common/ScrollToTop.js index c8624da0..19a34dfb 100644 --- a/src/common/ScrollToTop.js +++ b/src/common/ScrollToTop.js @@ -1,20 +1,14 @@ import React from 'react'; import PropTypes from 'prop-types'; -export default class ScrollToTop extends React.Component { +const ScrollToTop = (window) => class ScrollToTop extends React.Component { static propTypes = { location: PropTypes.object, - window: PropTypes.shape({ - scrollTo: PropTypes.func, - }), children: PropTypes.node, }; - static defaultProps = { - window: global.window, - }; componentDidUpdate(prevProps) { - const { location, window } = this.props; + const { location } = this.props; if (location !== prevProps.location) { window.scrollTo(0, 0); @@ -24,4 +18,6 @@ export default class ScrollToTop extends React.Component { render() { return this.props.children; } -} +}; + +export default ScrollToTop; diff --git a/src/common/services/provideServices.js b/src/common/services/provideServices.js index 584ddcf9..eb7e0c9d 100644 --- a/src/common/services/provideServices.js +++ b/src/common/services/provideServices.js @@ -5,7 +5,9 @@ import MenuLayout from '../MenuLayout'; import AsideMenu from '../AsideMenu'; const provideServices = (bottle, connect, withRouter) => { - bottle.constant('ScrollToTop', ScrollToTop); + bottle.constant('window', global.window); + + bottle.serviceFactory('ScrollToTop', ScrollToTop, 'window'); bottle.decorator('ScrollToTop', withRouter); bottle.serviceFactory('MainHeader', MainHeader, 'ServersDropdown'); diff --git a/src/servers/services/provideServices.js b/src/servers/services/provideServices.js index a2464749..c12f1b35 100644 --- a/src/servers/services/provideServices.js +++ b/src/servers/services/provideServices.js @@ -29,7 +29,6 @@ const provideServices = (bottle, connect, withRouter) => { // Services bottle.constant('csvjson', csvjson); - bottle.constant('window', global.window); bottle.service('ServersImporter', ServersImporter, 'csvjson'); bottle.service('ServersService', ServersService, 'Storage'); bottle.service('ServersExporter', ServersExporter, 'ServersService', 'window', 'csvjson');