diff --git a/src/App.js b/src/App.js index dce4f6e5..b351422c 100644 --- a/src/App.js +++ b/src/App.js @@ -1,10 +1,8 @@ import React from 'react'; import { Route, Switch } from 'react-router-dom'; import './App.scss'; -import MenuLayout from './common/MenuLayout'; -import CreateServer from './servers/CreateServer'; -const App = (MainHeader, Home) => () => ( +const App = (MainHeader, Home, MenuLayout, CreateServer) => () => (
diff --git a/src/common/MenuLayout.js b/src/common/MenuLayout.js index 60e33a31..e2034104 100644 --- a/src/common/MenuLayout.js +++ b/src/common/MenuLayout.js @@ -1,15 +1,11 @@ import React from 'react'; -import { Route, Switch, withRouter } from 'react-router-dom'; -import { connect } from 'react-redux'; -import { compose } from 'redux'; -import { pick } from 'ramda'; +import { Route, Switch } from 'react-router-dom'; import Swipeable from 'react-swipeable'; import burgerIcon from '@fortawesome/fontawesome-free-solid/faBars'; import FontAwesomeIcon from '@fortawesome/react-fontawesome'; import classnames from 'classnames'; import * as PropTypes from 'prop-types'; import ShortUrlsVisits from '../visits/ShortUrlVisits'; -import { selectServer } from '../servers/reducers/selectedServer'; import CreateShortUrl from '../short-urls/CreateShortUrl'; import ShortUrls from '../short-urls/ShortUrls'; import './MenuLayout.scss'; @@ -17,7 +13,7 @@ import TagsList from '../tags/TagsList'; import { serverType } from '../servers/prop-types'; import AsideMenu from './AsideMenu'; -export class MenuLayoutComponent extends React.Component { +export default class MenuLayout extends React.Component { static propTypes = { match: PropTypes.object, selectServer: PropTypes.func, @@ -104,10 +100,3 @@ export class MenuLayoutComponent extends React.Component { ); } } - -const MenuLayout = compose( - connect(pick([ 'selectedServer', 'shortUrlsListParams' ]), { selectServer }), - withRouter -)(MenuLayoutComponent); - -export default MenuLayout; diff --git a/src/container/index.js b/src/container/index.js index 2009c749..faf0ee7a 100644 --- a/src/container/index.js +++ b/src/container/index.js @@ -1,20 +1,38 @@ import Bottle from 'bottlejs'; import { withRouter } from 'react-router-dom'; import { connect } from 'react-redux'; +import { compose } from 'redux'; import { pick } from 'ramda'; import App from '../App'; import ScrollToTop from '../common/ScrollToTop'; import MainHeader from '../common/MainHeader'; -import { resetSelectedServer } from '../servers/reducers/selectedServer'; +import { resetSelectedServer, selectServer } from '../servers/reducers/selectedServer'; import Home from '../common/Home'; +import MenuLayout from '../common/MenuLayout'; +import { createServer } from '../servers/reducers/server'; +import CreateServer from '../servers/CreateServer'; import store from './store'; const bottle = new Bottle(); bottle.constant('store', store); -bottle.serviceFactory('App', App, 'MainHeader', 'Home'); -bottle.serviceFactory('MainHeader', () => withRouter(MainHeader())); bottle.serviceFactory('ScrollToTop', () => withRouter(ScrollToTop)); +bottle.serviceFactory('MainHeader', () => withRouter(MainHeader())); bottle.serviceFactory('Home', () => connect(pick([ 'servers' ]), { resetSelectedServer })(Home)); +bottle.serviceFactory( + 'MenuLayout', + () => compose( + connect(pick([ 'selectedServer', 'shortUrlsListParams' ]), { selectServer }), + withRouter + )(MenuLayout) +); +bottle.serviceFactory( + 'CreateServer', + () => connect( + pick([ 'selectedServer' ]), + { createServer, resetSelectedServer } + )(CreateServer) +); +bottle.serviceFactory('App', App, 'MainHeader', 'Home', 'MenuLayout', 'CreateServer'); export default bottle.container; diff --git a/src/servers/CreateServer.js b/src/servers/CreateServer.js index 3875ba66..4a601d26 100644 --- a/src/servers/CreateServer.js +++ b/src/servers/CreateServer.js @@ -1,17 +1,14 @@ -import { assoc, dissoc, pick, pipe } from 'ramda'; +import { assoc, dissoc, pipe } from 'ramda'; import React from 'react'; -import { connect } from 'react-redux'; import { v4 as uuid } from 'uuid'; import PropTypes from 'prop-types'; import { stateFlagTimeout } from '../utils/utils'; -import { resetSelectedServer } from './reducers/selectedServer'; -import { createServer } from './reducers/server'; import './CreateServer.scss'; import ImportServersBtn from './helpers/ImportServersBtn'; const SHOW_IMPORT_MSG_TIME = 4000; -export class CreateServerComponent extends React.Component { +export default class CreateServer extends React.Component { static propTypes = { createServer: PropTypes.func, history: PropTypes.shape({ @@ -92,10 +89,3 @@ export class CreateServerComponent extends React.Component { ); } } - -const CreateServer = connect( - pick([ 'selectedServer' ]), - { createServer, resetSelectedServer } -)(CreateServerComponent); - -export default CreateServer; diff --git a/src/servers/reducers/selectedServer.js b/src/servers/reducers/selectedServer.js index 891f5ce2..eca53474 100644 --- a/src/servers/reducers/selectedServer.js +++ b/src/servers/reducers/selectedServer.js @@ -1,4 +1,3 @@ -import { curry } from 'ramda'; import shlinkApiClient from '../../api/ShlinkApiClient'; import serversService from '../../servers/services/ServersService'; import { resetShortUrlParams } from '../../short-urls/reducers/shortUrlsListParams'; @@ -23,7 +22,7 @@ export default function reducer(state = defaultState, action) { export const resetSelectedServer = () => ({ type: RESET_SELECTED_SERVER }); -export const _selectServer = (shlinkApiClient, serversService, serverId) => (dispatch) => { +export const _selectServer = (shlinkApiClient, serversService) => (serverId) => (dispatch) => { dispatch(resetShortUrlParams()); const selectedServer = serversService.findServerById(serverId); @@ -36,4 +35,4 @@ export const _selectServer = (shlinkApiClient, serversService, serverId) => (dis }); }; -export const selectServer = curry(_selectServer)(shlinkApiClient, serversService); +export const selectServer = _selectServer(shlinkApiClient, serversService); diff --git a/test/App.test.js b/test/App.test.js index 63b6cdc8..1a112ae7 100644 --- a/test/App.test.js +++ b/test/App.test.js @@ -1,13 +1,16 @@ import React from 'react'; import { shallow } from 'enzyme'; import { Route } from 'react-router-dom'; -import App from '../src/App'; -import MainHeader from '../src/common/MainHeader'; +import { identity } from 'ramda'; +import appFactory from '../src/App'; describe('', () => { let wrapper; + const MainHeader = () => ''; beforeEach(() => { + const App = appFactory(MainHeader, identity, identity, identity); + wrapper = shallow(); }); afterEach(() => wrapper.unmount()); diff --git a/test/common/Home.test.js b/test/common/Home.test.js index d44d9b0e..83e01ba2 100644 --- a/test/common/Home.test.js +++ b/test/common/Home.test.js @@ -2,7 +2,7 @@ import { shallow } from 'enzyme'; import { values } from 'ramda'; import React from 'react'; import * as sinon from 'sinon'; -import { HomeComponent } from '../../src/common/Home'; +import Home from '../../src/common/Home'; describe('', () => { let wrapped; @@ -15,7 +15,7 @@ describe('', () => { const createComponent = (props) => { const actualProps = { ...defaultProps, ...props }; - wrapped = shallow(); + wrapped = shallow(); return wrapped; }; diff --git a/test/servers/CreateServer.test.js b/test/servers/CreateServer.test.js index ecfde7ce..c9ce859f 100644 --- a/test/servers/CreateServer.test.js +++ b/test/servers/CreateServer.test.js @@ -2,7 +2,7 @@ import React from 'react'; import { shallow } from 'enzyme'; import { identity } from 'ramda'; import sinon from 'sinon'; -import { CreateServerComponent } from '../../src/servers/CreateServer'; +import CreateServer from '../../src/servers/CreateServer'; import ImportServersBtn from '../../src/servers/helpers/ImportServersBtn'; describe('', () => { @@ -17,11 +17,7 @@ describe('', () => { historyMock.push.resetHistory(); wrapper = shallow( - + ); }); afterEach(() => wrapper.unmount()); diff --git a/test/servers/reducers/selectedServer.test.js b/test/servers/reducers/selectedServer.test.js index e8cf174f..442172da 100644 --- a/test/servers/reducers/selectedServer.test.js +++ b/test/servers/reducers/selectedServer.test.js @@ -49,7 +49,7 @@ describe('selectedServerReducer', () => { const dispatch = sinon.spy(); const expectedDispatchCalls = 2; - _selectServer(ShlinkApiClientMock, ServersServiceMock, serverId)(dispatch); + _selectServer(ShlinkApiClientMock, ServersServiceMock)(serverId)(dispatch); expect(dispatch.callCount).toEqual(expectedDispatchCalls); expect(dispatch.firstCall.calledWith({ type: RESET_SHORT_URL_PARAMS })).toEqual(true); @@ -60,7 +60,7 @@ describe('selectedServerReducer', () => { }); it('invokes dependencies', () => { - _selectServer(ShlinkApiClientMock, ServersServiceMock, serverId)(() => {}); + _selectServer(ShlinkApiClientMock, ServersServiceMock)(serverId)(() => {}); expect(ShlinkApiClientMock.setConfig.callCount).toEqual(1); expect(ServersServiceMock.findServerById.callCount).toEqual(1);