Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 4E025200B89 for ; Wed, 21 Sep 2016 17:18:55 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 4CA14160AEB; Wed, 21 Sep 2016 15:18:55 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 6DC82160AE3 for ; Wed, 21 Sep 2016 17:18:54 +0200 (CEST) Received: (qmail 85642 invoked by uid 500); 21 Sep 2016 15:18:53 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 85079 invoked by uid 99); 21 Sep 2016 15:18:53 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Sep 2016 15:18:53 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C53E7E00C4; Wed, 21 Sep 2016 15:18:52 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: garren@apache.org To: commits@couchdb.apache.org Date: Wed, 21 Sep 2016 15:18:59 -0000 Message-Id: <9496edf795d54b389c4bd9441d26e2c6@git.apache.org> In-Reply-To: <110d4ab9069244b3896f97c915df459f@git.apache.org> References: <110d4ab9069244b3896f97c915df459f@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [08/29] fauxton commit: updated refs/heads/new-replication to b0541e1 archived-at: Wed, 21 Sep 2016 15:18:55 -0000 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 Authored: Tue Sep 13 16:30:33 2016 +0200 Committer: Garren Smith 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(); + + assert.notOk(controller.instance().confirmButtonEnabled()); + }); + + it('returns false for empty remote source', () => { + const controller = mount(); + + 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.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); + + }); + + }); + +});