From c632cc6dea9062e7a3e80c9dffd2f660552060c8 Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Fri, 24 Apr 2015 19:59:51 +0200 Subject: [PATCH] Add tests. --- src/_h5ai/client/js/inc/model/item.js | 3 +- test/tests/unit/model/item.js | 95 ++++++++++++++++++++++++++- 2 files changed, 95 insertions(+), 3 deletions(-) diff --git a/src/_h5ai/client/js/inc/model/item.js b/src/_h5ai/client/js/inc/model/item.js index fe54ed11..06269787 100644 --- a/src/_h5ai/client/js/inc/model/item.js +++ b/src/_h5ai/client/js/inc/model/item.js @@ -164,7 +164,8 @@ modulejs.define('model/item', ['_', 'core/event', 'core/location', 'core/server' isCurrentParentFolder: function () { - return this === getItem(location.getAbsHref()).parent; + var item = getItem(location.getAbsHref()); + return Boolean(item) && this === item.parent; }, isDomain: function () { diff --git a/test/tests/unit/model/item.js b/test/tests/unit/model/item.js index eb02b0b3..7fb2367b 100644 --- a/test/tests/unit/model/item.js +++ b/test/tests/unit/model/item.js @@ -21,7 +21,8 @@ describe('module \'' + ID + '\'', function () { this.xServer = util.uniqObj(); this.xLocation = { forceEncoding: sinon.stub().returnsArg(0), - getDomain: sinon.stub().returns(util.uniqId()) + getDomain: sinon.stub().returns(util.uniqId()), + getAbsHref: sinon.stub().returns(util.uniqId()) }; this.applyFn = function () { @@ -196,6 +197,11 @@ describe('module \'' + ID + '\'', function () { assert.isObject(this.item.parent); }); + it('parent has same constructor', function () { + + assert.strictEqual(this.item.constructor, this.item.parent.constructor); + }); + it('sets isManaged to null', function () { assert.isNull(this.item.isManaged); @@ -206,9 +212,49 @@ describe('module \'' + ID + '\'', function () { assert.isPlainObject(this.item.content); assert.lengthOfKeys(this.item.content, 0); }); + + it('.isFolder() returns true', function () { + + assert.isTrue(this.item.isFolder()); + }); + + it('.isCurrentFolder() returns false', function () { + + assert.isFalse(this.item.isCurrentFolder()); + }); + + it('.isInCurrentFolder() returns false', function () { + + assert.isFalse(this.item.isInCurrentFolder()); + }); + + it('.isCurrentParentFolder() returns false', function () { + + assert.isFalse(this.item.isCurrentParentFolder()); + }); + + it('.isDomain() returns false', function () { + + assert.isFalse(this.item.isDomain()); + }); + + it('.isRoot() returns false', function () { + + assert.isFalse(this.item.isRoot()); + }); + + it('.isH5ai() returns false', function () { + + assert.isFalse(this.item.isH5ai()); + }); + + it('.isEmpty() returns true', function () { + + assert.isTrue(this.item.isEmpty()); + }); }); - describe('for file href other than rootHref', function () { + describe('for file href', function () { beforeEach(function () { @@ -251,6 +297,11 @@ describe('module \'' + ID + '\'', function () { assert.isObject(this.item.parent); }); + it('parent has same constructor', function () { + + assert.strictEqual(this.item.constructor, this.item.parent.constructor); + }); + it('sets isManaged to null', function () { assert.isNull(this.item.isManaged); @@ -261,6 +312,46 @@ describe('module \'' + ID + '\'', function () { assert.isPlainObject(this.item.content); assert.lengthOfKeys(this.item.content, 0); }); + + it('.isFolder() returns false', function () { + + assert.isFalse(this.item.isFolder()); + }); + + it('.isCurrentFolder() returns false', function () { + + assert.isFalse(this.item.isCurrentFolder()); + }); + + it('.isInCurrentFolder() returns false', function () { + + assert.isFalse(this.item.isInCurrentFolder()); + }); + + it('.isCurrentParentFolder() returns false', function () { + + assert.isFalse(this.item.isCurrentParentFolder()); + }); + + it('.isDomain() returns false', function () { + + assert.isFalse(this.item.isDomain()); + }); + + it('.isRoot() returns false', function () { + + assert.isFalse(this.item.isRoot()); + }); + + it('.isH5ai() returns false', function () { + + assert.isFalse(this.item.isH5ai()); + }); + + it('.isEmpty() returns true', function () { + + assert.isTrue(this.item.isEmpty()); + }); }); });