diff --git a/src/servers/ServersDropdown.js b/src/servers/ServersDropdown.js index 4a060946..20583787 100644 --- a/src/servers/ServersDropdown.js +++ b/src/servers/ServersDropdown.js @@ -1,6 +1,5 @@ import { isEmpty, values } from 'ramda'; import React from 'react'; -import { Link } from 'react-router-dom'; import { DropdownItem, DropdownMenu, DropdownToggle, UncontrolledDropdown } from 'reactstrap'; import PropTypes from 'prop-types'; import { serverType } from './prop-types'; @@ -11,11 +10,20 @@ const ServersDropdown = (serversExporter) => class ServersDropdown extends React selectedServer: serverType, selectServer: PropTypes.func, listServers: PropTypes.func, + history: PropTypes.shape({ + push: PropTypes.func, + }), }; renderServers = () => { const { servers: { list, loading }, selectedServer, selectServer } = this.props; const servers = values(list); + const { push } = this.props.history; + const loadServer = (id) => { + selectServer(id) + .then(() => push(`/server/${id}/list-short-urls/1`)) + .catch(() => {}); + }; if (loading) { return Trying to load servers...; @@ -28,15 +36,7 @@ const ServersDropdown = (serversExporter) => class ServersDropdown extends React return ( {servers.map(({ name, id }) => ( - selectServer(id)} - > + loadServer(id)}> {name} ))} diff --git a/src/servers/services/provideServices.js b/src/servers/services/provideServices.js index 12755474..7c87157a 100644 --- a/src/servers/services/provideServices.js +++ b/src/servers/services/provideServices.js @@ -16,6 +16,7 @@ const provideServices = (bottle, connect, withRouter) => { bottle.decorator('CreateServer', connect([ 'selectedServer' ], [ 'createServer', 'resetSelectedServer' ])); bottle.serviceFactory('ServersDropdown', ServersDropdown, 'ServersExporter'); + bottle.decorator('ServersDropdown', withRouter); bottle.decorator('ServersDropdown', connect([ 'servers', 'selectedServer' ], [ 'listServers', 'selectServer' ])); bottle.serviceFactory('DeleteServerModal', () => DeleteServerModal); diff --git a/test/servers/ServersDropdown.test.js b/test/servers/ServersDropdown.test.js index c5bc0dd4..2120e695 100644 --- a/test/servers/ServersDropdown.test.js +++ b/test/servers/ServersDropdown.test.js @@ -15,15 +15,18 @@ describe('', () => { }, loading: false, }; + const history = { + push: jest.fn(), + }; beforeEach(() => { ServersDropdown = serversDropdownCreator({}); - wrapped = shallow(); + wrapped = shallow(); }); afterEach(() => wrapped.unmount()); - it('contains the list of servers', () => - expect(wrapped.find(DropdownItem).filter('[to]')).toHaveLength(values(servers.list).length)); + it('contains the list of servers, the divider and the export button', () => + expect(wrapped.find(DropdownItem)).toHaveLength(values(servers.list).length + 2)); it('contains a toggle with proper title', () => expect(wrapped.find(DropdownToggle)).toHaveLength(1)); @@ -36,7 +39,9 @@ describe('', () => { }); it('shows a message when no servers exist yet', () => { - wrapped = shallow(); + wrapped = shallow( + + ); const item = wrapped.find(DropdownItem); expect(item).toHaveLength(1); @@ -45,7 +50,9 @@ describe('', () => { }); it('shows a message when loading', () => { - wrapped = shallow(); + wrapped = shallow( + + ); const item = wrapped.find(DropdownItem); expect(item).toHaveLength(1);