couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gar...@apache.org
Subject [12/13] fauxton commit: updated refs/heads/backbone.layout-upgrade to 755eb7a
Date Tue, 12 Aug 2014 14:56:20 GMT
Fix failing tests and add more 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/b82b8ed5
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/b82b8ed5
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/b82b8ed5

Branch: refs/heads/backbone.layout-upgrade
Commit: b82b8ed50a5a6087e1e530f6fbefb9034bc9f51a
Parents: 09805dd
Author: Garren Smith <garren.smith@gmail.com>
Authored: Tue Aug 12 13:13:48 2014 +0200
Committer: Garren Smith <garren.smith@gmail.com>
Committed: Tue Aug 12 16:49:56 2014 +0200

----------------------------------------------------------------------
 app/core/layout.js                | 33 ++------------
 app/core/tests/layoutSpec.js      | 79 +++++++++++++++++++++++++++++++---
 app/core/tests/routeObjectSpec.js |  6 +++
 3 files changed, 83 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/b82b8ed5/app/core/layout.js
----------------------------------------------------------------------
diff --git a/app/core/layout.js b/app/core/layout.js
index 11992cb..84fc71e 100644
--- a/app/core/layout.js
+++ b/app/core/layout.js
@@ -10,35 +10,6 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
-/*define(function(require, exports, module) {
-  var Backbone = require("backbone");
-  var LayoutManager = require("plugins/backbone.layoutmanager");
-
-  var Layout = Backbone.Layout.extend({
-    template: "templates/layouts/with_sidebar",
-
-    // Either tests or source are expecting synchronous renders, so disable
-    // asynchronous rendering improvements.
-    useRAF: true,
-
-    setTemplate: function(template) {
-      if (template.prefix){
-        this.template = template.prefix + template.name;
-      } else{
-        this.template = "templates/layouts/" + template;
-      }
-
-      // If we're changing layouts all bets are off, so kill off all the
-      // existing views in the layout.
-      this.removeView();
-      this.render();
-    }
-  });
-
-  module.exports = Layout;
-
-});*/
-
 define([
   "backbone", 
   "plugins/backbone.layoutmanager"
@@ -52,6 +23,8 @@ define([
     });
 
     this.layoutViews = {};
+    //this views don't ever get removed. An example of this is the main navigation sidebar
+    this.permanentViews = {};
     this.el = this.layout.el;
   };
 
@@ -83,6 +56,8 @@ define([
 
       if (!keep) {
         this.layoutViews[selector] = view;
+      } else {
+        this.permanentViews[selector] = view;
       }
 
       return view;

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/b82b8ed5/app/core/tests/layoutSpec.js
----------------------------------------------------------------------
diff --git a/app/core/tests/layoutSpec.js b/app/core/tests/layoutSpec.js
index 2b87173..1ae5675 100644
--- a/app/core/tests/layoutSpec.js
+++ b/app/core/tests/layoutSpec.js
@@ -27,24 +27,24 @@ define([
       it("Should set template without prefix", function () {
         layout.setTemplate('myTemplate');
 
-        assert.equal(layout.template, 'templates/layouts/myTemplate');
+        assert.equal(layout.layout.template, 'templates/layouts/myTemplate');
 
       });
 
       it("Should set template with prefix", function () {
         layout.setTemplate({name: 'myTemplate', prefix: 'myPrefix/'});
 
-        assert.equal(layout.template, 'myPrefix/myTemplate');
+        assert.equal(layout.layout.template, 'myPrefix/myTemplate');
       });
 
       it("Should remove old views", function () {
-        var view = new FauxtonAPI.Layout();
+        var view = new FauxtonAPI.View();
 
-        layout.setView('selector', view);
+        layout.setView('#selector', view);
 
-        var mockRemove = sinon.spy(view, 'remove');
+        var removeSpy = sinon.spy(view, 'removeView');
         layout.setTemplate('myTemplate');
-        assert.ok(mockRemove.calledOnce);
+        assert.ok(removeSpy.calledOnce);
 
       });
 
@@ -58,5 +58,72 @@ define([
       });
 
     });
+
+    describe('#setView', function () {
+      var view;
+      beforeEach(function () {
+        view = new FauxtonAPI.View();
+      });
+
+      it("Should keep record of view", function () {
+        layout.setView('.selector', view);
+        assert.equal(view, layout.layoutViews['.selector']);
+      });
+
+      it("Should not keep record of view if keep is false", function () {
+        layout.setView('.selector', view, true);
+        assert.ok(_.isUndefined(layout.layoutViews['.selector']));
+        assert.equal(view, layout.permanentViews['.selector']);
+      });
+
+    });
+
+    describe('#removeView', function () {
+      var view;
+
+      beforeEach(function () {
+        view = new FauxtonAPI.View();
+        layout.setView('#selector', view);
+      });
+
+      it('Should remove view from layout', function () {
+        var removeSpy = sinon.spy(layout.layout, 'removeView');
+
+        layout.removeView('#selector');
+        assert.ok(removeSpy.calledOnce);
+      });
+
+      it('Should remove view from list of active views', function () {
+        layout.setView('#selector', view);
+        layout.removeView('#selector');
+
+        assert.ok(_.isUndefined(layout.layoutViews['#selector']));
+      });
+
+      it("should return false if view doesn't exist", function () {
+        assert.notOk(layout.removeView('#fake'));
+      });
+
+    });
+
+    describe('#renderView', function () {
+      var view;
+
+      beforeEach(function () {
+        view = new FauxtonAPI.View();
+        layout.setView('#selector', view);
+      });
+
+      it('should render view', function () {
+        var renderSpy = sinon.spy(view, 'render');
+        layout.renderView('#selector');
+        assert.ok(renderSpy.calledOnce);
+      });
+
+      it('should not render a non-existing view', function () {
+        assert.notOk(layout.renderView('#fake'));
+      });
+
+    });
   });
 });

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/b82b8ed5/app/core/tests/routeObjectSpec.js
----------------------------------------------------------------------
diff --git a/app/core/tests/routeObjectSpec.js b/app/core/tests/routeObjectSpec.js
index 2fca94d..f3f4b48 100644
--- a/app/core/tests/routeObjectSpec.js
+++ b/app/core/tests/routeObjectSpec.js
@@ -71,7 +71,13 @@ define([
             viewSpy = sinon.stub(view, "establish");
         
         view.hasRendered = false;
+        view.promise = function () { 
+          var promise = $.Deferred();
+          promise.resolve();
+          return promise;
+        };
         getViewsSpy.returns({'#view': view});
+        mockLayout.renderView = function () { return view;};
 
         testRouteObject.renderWith('the-route', mockLayout, 'args');
         assert.ok(viewSpy.calledOnce, 'Should render view');


Mime
View raw message