fix bugs and add tests

Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/0ffc5797
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/0ffc5797
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/0ffc5797

Branch: refs/heads/new-replication
Commit: 0ffc579706bc486c44df6a016888be0d7b0d505e
Parents: 37789eb
Author: Garren Smith <garren.sm...@gmail.com>
Authored: Tue Sep 13 16:30:33 2016 +0200
Committer: Garren Smith <garren.sm...@gmail.com>
Committed: Wed Sep 14 17:22:30 2016 +0200

----------------------------------------------------------------------
 app/addons/replication/controller.js           | 18 ++++++++-
 app/addons/replication/helpers.js              |  7 ++--
 app/addons/replication/tests/controllerSpec.js | 38 ++++++++++++++++---
 app/addons/replication/tests/helpersSpec.js    | 41 +++++++++++++++++++++
 4 files changed, 95 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ffc5797/app/addons/replication/controller.js
----------------------------------------------------------------------
diff --git a/app/addons/replication/controller.js 
b/app/addons/replication/controller.js
index ac69326..19d7e6b 100644
--- a/app/addons/replication/controller.js
+++ b/app/addons/replication/controller.js
@@ -166,11 +166,19 @@ export default class ReplicationController extends 
React.Component {
   }
 
   confirmButtonEnabled () {
-    const {localSourceDatabaseKnown, replicationSource, replicationTarget, 
localTargetDatabaseKnown} = this.state;
+    const {
+      remoteSource,
+      localSourceDatabaseKnown,
+      replicationSource,
+      replicationTarget,
+      localTargetDatabaseKnown,
+      targetDatabase
+    } = this.state;
 
     if (!replicationSource || !replicationTarget) {
       return false;
     }
+
     if (replicationSource === Constants.REPLICATION_SOURCE.LOCAL && 
!localSourceDatabaseKnown) {
       return false;
     }
@@ -178,6 +186,14 @@ export default class ReplicationController extends 
React.Component {
       return false;
     }
 
+    if (replicationTarget === Constants.REPLICATION_TARGET.NEW_LOCAL_DATABASE 
&& !targetDatabase) {
+      return false;
+    }
+
+    if (replicationSource === Constants.REPLICATION_SOURCE.REMOTE && 
remoteSource === "") {
+      return false;
+    }
+
     return true;
   }
 

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ffc5797/app/addons/replication/helpers.js
----------------------------------------------------------------------
diff --git a/app/addons/replication/helpers.js 
b/app/addons/replication/helpers.js
index 807cedd..52472fa 100644
--- a/app/addons/replication/helpers.js
+++ b/app/addons/replication/helpers.js
@@ -10,10 +10,11 @@
 // License for the specific language governing permissions and limitations 
under
 // the License.
 
+import _ from 'underscore';
+
 const getDatabaseLabel = db => {
-  let dbString = (_.isString(db)) ? db.trim().replace(/\/$/, '') : db.url;
-  const matches = dbString.match(/[^\/]+$/, '');
-  return matches[0];
+  const dbString = (_.isString(db)) ? db.trim().replace(/\/$/, '') : db.url;
+  return (new URL(dbString)).pathname.slice(1);
 };
 
 export default {

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ffc5797/app/addons/replication/tests/controllerSpec.js
----------------------------------------------------------------------
diff --git a/app/addons/replication/tests/controllerSpec.js 
b/app/addons/replication/tests/controllerSpec.js
index 77558f5..4489e00 100644
--- a/app/addons/replication/tests/controllerSpec.js
+++ b/app/addons/replication/tests/controllerSpec.js
@@ -19,8 +19,7 @@ import Controller from '../controller';
 import Constants from '../constants';
 
 const store = Stores.replicationStore;
-
-var assert = utils.assert;
+const assert = utils.assert;
 
 describe('Replication Controller', () => {
 
@@ -37,16 +36,45 @@ describe('Replication Controller', () => {
         targetDatabase: 'new-database',
       });
 
-      console.log(controller);
-      assert.ok(controller.validate());
+      console.log(controller.instance());
+      assert.ok(controller.instance().validate());
     });
 
   });
 
   describe('confirmButtonEnabled', () => {
 
-    it('returns false if remote database has no text', () => {
+    it('returns false for default', () => {
+      const controller = mount(<Controller />);
+
+      assert.notOk(controller.instance().confirmButtonEnabled());
+    });
+
+    it('returns false for empty remote source', () => {
+      const controller = mount(<Controller />);
+
+      controller.setState({
+        replicationSource: Constants.REPLICATION_SOURCE.REMOTE,
+        replicationTarget: Constants.REPLICATION_TARGET.NEW_LOCAL_DATABASE,
+        localTargetDatabaseKnown: false,
+        localSourceDatabaseKnown: false,
+      });
+
+      assert.notOk(controller.instance().confirmButtonEnabled());
+    });
+
+    it('returns false for empty local source', () => {
+      const controller = mount(<Controller />);
+
+      controller.setState({
+        replicationSource: Constants.REPLICATION_SOURCE.REMOTE,
+        replicationTarget: Constants.REPLICATION_TARGET.NEW_LOCAL_DATABASE,
+        localTargetDatabaseKnown: false,
+        localSourceDatabaseKnown: false,
+        remoteSource: 'db'
+      });
 
+      assert.notOk(controller.instance().confirmButtonEnabled());
     });
 
   });

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ffc5797/app/addons/replication/tests/helpersSpec.js
----------------------------------------------------------------------
diff --git a/app/addons/replication/tests/helpersSpec.js 
b/app/addons/replication/tests/helpersSpec.js
new file mode 100644
index 0000000..5e2b1c3
--- /dev/null
+++ b/app/addons/replication/tests/helpersSpec.js
@@ -0,0 +1,41 @@
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy 
of
+// the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations 
under
+// the License.
+
+import utils from "../../../../test/mocha/testUtils";
+import helpers from '../helpers';
+const assert = utils.assert;
+
+describe('Replication Helpers', () => {
+
+  describe('getDatabaseLabel', () => {
+
+    it('returns database name for string', () => {
+      const db = 'http://tester:testerpass@127.0.0.1/fancy/db/name';
+
+      const dbName = helpers.getDatabaseLabel(db);
+      assert.deepEqual('fancy/db/name', dbName);
+
+    });
+
+    it('returns database name for object', () => {
+      const db = {
+        url: 'http://tester:testerpass@127.0.0.1/fancy'
+      };
+
+      const dbName = helpers.getDatabaseLabel(db);
+      assert.deepEqual('fancy', dbName);
+
+    });
+
+  });
+
+});

Reply via email to