You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ns...@apache.org on 2013/12/14 12:41:22 UTC
[16/51] [partial] Bring Fauxton directories together
http://git-wip-us.apache.org/repos/asf/couchdb/blob/c14b2991/share/www/fauxton/src/test/core/navbarSpec.js
----------------------------------------------------------------------
diff --git a/share/www/fauxton/src/test/core/navbarSpec.js b/share/www/fauxton/src/test/core/navbarSpec.js
new file mode 100644
index 0000000..ec3e71f
--- /dev/null
+++ b/share/www/fauxton/src/test/core/navbarSpec.js
@@ -0,0 +1,107 @@
+// 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.
+define([
+ 'modules/fauxton/base',
+ 'testUtils'
+], function (Fauxton, testUtils) {
+ var assert = testUtils.assert,
+ NavBar = Fauxton.NavBar;
+
+ describe('NavBar', function () {
+
+ describe('adding links', function () {
+ var navBar;
+
+ beforeEach(function () {
+ navBar = new NavBar();
+ navBar.navLinks = [];
+ navBar.bottomNavLinks = [];
+ navBar.footerNavLinks = [];
+ });
+
+ it('Should add link to navlinks', function () {
+ navBar.addLink({href: '#/test', title: 'Test Title'});
+
+ assert.equal(navBar.navLinks.length, 1);
+ assert.equal(navBar.footerNavLinks.length, 0);
+ assert.equal(navBar.bottomNavLinks.length, 0);
+ });
+
+ it('Should add link to bottom links', function () {
+ navBar.addLink({href: '#/test', bottomNav: true, title: 'Test Title'});
+
+ assert.equal(navBar.bottomNavLinks.length, 1);
+ assert.equal(navBar.navLinks.length, 0);
+ assert.equal(navBar.footerNavLinks.length, 0);
+ });
+
+ it('Should add link to footer links', function () {
+ navBar.addLink({href: '#/test', footerNav: true, title: 'Test Title'});
+
+ assert.equal(navBar.footerNavLinks.length, 1);
+ assert.equal(navBar.bottomNavLinks.length, 0);
+ assert.equal(navBar.navLinks.length, 0);
+ });
+ });
+
+ describe('removing links', function () {
+ var navBar;
+
+ beforeEach(function () {
+ navBar = new NavBar();
+ navBar.navLinks = [];
+ navBar.bottomNavLinks = [];
+ navBar.footerNavLinks = [];
+ navBar.addLink({
+ href: '#/test',
+ footerNav: true,
+ title: 'Test Title Footer'
+ });
+
+ navBar.addLink({
+ href: '#/test',
+ bottomNav: true,
+ title: 'Test Title Bottom'
+ });
+
+ navBar.addLink({
+ href: '#/test',
+ title: 'Test Title'
+ });
+ });
+
+ it("should remove links from list", function () {
+ navBar.removeLink({
+ title: 'Test Title Footer',
+ footerNav: true
+ });
+
+ assert.equal(navBar.footerNavLinks.length, 0);
+ assert.equal(navBar.bottomNavLinks.length, 1);
+ assert.equal(navBar.navLinks.length, 1);
+ });
+
+ it("Should call render after removing links", function () {
+ var renderSpy = sinon.stub(navBar,'render');
+
+ navBar.removeLink({
+ title: 'Test Title Footer',
+ footerNav: true
+ });
+
+ assert.ok(renderSpy.calledOnce);
+ });
+
+ });
+ });
+
+});
http://git-wip-us.apache.org/repos/asf/couchdb/blob/c14b2991/share/www/fauxton/src/test/core/paginateSpec.js
----------------------------------------------------------------------
diff --git a/share/www/fauxton/src/test/core/paginateSpec.js b/share/www/fauxton/src/test/core/paginateSpec.js
new file mode 100644
index 0000000..114c434
--- /dev/null
+++ b/share/www/fauxton/src/test/core/paginateSpec.js
@@ -0,0 +1,109 @@
+// 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.
+define([
+ 'api',
+ 'modules/fauxton/components',
+ 'modules/documents/resources',
+ 'testUtils',
+ 'app'
+], function (FauxtonAPI, Views, Models, testUtils, app) {
+ var assert = testUtils.assert,
+ ViewSandbox = testUtils.ViewSandbox;
+
+
+ describe('IndexPaginate', function () {
+ var viewSandbox, paginate, collection, navigateMock;
+ beforeEach(function () {
+ app.router = {
+ navigate: function () {}
+ };
+
+ collection = new Models.IndexCollection([{
+ id:'myId1',
+ doc: 'num1'
+ },
+ {
+ id:'myId2',
+ doc: 'num2'
+ }], {
+ database: {id: 'databaseId'},
+ design: '_design/myDoc'
+ });
+
+ paginate = new Views.IndexPagination({
+ collection: collection,
+ previousUrlfn: function () {},
+ nextUrlfn: function () {},
+ canShowPreviousfn: function () { return true; },
+ canShowNextfn: function () { return true;}
+ });
+ viewSandbox = new ViewSandbox();
+ viewSandbox.renderView(paginate);
+ });
+
+ afterEach(function () {
+ viewSandbox.remove();
+ });
+
+ describe('#next', function () {
+ beforeEach(function () {
+ //do this so it doesn't throw an error on other unwired up components
+ FauxtonAPI.triggerRouteEvent = function () {};
+ //FauxtonAPI.triggerRouteEvent.restore && FauxtonAPI.triggerRouteEvent.restore();
+ //FauxtonAPI.navigate.restore && FauxtonAPI.navigate.restore();
+ });
+
+ it('Should navigate', function () {
+ var navigateMock = sinon.spy(FauxtonAPI, 'navigate');
+
+ paginate.$('a#next').click();
+
+ assert.ok(navigateMock.calledOnce);
+ FauxtonAPI.navigate.restore();
+ });
+
+ it('Should trigger routeEvent', function () {
+ var navigateMock = sinon.spy(FauxtonAPI, 'triggerRouteEvent');
+
+ paginate.$('a#next').click();
+
+ assert.ok(navigateMock.calledOnce);
+ FauxtonAPI.triggerRouteEvent.restore();
+ });
+
+ });
+
+
+ describe('#previous', function () {
+
+ it('Should navigate', function () {
+ var navigateMock = sinon.spy(FauxtonAPI, 'navigate');
+
+ paginate.$('a#previous').click();
+
+ assert.ok(navigateMock.calledOnce);
+ FauxtonAPI.navigate.restore();
+ });
+
+ it('Should trigger routeEvent', function () {
+ var navigateMock = sinon.spy(FauxtonAPI, 'triggerRouteEvent');
+
+ paginate.$('a#previous').click();
+
+ assert.ok(navigateMock.calledOnce);
+ FauxtonAPI.triggerRouteEvent.restore();
+ });
+
+ });
+
+ });
+});
http://git-wip-us.apache.org/repos/asf/couchdb/blob/c14b2991/share/www/fauxton/src/test/core/routeObjectSpec.js
----------------------------------------------------------------------
diff --git a/share/www/fauxton/src/test/core/routeObjectSpec.js b/share/www/fauxton/src/test/core/routeObjectSpec.js
new file mode 100644
index 0000000..987d5b7
--- /dev/null
+++ b/share/www/fauxton/src/test/core/routeObjectSpec.js
@@ -0,0 +1,105 @@
+// 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.
+define([
+ 'api',
+ 'testUtils'
+], function (FauxtonAPI, testUtils) {
+ var assert = testUtils.assert,
+ RouteObject = FauxtonAPI.RouteObject;
+
+ describe('RouteObjects', function () {
+
+ describe('renderWith', function () {
+ var TestRouteObject, testRouteObject, mockLayout;
+
+ beforeEach(function () {
+ TestRouteObject = RouteObject.extend({
+ crumbs: ['mycrumbs']
+ });
+
+ testRouteObject = new TestRouteObject();
+ var apiBar = {};
+ apiBar.hide = sinon.spy();
+
+ // Need to find a better way of doing this
+ mockLayout = {
+ setTemplate: sinon.spy(),
+ clearBreadcrumbs: sinon.spy(),
+ setView: sinon.spy(),
+ renderView: sinon.spy(),
+ hooks: [],
+ setBreadcrumbs: sinon.spy(),
+ apiBar: apiBar
+ };
+
+ });
+
+ it('Should set template for first render ', function () {
+ testRouteObject.renderWith('the-route', mockLayout, 'args');
+
+ assert.ok(mockLayout.setTemplate.calledOnce, 'setTempalte was called');
+ });
+
+ it('Should not set template after first render', function () {
+ testRouteObject.renderWith('the-route', mockLayout, 'args');
+
+ testRouteObject.renderWith('the-route', mockLayout, 'args');
+
+ assert.ok(mockLayout.setTemplate.calledOnce, 'SetTemplate not meant to be called');
+ });
+
+ it('Should clear breadcrumbs', function () {
+ testRouteObject.renderWith('the-route', mockLayout, 'args');
+ assert.ok(mockLayout.clearBreadcrumbs.calledOnce, 'Clear Breadcrumbs called');
+ });
+
+ it('Should set breadcrumbs when breadcrumbs exist', function () {
+ testRouteObject.renderWith('the-route', mockLayout, 'args');
+ assert.ok(mockLayout.setBreadcrumbs.calledOnce, 'Set Breadcrumbs was called');
+ });
+
+ it("Should call establish of routeObject", function () {
+ var establishSpy = sinon.spy(testRouteObject,"establish");
+
+ testRouteObject.renderWith('the-route', mockLayout, 'args');
+ assert.ok(establishSpy.calledOnce, 'Calls establish');
+ });
+
+ it("Should render views", function () {
+ var view = new FauxtonAPI.View(),
+ getViewsSpy = sinon.stub(testRouteObject,"getViews"),
+ viewSpy = sinon.stub(view, "establish");
+
+ view.hasRendered = false;
+ getViewsSpy.returns({'#view': view});
+
+ testRouteObject.renderWith('the-route', mockLayout, 'args');
+ assert.ok(viewSpy.calledOnce, 'Should render view');
+ });
+
+ it("Should not re-render a view", function () {
+ var view = new FauxtonAPI.View(),
+ getViewsSpy = sinon.stub(testRouteObject,"getViews"),
+ viewSpy = sinon.stub(view, "establish");
+
+ view.hasRendered = true;
+ getViewsSpy.returns({'#view': view});
+
+ testRouteObject.renderWith('the-route', mockLayout, 'args');
+ assert.notOk(viewSpy.calledOnce, 'Should render view');
+ });
+ });
+
+ });
+
+
+});