summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorErik Larkö <erik@mullvad.net>2017-07-27 15:01:24 +0200
committerErik Larkö <erik@mullvad.net>2017-08-08 09:50:58 +0200
commite516d327f01dc2b0969657228257b2cac7942ad3 (patch)
tree0aac108255a7bc2e39300d840b6a825c6cae89f3
parent3ec32f23e93c8a487da82db86516ad12782b54f6 (diff)
downloadmullvadvpn-e516d327f01dc2b0969657228257b2cac7942ad3.tar.xz
mullvadvpn-e516d327f01dc2b0969657228257b2cac7942ad3.zip
Add CONNECTING action
-rw-r--r--app/lib/backend.js9
-rw-r--r--app/redux/connection/actions.js15
-rw-r--r--app/redux/connection/reducers.js5
-rw-r--r--test/connect.spec.js12
4 files changed, 33 insertions, 8 deletions
diff --git a/app/lib/backend.js b/app/lib/backend.js
index e5cf3765c4..bd0ca7ab63 100644
--- a/app/lib/backend.js
+++ b/app/lib/backend.js
@@ -227,15 +227,12 @@ export class Backend {
});
}
- connect(addr: string) {
+ connect(addr: string): Promise<void> {
- this._store.dispatch(connectionActions.connectionChange({
- status: 'connecting',
- serverAddress: addr,
- }));
+ this._store.dispatch(connectionActions.connectingTo(addr));
- this._ipc.setCountry(addr)
+ return this._ipc.setCountry(addr)
.then( () => {
return this._ipc.connect();
})
diff --git a/app/redux/connection/actions.js b/app/redux/connection/actions.js
index 0a7591fa11..7c808c8753 100644
--- a/app/redux/connection/actions.js
+++ b/app/redux/connection/actions.js
@@ -20,6 +20,10 @@ const copyIPAddress = () => {
};
+type ConnectingAction = {
+ type: 'CONNECTING',
+ serverAddress: string,
+};
type ConnectionChangeAction = {
type: 'CONNECTION_CHANGE',
@@ -42,7 +46,14 @@ type NewLocationAction = {
newLocation: Location,
};
-export type ConnectionAction = ConnectionChangeAction | NewPublicIpAction | NewLocationAction;
+export type ConnectionAction = ConnectionChangeAction | NewPublicIpAction | NewLocationAction | ConnectingAction;
+
+function connectingTo(serverAddress: string): ConnectingAction {
+ return {
+ type: 'CONNECTING',
+ serverAddress: serverAddress,
+ };
+}
function connectionChange(newData: $Shape<ConnectionReduxState>): ConnectionChangeAction {
return {
@@ -66,4 +77,4 @@ function newLocation(newLoc: Location): NewLocationAction {
}
-export default { connect, disconnect, copyIPAddress, connectionChange, newPublicIp, newLocation };
+export default { connect, disconnect, copyIPAddress, connectionChange, newPublicIp, newLocation, connectingTo };
diff --git a/app/redux/connection/reducers.js b/app/redux/connection/reducers.js
index 7bf9abebc9..3c98ea2e4e 100644
--- a/app/redux/connection/reducers.js
+++ b/app/redux/connection/reducers.js
@@ -34,6 +34,11 @@ export default function(state: ConnectionReduxState = initialState, action: Redu
return { ...state, ...{ clientIp: action.ip }};
case 'NEW_LOCATION':
return { ...state, ...action.newLocation };
+ case 'CONNECTING':
+ return { ...state, ...{
+ status: 'connecting',
+ serverAddress: action.serverAddress,
+ }};
default:
return state;
}
diff --git a/test/connect.spec.js b/test/connect.spec.js
index 6f7069f2c0..e2e531e179 100644
--- a/test/connect.spec.js
+++ b/test/connect.spec.js
@@ -45,6 +45,18 @@ describe('connect', () => {
}, done);
});
+ it('should update the state with the server address', () => {
+ const { store, backend } = setupBackendAndStore();
+ const arbitraryString = 'www.example.com';
+
+ return backend.connect(arbitraryString)
+ .then( () => {
+ const state = store.getState().connection;
+ expect(state.status).to.equal('connecting');
+ expect(state.serverAddress).to.equal(arbitraryString);
+ });
+ });
+
it('should correctly deduce \'connected\' from backend states', () => {
const { store, mockIpc } = setupBackendAndStore();