1
0
Fork 0

Started fixing documentsView specs. Most of them were broken

This commit is contained in:
Michael Hackstein 2015-01-26 09:36:30 +00:00
parent c19ee02a93
commit 6ba4e96a43
2 changed files with 185 additions and 462 deletions

View File

@ -81,7 +81,6 @@
"click #documents_prev" : "prevDocuments", "click #documents_prev" : "prevDocuments",
"click #documents_next" : "nextDocuments", "click #documents_next" : "nextDocuments",
"click #confirmDeleteBtn" : "confirmDelete", "click #confirmDeleteBtn" : "confirmDelete",
"keyup #createEdge" : "listenKey",
"click .key" : "nop", "click .key" : "nop",
"keyup" : "returnPressedHandler", "keyup" : "returnPressedHandler",
"keydown .queryline input" : "filterValueKeydown", "keydown .queryline input" : "filterValueKeydown",
@ -151,9 +150,6 @@
event.stopPropagation(); event.stopPropagation();
}, },
listenKey: function (e) {
},
resetView: function () { resetView: function () {
//clear all input/select - fields //clear all input/select - fields
$('input').val(''); $('input').val('');
@ -868,7 +864,7 @@
}, },
drawTable: function() { drawTable: function() {
this.tableView.setElement(this.$(this.table)).render(); this.tableView.setElement($(this.table)).render();
// we added some icons, so we need to fix their tooltips // we added some icons, so we need to fix their tooltips
arangoHelper.fixTooltips(".icon_arangodb, .arangoicon", "top"); arangoHelper.fixTooltips(".icon_arangodb, .arangoicon", "top");
@ -901,7 +897,7 @@
render: function() { render: function() {
$(this.el).html(this.template.render({})); $(this.el).html(this.template.render({}));
this.tableView.setElement(this.$(this.table)).drawLoading(); this.tableView.setElement($(this.table)).drawLoading();
this.collectionContext = this.collectionsStore.getPosition( this.collectionContext = this.collectionsStore.getPosition(
this.collection.collectionID this.collection.collectionID

View File

@ -1,21 +1,81 @@
/*jshint browser: true */ /*jshint browser: true */
/*jshint unused: false */ /*jshint unused: false */
/*global $, arangoHelper, jasmine, describe, beforeEach, afterEach, it, spyOn, expect*/ /*global $, arangoHelper, jasmine, describe, beforeEach, afterEach, it, spyOn, expect, _*/
(function () { (function () {
"use strict"; "use strict";
describe("The documents view", function () { describe("The documents view", function () {
var view, jQueryDummy; var view, jQueryDummy, arangoDocStoreDummy, arangoDocsStoreDummy, arangoCollectionsDummy;
beforeEach(function () { beforeEach(function () {
arangoDocStoreDummy = {
createTypeDocument: function () {
throw "Should be a spy";
},
createTypeEdge: function () {
throw "Should be a spy";
},
deleteDocument: function () {
throw "Should be a spy";
},
deleteEdge: function () {
throw "Should be a spy";
}
};
arangoDocsStoreDummy = {
models: [],
totalPages: 1,
currentPage: 1,
documentsCount: 0,
setToFirst: function () {
throw "Should be a spy.";
},
addFilter: function () {
throw "Should be a spy.";
},
resetFilter: function () {
throw "Should be a spy.";
},
getDocuments: function () {
throw "Should be a spy";
},
getPageSize: function() {
return 10;
},
loadTotal: function () {
throw "Should be a spy";
},
updloadDocuments: function () {
throw "Should be a spy";
},
each: function (cb) {
this.models.forEach(cb);
},
size: function () {
return this.models.length;
},
getLastPageNumber: function () {
return this.totalPages;
},
getPage: function () {
return this.currentPage;
},
getTotal: function () {
return this.documentsCount;
},
collectionID: "collection"
};
window.App = { window.App = {
navigate: function () { navigate: function () {
throw "This should be a spy"; throw "This should be a spy";
} }
}; };
view = new window.DocumentsView(); view = new window.DocumentsView({
documentStore: arangoDocStoreDummy,
collection: arangoDocsStoreDummy
});
}); });
afterEach(function () { afterEach(function () {
@ -31,41 +91,52 @@
prev: null, prev: null,
next: null next: null
}); });
expect(view.alreadyClicked).toEqual(false);
expect(view.table).toEqual('#documentsTableID'); expect(view.table).toEqual('#documentsTableID');
expect(view.events).toEqual({ var expectedEvents = {
"click #collectionPrev": "prevCollection", "click #collectionPrev" : "prevCollection",
"click #collectionNext": "nextCollection", "click #collectionNext" : "nextCollection",
"click #filterCollection": "filterCollection", "click #filterCollection" : "filterCollection",
"click #indexCollection": "indexCollection", "click #markDocuments" : "editDocuments",
"click #importCollection": "importCollection", "click #indexCollection" : "indexCollection",
"click #filterSend": "sendFilter", "click #importCollection" : "importCollection",
"click #addFilterItem": "addFilterItem", "click #exportCollection" : "exportCollection",
"click .removeFilterItem": "removeFilterItem", "click #filterSend" : "sendFilter",
"click #confirmCreateEdge": "addEdge", "click #addFilterItem" : "addFilterItem",
"click #documentsTableID tr": "clicked", "click .removeFilterItem" : "removeFilterItem",
"click #deleteDoc": "remove", "click #deleteSelected" : "deleteSelectedDocs",
"click #addDocumentButton": "addDocument", "click #moveSelected" : "moveSelectedDocs",
"click #documents_first": "firstDocuments", "click #addDocumentButton" : "addDocumentModal",
"click #documents_last": "lastDocuments", "click #documents_first" : "firstDocuments",
"click #documents_prev": "prevDocuments", "click #documents_last" : "lastDocuments",
"click #documents_next": "nextDocuments", "click #documents_prev" : "prevDocuments",
"click #confirmDeleteBtn": "confirmDelete", "click #documents_next" : "nextDocuments",
"keyup #createEdge": "listenKey", "click #confirmDeleteBtn" : "confirmDelete",
"click .key": "nop", "click .key" : "nop",
"keyup": "returnPressedHandler", "keyup" : "returnPressedHandler",
"keydown .filterValue": "filterValueKeydown", "keydown .queryline input" : "filterValueKeydown",
"click #importModal": "showImportModal", "click #importModal" : "showImportModal",
"click #resetView": "resetView", "click #resetView" : "resetView",
"click #confirmDocImport": "startUpload", "click #confirmDocImport" : "startUpload",
"change #newIndexType": "selectIndexType", "click #exportDocuments" : "startDownload",
"click #createIndex": "createIndex", "change #newIndexType" : "selectIndexType",
"click .deleteIndex": "prepDeleteIndex", "click #createIndex" : "createIndex",
"click #confirmDeleteIndexBtn": "deleteIndex", "click .deleteIndex" : "prepDeleteIndex",
"click #documentsToolbar ul": "resetIndexForms", "click #confirmDeleteIndexBtn" : "deleteIndex",
"click #indexHeader #addIndex": "toggleNewIndexView", "click #documentsToolbar ul" : "resetIndexForms",
"click #indexHeader #cancelIndex": "toggleNewIndexView" "click #indexHeader #addIndex" : "toggleNewIndexView",
}); "click #indexHeader #cancelIndex" : "toggleNewIndexView",
"change #documentSize" : "setPagesize",
"change #docsSort" : "setSorting"
};
var expectedKeys = Object.keys(expectedEvents);
var i, key;
for (i = 0; i < expectedKeys.length; ++i) {
key = expectedKeys[i];
expect(view.events[key]).toEqual(expectedEvents[key]);
}
expect(
_.difference(Object.keys(view.events), expectedKeys)
).toEqual([]);
}); });
@ -132,6 +203,9 @@
jQueryDummy = { jQueryDummy = {
attr: function () { attr: function () {
return false; return false;
},
is: function () {
return false;
} }
}; };
spyOn(jQueryDummy, "attr").andCallThrough(); spyOn(jQueryDummy, "attr").andCallThrough();
@ -150,6 +224,9 @@
jQueryDummy = { jQueryDummy = {
attr: function () { attr: function () {
return false; return false;
},
is: function () {
return false;
} }
}; };
spyOn(jQueryDummy, "attr"); spyOn(jQueryDummy, "attr");
@ -168,6 +245,9 @@
jQueryDummy = { jQueryDummy = {
attr: function () { attr: function () {
return true; return true;
},
is: function () {
return false;
} }
}; };
spyOn(jQueryDummy, "attr"); spyOn(jQueryDummy, "attr");
@ -209,21 +289,11 @@
expect(event.stopPropagation).toHaveBeenCalled(); expect(event.stopPropagation).toHaveBeenCalled();
}); });
it("listenKey with keyCode 13", function () {
spyOn(view, "addEdge");
view.listenKey({keyCode: 13});
expect(view.addEdge).toHaveBeenCalled();
});
it("listenKey with keyCode != 13", function () {
spyOn(view, "addEdge");
view.listenKey({keyCode: 12});
expect(view.addEdge).not.toHaveBeenCalled();
});
it("resetView", function () { it("resetView", function () {
jQueryDummy = { jQueryDummy = {
attr: function() {
throw "Should be a spy";
},
val: function () { val: function () {
throw "Should be a spy"; throw "Should be a spy";
}, },
@ -233,29 +303,16 @@
}; };
spyOn(jQueryDummy, "val"); spyOn(jQueryDummy, "val");
spyOn(jQueryDummy, "css"); spyOn(jQueryDummy, "css");
spyOn(jQueryDummy, "attr");
spyOn(window, "$").andReturn( spyOn(window, "$").andReturn(
jQueryDummy jQueryDummy
); );
spyOn(view, "removeAllFilterItems"); spyOn(view, "removeAllFilterItems");
spyOn(view, "clearTable");
spyOn(view, "drawTable"); spyOn(view, "drawTable");
spyOn(view, "renderPaginationElements"); spyOn(view, "renderPaginationElements");
var arangoDocStoreDummy = { spyOn(arangoDocsStoreDummy, "getDocuments");
resetFilter: function () { spyOn(arangoDocsStoreDummy, "loadTotal");
throw "Should be a spy"; spyOn(arangoDocsStoreDummy, "resetFilter");
},
getDocuments: function () {
throw "Should be a spy";
},
loadTotal: function () {
throw "Should be a spy";
}
};
spyOn(arangoDocStoreDummy, "getDocuments");
spyOn(arangoDocStoreDummy, "loadTotal");
spyOn(arangoDocStoreDummy, "resetFilter");
spyOn(window, "arangoDocuments").andReturn(arangoDocStoreDummy);
view.collection = new window.arangoDocuments({collectionID: view.colid});
view.resetView(); view.resetView();
expect(window.$).toHaveBeenCalledWith("input"); expect(window.$).toHaveBeenCalledWith("input");
expect(window.$).toHaveBeenCalledWith("select"); expect(window.$).toHaveBeenCalledWith("select");
@ -265,61 +322,47 @@
expect(jQueryDummy.val).toHaveBeenCalledWith('=='); expect(jQueryDummy.val).toHaveBeenCalledWith('==');
expect(jQueryDummy.css).toHaveBeenCalledWith("visibility", "visible"); expect(jQueryDummy.css).toHaveBeenCalledWith("visibility", "visible");
expect(jQueryDummy.css).toHaveBeenCalledWith("visibility", "visible"); expect(jQueryDummy.css).toHaveBeenCalledWith("visibility", "visible");
expect(arangoDocStoreDummy.resetFilter).toHaveBeenCalled(); expect(arangoDocsStoreDummy.resetFilter).toHaveBeenCalled();
expect(arangoDocStoreDummy.getDocuments).toHaveBeenCalled(); expect(arangoDocsStoreDummy.getDocuments).toHaveBeenCalled();
expect(arangoDocStoreDummy.loadTotal).toHaveBeenCalled(); expect(arangoDocsStoreDummy.loadTotal).toHaveBeenCalled();
expect(view.removeAllFilterItems).toHaveBeenCalled(); expect(view.removeAllFilterItems).toHaveBeenCalled();
expect(view.clearTable).toHaveBeenCalled();
expect(view.drawTable).toHaveBeenCalled(); expect(view.drawTable).toHaveBeenCalled();
expect(view.renderPaginationElements).toHaveBeenCalled(); expect(view.renderPaginationElements).toHaveBeenCalled();
expect(view.addDocumentSwitch).toEqual(true); expect(view.addDocumentSwitch).toEqual(true);
}); });
it("start succesful Upload mit XHR ready state = 4, " + it("start succesful Upload with XHR ready state = 4, " +
"XHR status = 201 and parseable JSON", function () { "XHR status = 201 and parseable JSON", function () {
spyOn(view, "showSpinner"); spyOn(view, "showSpinner");
spyOn(view, "hideSpinner"); spyOn(view, "hideSpinner");
spyOn(view, "hideImportModal"); spyOn(view, "hideImportModal");
spyOn(view, "resetView"); spyOn(view, "resetView");
var arangoDocumentsStoreDummy = { spyOn(arangoDocsStoreDummy, "updloadDocuments").andReturn(true);
updloadDocuments: function () {
}
};
spyOn(arangoDocumentsStoreDummy, "updloadDocuments").andReturn(true);
spyOn(window, "arangoDocuments").andReturn(arangoDocumentsStoreDummy);
view.collection = new window.arangoDocuments();
view.allowUpload = true; view.allowUpload = true;
view.startUpload(); view.startUpload();
expect(arangoDocumentsStoreDummy.updloadDocuments).toHaveBeenCalledWith(view.file); expect(arangoDocsStoreDummy.updloadDocuments).toHaveBeenCalledWith(view.file);
expect(view.showSpinner).toHaveBeenCalled(); expect(view.showSpinner).toHaveBeenCalled();
expect(view.hideSpinner).toHaveBeenCalled(); expect(view.hideSpinner).toHaveBeenCalled();
expect(view.hideImportModal).toHaveBeenCalled(); expect(view.hideImportModal).toHaveBeenCalled();
expect(view.resetView).toHaveBeenCalled(); expect(view.resetView).toHaveBeenCalled();
}); });
it("start succesful Upload mit XHR ready state != 4", function () { it("start succesful Upload with XHR ready state != 4", function () {
spyOn(view, "showSpinner"); spyOn(view, "showSpinner");
spyOn(view, "hideSpinner"); spyOn(view, "hideSpinner");
spyOn(view, "hideImportModal"); spyOn(view, "hideImportModal");
spyOn(view, "resetView"); spyOn(view, "resetView");
var arangoDocumentsStoreDummy = { spyOn(arangoDocsStoreDummy, "updloadDocuments").andReturn("Upload error");
updloadDocuments: function () {
}
};
spyOn(arangoDocumentsStoreDummy, "updloadDocuments").andReturn("Upload error");
spyOn(window, "arangoDocuments").andReturn(arangoDocumentsStoreDummy);
view.collection = new window.arangoDocuments();
view.allowUpload = true; view.allowUpload = true;
spyOn(arangoHelper, "arangoError"); spyOn(arangoHelper, "arangoError");
view.startUpload(); view.startUpload();
expect(arangoDocumentsStoreDummy.updloadDocuments).toHaveBeenCalledWith(view.file); expect(arangoDocsStoreDummy.updloadDocuments).toHaveBeenCalledWith(view.file);
expect(view.showSpinner).toHaveBeenCalled(); expect(view.showSpinner).toHaveBeenCalled();
expect(view.hideSpinner).toHaveBeenCalled(); expect(view.hideSpinner).toHaveBeenCalled();
expect(view.hideImportModal).not.toHaveBeenCalled(); expect(view.hideImportModal).not.toHaveBeenCalled();
@ -329,25 +372,18 @@
it("start succesful Upload mit XHR ready state = 4, " + it("start succesful Upload mit XHR ready state = 4, " +
"XHR status = 201 and not parseable JSON", function () { "XHR status = 201 and not parseable JSON", function () {
view.collection = new window.arangoDocuments();
spyOn(view, "showSpinner"); spyOn(view, "showSpinner");
spyOn(view, "hideSpinner"); spyOn(view, "hideSpinner");
spyOn(view, "hideImportModal"); spyOn(view, "hideImportModal");
spyOn(view, "resetView"); spyOn(view, "resetView");
var arangoDocumentsStoreDummy = { spyOn(arangoDocsStoreDummy, "updloadDocuments").andReturn(
updloadDocuments: function () {
}
};
spyOn(arangoDocumentsStoreDummy, "updloadDocuments").andReturn(
'Error: SyntaxError: Unable to parse JSON string' 'Error: SyntaxError: Unable to parse JSON string'
); );
spyOn(window, "arangoDocuments").andReturn(arangoDocumentsStoreDummy);
view.collection = new window.arangoDocuments();
view.allowUpload = true; view.allowUpload = true;
spyOn(arangoHelper, "arangoError"); spyOn(arangoHelper, "arangoError");
view.startUpload(); view.startUpload();
expect(arangoDocumentsStoreDummy.updloadDocuments).toHaveBeenCalledWith(view.file); expect(arangoDocsStoreDummy.updloadDocuments).toHaveBeenCalledWith(view.file);
expect(view.showSpinner).toHaveBeenCalled(); expect(view.showSpinner).toHaveBeenCalled();
expect(view.hideSpinner).toHaveBeenCalled(); expect(view.hideSpinner).toHaveBeenCalled();
expect(view.hideImportModal).toHaveBeenCalled(); expect(view.hideImportModal).toHaveBeenCalled();
@ -675,37 +711,16 @@
); );
var arangoDocStoreDummy = {
setToFirst: function () {
throw "Should be a spy.";
},
addFilter: function () {
throw "Should be a spy.";
},
resetFilter: function () {
throw "Should be a spy.";
},
getDocuments: function () {
throw "Should be a spy.";
},
size: function () {
throw "Should be a spy.";
}
};
spyOn(arangoDocStoreDummy, "setToFirst"); spyOn(arangoDocStoreDummy, "setToFirst");
spyOn(arangoDocStoreDummy, "addFilter"); spyOn(arangoDocStoreDummy, "addFilter");
spyOn(arangoDocStoreDummy, "resetFilter"); spyOn(arangoDocStoreDummy, "resetFilter");
spyOn(arangoDocStoreDummy, "getDocuments"); spyOn(arangoDocStoreDummy, "getDocuments");
spyOn(window, "arangoDocuments").andReturn(arangoDocStoreDummy);
spyOn(view, "clearTable");
spyOn(view, "drawTable"); spyOn(view, "drawTable");
spyOn(view, "renderPaginationElements"); spyOn(view, "renderPaginationElements");
view.collection = new window.arangoDocuments();
view.sendFilter(); view.sendFilter();
expect(view.addDocumentSwitch).toEqual(false); expect(view.addDocumentSwitch).toEqual(false);
expect(view.clearTable).toHaveBeenCalled();
expect(view.drawTable).toHaveBeenCalled(); expect(view.drawTable).toHaveBeenCalled();
expect(view.renderPaginationElements).toHaveBeenCalled(); expect(view.renderPaginationElements).toHaveBeenCalled();
expect(arangoDocStoreDummy.resetFilter).toHaveBeenCalled(); expect(arangoDocStoreDummy.resetFilter).toHaveBeenCalled();
@ -816,13 +831,7 @@
}); });
it("addDocument without an error", function () { it("addDocument without an error", function () {
var arangoDocStoreDummy = {
createTypeDocument: function () {
}
};
spyOn(arangoDocStoreDummy, "createTypeDocument").andReturn("newDoc"); spyOn(arangoDocStoreDummy, "createTypeDocument").andReturn("newDoc");
spyOn(window, "arangoDocument").andReturn(arangoDocStoreDummy);
view.documentStore = new window.arangoDocument();
spyOn(arangoHelper, "collectionApiType").andReturn("document"); spyOn(arangoHelper, "collectionApiType").andReturn("document");
window.location.hash = "1/2"; window.location.hash = "1/2";
@ -835,13 +844,7 @@
}); });
it("addDocument with an edge", function () { it("addDocument with an edge", function () {
var arangoDocStoreDummy = {
createTypeDocument: function () {
}
};
spyOn(arangoDocStoreDummy, "createTypeDocument").andReturn("newDoc"); spyOn(arangoDocStoreDummy, "createTypeDocument").andReturn("newDoc");
spyOn(window, "arangoDocument").andReturn(arangoDocStoreDummy);
view.documentStore = new window.arangoDocument();
jQueryDummy = { jQueryDummy = {
modal: function () { modal: function () {
@ -866,13 +869,7 @@
}); });
it("addDocument with an error", function () { it("addDocument with an error", function () {
var arangoDocStoreDummy = {
createTypeDocument: function () {
}
};
spyOn(arangoDocStoreDummy, "createTypeDocument").andReturn(false); spyOn(arangoDocStoreDummy, "createTypeDocument").andReturn(false);
spyOn(window, "arangoDocument").andReturn(arangoDocStoreDummy);
view.documentStore = new window.arangoDocument();
spyOn(arangoHelper, "collectionApiType").andReturn("document"); spyOn(arangoHelper, "collectionApiType").andReturn("document");
spyOn(arangoHelper, "arangoError"); spyOn(arangoHelper, "arangoError");
@ -908,13 +905,7 @@
}); });
var arangoDocStoreDummy = {
createTypeEdge: function () {
}
};
spyOn(arangoDocStoreDummy, "createTypeEdge"); spyOn(arangoDocStoreDummy, "createTypeEdge");
spyOn(window, "arangoDocument").andReturn(arangoDocStoreDummy);
view.documentStore = new window.arangoDocument();
window.location.hash = "1/2"; window.location.hash = "1/2";
view.addEdge(); view.addEdge();
@ -947,13 +938,7 @@
}); });
var arangoDocStoreDummy = {
createTypeEdge: function () {
}
};
spyOn(arangoDocStoreDummy, "createTypeEdge"); spyOn(arangoDocStoreDummy, "createTypeEdge");
spyOn(window, "arangoDocument").andReturn(arangoDocStoreDummy);
view.documentStore = new window.arangoDocument();
window.location.hash = "1/2"; window.location.hash = "1/2";
view.addEdge(); view.addEdge();
@ -990,13 +975,7 @@
}); });
var arangoDocStoreDummy = {
createTypeEdge: function () {
}
};
spyOn(arangoDocStoreDummy, "createTypeEdge").andReturn("newEdge"); spyOn(arangoDocStoreDummy, "createTypeEdge").andReturn("newEdge");
spyOn(window, "arangoDocument").andReturn(arangoDocStoreDummy);
view.documentStore = new window.arangoDocument();
window.location.hash = "1/2"; window.location.hash = "1/2";
view.addEdge(); view.addEdge();
@ -1035,13 +1014,7 @@
}); });
var arangoDocStoreDummy = {
createTypeEdge: function () {
}
};
spyOn(arangoDocStoreDummy, "createTypeEdge").andReturn(false); spyOn(arangoDocStoreDummy, "createTypeEdge").andReturn(false);
spyOn(window, "arangoDocument").andReturn(arangoDocStoreDummy);
view.documentStore = new window.arangoDocument();
window.location.hash = "1/2"; window.location.hash = "1/2";
view.addEdge(); view.addEdge();
@ -1056,16 +1029,9 @@
}); });
it("first-last-next-prev document", function () { it("first-last-next-prev document", function () {
var arangoDocumentsStoreDummy = {
getLastPageNumber: function () {
return 5;
},
getPage: function () {
return 4;
}
};
spyOn(view, "jumpTo"); spyOn(view, "jumpTo");
view.collection = arangoDocumentsStoreDummy; spyOn(arangoDocsStoreDummy, "getLastPageNumber").andReturn(5);
spyOn(arangoDocsStoreDummy, "getPage").andReturn(4);
view.firstDocuments(); view.firstDocuments();
expect(view.jumpTo).toHaveBeenCalledWith(1); expect(view.jumpTo).toHaveBeenCalledWith(1);
@ -1175,22 +1141,9 @@
view.colid = "collection"; view.colid = "collection";
spyOn(arangoHelper, "arangoError"); spyOn(arangoHelper, "arangoError");
var arangoDocStoreDummy = {
deleteDocument: function () {
}
}, arangoDocsStoreDummy = {
getDocuments: function () {
},
collectionID: "collection"
};
spyOn(arangoDocStoreDummy, "deleteDocument").andReturn(false); spyOn(arangoDocStoreDummy, "deleteDocument").andReturn(false);
spyOn(window, "arangoDocument").andReturn(arangoDocStoreDummy);
view.documentStore = new window.arangoDocument();
spyOn(arangoDocsStoreDummy, "getDocuments"); spyOn(arangoDocsStoreDummy, "getDocuments");
spyOn(window, "arangoDocuments").andReturn(arangoDocsStoreDummy);
view.collection = new window.arangoDocuments();
view.target = "#confirmDeleteBtn"; view.target = "#confirmDeleteBtn";
view.reallyDelete(); view.reallyDelete();
@ -1228,21 +1181,8 @@
view.colid = "collection"; view.colid = "collection";
spyOn(arangoHelper, "arangoError"); spyOn(arangoHelper, "arangoError");
var arangoDocStoreDummy = {
deleteEdge: function () {
}
}, arangoDocsStoreDummy = {
getDocuments: function () {
},
collectionID: "collection"
};
spyOn(arangoDocStoreDummy, "deleteEdge").andReturn(false); spyOn(arangoDocStoreDummy, "deleteEdge").andReturn(false);
spyOn(window, "arangoDocument").andReturn(arangoDocStoreDummy);
view.documentStore = new window.arangoDocument();
spyOn(arangoDocsStoreDummy, "getDocuments"); spyOn(arangoDocsStoreDummy, "getDocuments");
spyOn(window, "arangoDocuments").andReturn(arangoDocsStoreDummy);
view.collection = new window.arangoDocuments();
view.target = "#confirmDeleteBtn"; view.target = "#confirmDeleteBtn";
view.reallyDelete(); view.reallyDelete();
@ -1301,22 +1241,10 @@
view.colid = "collection"; view.colid = "collection";
spyOn(arangoHelper, "arangoError"); spyOn(arangoHelper, "arangoError");
var arangoDocStoreDummy = {
deleteDocument: function () {
}
}, arangoDocsStoreDummy = {
getDocuments: function () {
},
collectionID: "collection"
};
spyOn(arangoDocStoreDummy, "deleteDocument").andReturn(true); spyOn(arangoDocStoreDummy, "deleteDocument").andReturn(true);
spyOn(window, "arangoDocument").andReturn(arangoDocStoreDummy);
view.documentStore = new window.arangoDocument();
spyOn(arangoDocsStoreDummy, "getDocuments"); spyOn(arangoDocsStoreDummy, "getDocuments");
spyOn(window, "arangoDocuments").andReturn(arangoDocsStoreDummy);
spyOn(view, "drawTable"); spyOn(view, "drawTable");
view.collection = new window.arangoDocuments();
view.target = "#confirmDeleteBtn"; view.target = "#confirmDeleteBtn";
spyOn(view, "renderPaginationElements"); spyOn(view, "renderPaginationElements");
@ -1388,21 +1316,9 @@
view.colid = "collection"; view.colid = "collection";
spyOn(arangoHelper, "arangoError"); spyOn(arangoHelper, "arangoError");
var arangoDocStoreDummy = {
deleteEdge: function () {
}
}, arangoDocsStoreDummy = {
getDocuments: function () {
},
collectionID: "collection"
};
spyOn(arangoDocStoreDummy, "deleteEdge").andReturn(true); spyOn(arangoDocStoreDummy, "deleteEdge").andReturn(true);
spyOn(window, "arangoDocument").andReturn(arangoDocStoreDummy);
view.documentStore = new window.arangoDocument();
spyOn(arangoDocsStoreDummy, "getDocuments"); spyOn(arangoDocsStoreDummy, "getDocuments");
spyOn(window, "arangoDocuments").andReturn(arangoDocsStoreDummy);
view.collection = new window.arangoDocuments();
view.target = "#confirmDeleteBtn"; view.target = "#confirmDeleteBtn";
spyOn(view, "drawTable"); spyOn(view, "drawTable");
spyOn(view, "renderPaginationElements"); spyOn(view, "renderPaginationElements");
@ -1500,62 +1416,12 @@
spyOn(window, "$").andReturn(jQueryDummy); spyOn(window, "$").andReturn(jQueryDummy);
spyOn(view, "addDocument"); spyOn(view, "addDocument");
view.alreadyClicked = false; view.alreadyClicked = false;
view.colid = "coll";
view.collection = {
collectionID: "coll"
};
expect(view.clicked({currentTarget: {firstChild: "blub"}})).toEqual(undefined); expect(view.clicked({currentTarget: {firstChild: "blub"}})).toEqual(undefined);
expect(view.addDocument).not.toHaveBeenCalled(); expect(view.addDocument).not.toHaveBeenCalled();
expect(window.$).toHaveBeenCalledWith("blub"); expect(window.$).toHaveBeenCalledWith("blub");
expect(window.location.hash).toEqual("#collection/coll/12"); expect(window.location.hash).toEqual("#collection/" + arangoDocsStoreDummy.collectionID + "/12");
}); });
it("initTable", function () {
jQueryDummy = {
dataTable: function () {
}
};
spyOn(jQueryDummy, "dataTable");
spyOn(window, "$").andReturn(jQueryDummy);
view.initTable();
expect(jQueryDummy.dataTable).toHaveBeenCalledWith({
"bSortClasses": false,
"bFilter": false,
"bPaginate": false,
"bRetrieve": true,
"bSortable": false,
"bSort": false,
"bLengthChange": false,
"bAutoWidth": false,
"iDisplayLength": -1,
"bJQueryUI": false,
"aoColumns": [
{ "sClass": "docsFirstCol", "bSortable": false},
{ "sClass": "docsSecCol", "bSortable": false},
{ "bSortable": false, "sClass": "docsThirdCol"}
],
"oLanguage": { "sEmptyTable": "Loading..."}
});
});
it("clearTable", function () {
jQueryDummy = {
dataTable: function () {
return jQueryDummy;
},
fnClearTable: function () {
}
};
spyOn(jQueryDummy, "dataTable").andCallThrough();
spyOn(jQueryDummy, "fnClearTable");
spyOn(window, "$").andReturn(jQueryDummy);
view.table = "blub";
view.clearTable();
expect(window.$).toHaveBeenCalledWith("blub");
expect(jQueryDummy.fnClearTable).toHaveBeenCalled();
});
it("drawTable with empty collection", function () { it("drawTable with empty collection", function () {
jQueryDummy = { jQueryDummy = {
text: function () { text: function () {
@ -1566,32 +1432,8 @@
spyOn(jQueryDummy, "text"); spyOn(jQueryDummy, "text");
spyOn(window, "$").andReturn(jQueryDummy); spyOn(window, "$").andReturn(jQueryDummy);
var arangoDocsStoreDummy = {
models: [],
totalPages: 1,
currentPage: 1,
documentsCount: 0,
size: function () {
return arangoDocsStoreDummy.models.length;
},
getLastPageNumber: function () {
return arangoDocsStoreDummy.totalPages;
},
getPage: function () {
return arangoDocsStoreDummy.currentPage;
},
getTotal: function () {
return arangoDocsStoreDummy.documentsCount;
}
};
spyOn(view, "clearTable");
spyOn(window, "arangoDocuments").andReturn(arangoDocsStoreDummy);
view.collection = new window.arangoDocuments();
//$(self.table).dataTable().fnAddData(
view.drawTable(); view.drawTable();
expect(window.$).toHaveBeenCalledWith(".dataTables_empty"); expect(window.$).toHaveBeenCalledWith(".dataTables_empty");
expect(view.clearTable).toHaveBeenCalled();
expect(jQueryDummy.text).toHaveBeenCalledWith('No documents'); expect(jQueryDummy.text).toHaveBeenCalledWith('No documents');
}); });
@ -1617,8 +1459,7 @@
spyOn(jQueryDummy, "snippet"); spyOn(jQueryDummy, "snippet");
spyOn(window, "$").andReturn(jQueryDummy); spyOn(window, "$").andReturn(jQueryDummy);
var arangoDocsStoreDummy = { arangoDocsStoreDummy.models = [
models: [
new window.arangoDocumentModel( new window.arangoDocumentModel(
{content: [ {content: [
{_id: 1}, {_id: 1},
@ -1643,28 +1484,16 @@
{bla: 1} {bla: 1}
]} ]}
) )
], ];
totalPages: 1, arangoDocsStoreDummy.totalPages = 1;
currentPage: 2, arangoDocsStoreDummy.currentPage = 2;
documentsCount: 3, arangoDocsStoreDummy.documentsCount = 3;
size: function () {
return arangoDocsStoreDummy.models.length;
},
each: function (cb) {
arangoDocsStoreDummy.models.forEach(cb);
}
};
spyOn(view, "clearTable");
spyOn(window, "arangoDocuments").andReturn(arangoDocsStoreDummy);
spyOn(arangoHelper, "fixTooltips"); spyOn(arangoHelper, "fixTooltips");
view.collection = new window.arangoDocuments();
view.drawTable(); view.drawTable();
expect(arangoHelper.fixTooltips).toHaveBeenCalledWith( expect(arangoHelper.fixTooltips).toHaveBeenCalledWith(
".icon_arangodb, .arangoicon", "top" ".icon_arangodb, .arangoicon", "top"
); );
expect(view.clearTable).toHaveBeenCalled();
expect(window.$).toHaveBeenCalledWith(".prettify"); expect(window.$).toHaveBeenCalledWith(".prettify");
expect(jQueryDummy.dataTable).toHaveBeenCalled(); expect(jQueryDummy.dataTable).toHaveBeenCalled();
expect(jQueryDummy.snippet).toHaveBeenCalledWith("javascript", { expect(jQueryDummy.snippet).toHaveBeenCalledWith("javascript", {
@ -1678,7 +1507,7 @@
}); });
describe("render", function () { describe("render", function () {
var jQueryDummy, arangoCollectionsDummy; var jQueryDummy;
beforeEach(function () { beforeEach(function () {
jQueryDummy = { jQueryDummy = {
parent: function () { parent: function () {
@ -1691,12 +1520,20 @@
}, },
html: function () { html: function () {
},
val: function () {
},
removeClass: function () {
} }
}; };
spyOn(jQueryDummy, "parent").andCallThrough(); spyOn(jQueryDummy, "parent").andCallThrough();
spyOn(jQueryDummy, "addClass"); spyOn(jQueryDummy, "addClass");
spyOn(jQueryDummy, "tooltip"); spyOn(jQueryDummy, "tooltip");
spyOn(jQueryDummy, "html"); spyOn(jQueryDummy, "html");
spyOn(jQueryDummy, "val");
spyOn(jQueryDummy, "removeClass");
spyOn(window, "$").andReturn(jQueryDummy); spyOn(window, "$").andReturn(jQueryDummy);
arangoCollectionsDummy = { arangoCollectionsDummy = {
getPosition: function () { getPosition: function () {
@ -1705,16 +1542,13 @@
}; };
spyOn(window, "arangoCollections").andReturn(arangoCollectionsDummy); spyOn(window, "arangoCollections").andReturn(arangoCollectionsDummy);
view.collectionsStore = new window.arangoCollections(); view.collectionsStore = new window.arangoCollections();
view.collection = {collectionID: "1"};
spyOn(view, "getIndex"); spyOn(view, "getIndex");
spyOn(view, "initTable");
spyOn(view, "breadcrumb"); spyOn(view, "breadcrumb");
spyOn(view, "uploadSetup"); spyOn(view, "uploadSetup");
spyOn(view, "drawTable"); spyOn(view, "drawTable");
spyOn(view, "renderPaginationElements"); spyOn(view, "renderPaginationElements");
spyOn(arangoHelper, "fixTooltips"); spyOn(arangoHelper, "fixTooltips");
view.el = 1; view.el = 1;
view.colid = "1";
view.template = { view.template = {
render: function () { render: function () {
return "tmp"; return "tmp";
@ -1727,10 +1561,8 @@
spyOn(arangoCollectionsDummy, "getPosition").andReturn({prev: null, next: null}); spyOn(arangoCollectionsDummy, "getPosition").andReturn({prev: null, next: null});
expect(view.render()).toEqual(view); expect(view.render()).toEqual(view);
expect(arangoCollectionsDummy.getPosition).toHaveBeenCalledWith("1"); expect(arangoCollectionsDummy.getPosition).toHaveBeenCalledWith(arangoDocsStoreDummy.collectionID);
expect(view.getIndex).toHaveBeenCalled(); expect(view.getIndex).toHaveBeenCalled();
expect(view.initTable).toHaveBeenCalled();
expect(view.drawTable).toHaveBeenCalled();
expect(view.renderPaginationElements).toHaveBeenCalled(); expect(view.renderPaginationElements).toHaveBeenCalled();
expect(view.breadcrumb).toHaveBeenCalled(); expect(view.breadcrumb).toHaveBeenCalled();
expect(view.uploadSetup).toHaveBeenCalled(); expect(view.uploadSetup).toHaveBeenCalled();
@ -1752,11 +1584,9 @@
spyOn(arangoCollectionsDummy, "getPosition").andReturn({prev: null, next: 1}); spyOn(arangoCollectionsDummy, "getPosition").andReturn({prev: null, next: 1});
expect(view.render()).toEqual(view); expect(view.render()).toEqual(view);
expect(arangoCollectionsDummy.getPosition).toHaveBeenCalledWith("1"); expect(arangoCollectionsDummy.getPosition).toHaveBeenCalledWith(arangoDocsStoreDummy.collectionID);
expect(view.getIndex).toHaveBeenCalled(); expect(view.getIndex).toHaveBeenCalled();
expect(view.initTable).toHaveBeenCalled();
expect(view.breadcrumb).toHaveBeenCalled(); expect(view.breadcrumb).toHaveBeenCalled();
expect(view.drawTable).toHaveBeenCalled();
expect(view.renderPaginationElements).toHaveBeenCalled(); expect(view.renderPaginationElements).toHaveBeenCalled();
expect(view.uploadSetup).toHaveBeenCalled(); expect(view.uploadSetup).toHaveBeenCalled();
expect(jQueryDummy.parent).toHaveBeenCalled(); expect(jQueryDummy.parent).toHaveBeenCalled();
@ -1777,11 +1607,9 @@
spyOn(arangoCollectionsDummy, "getPosition").andReturn({prev: 1, next: null}); spyOn(arangoCollectionsDummy, "getPosition").andReturn({prev: 1, next: null});
expect(view.render()).toEqual(view); expect(view.render()).toEqual(view);
expect(arangoCollectionsDummy.getPosition).toHaveBeenCalledWith("1"); expect(arangoCollectionsDummy.getPosition).toHaveBeenCalledWith(arangoDocsStoreDummy.collectionID);
expect(view.getIndex).toHaveBeenCalled(); expect(view.getIndex).toHaveBeenCalled();
expect(view.initTable).toHaveBeenCalled();
expect(view.breadcrumb).toHaveBeenCalled(); expect(view.breadcrumb).toHaveBeenCalled();
expect(view.drawTable).toHaveBeenCalled();
expect(view.renderPaginationElements).toHaveBeenCalled(); expect(view.renderPaginationElements).toHaveBeenCalled();
expect(view.uploadSetup).toHaveBeenCalled(); expect(view.uploadSetup).toHaveBeenCalled();
expect(jQueryDummy.parent).toHaveBeenCalled(); expect(jQueryDummy.parent).toHaveBeenCalled();
@ -1864,7 +1692,6 @@
] ]
); );
spyOn(view, "clearTable");
spyOn(view, "rerender"); spyOn(view, "rerender");
view.colid = 1; view.colid = 1;
view.documentsCount = 11; view.documentsCount = 11;
@ -1936,7 +1763,6 @@
] ]
); );
spyOn(view, "clearTable");
spyOn(view, "rerender"); spyOn(view, "rerender");
view.colid = 1; view.colid = 1;
view.documentsCount = 0; view.documentsCount = 0;
@ -1967,68 +1793,6 @@
expect(window.$).toHaveBeenCalledWith('#transparentHeader'); expect(window.$).toHaveBeenCalledWith('#transparentHeader');
}); });
it("cutByResolution with small string", function () {
expect(view.cutByResolution("blub")).toEqual(view.escaped("blub"));
});
it("cutByResolution with string longer than 1024", function () {
var string = "12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890",
resultString = "12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"12345678901234567890123456789012345678901234567890" +
"123456789012345678901234...";
expect(view.cutByResolution(string)).toEqual(view.escaped(resultString));
});
it("escaped", function () {
expect(view.escaped('&<>"\'')).toEqual("&amp;&lt;&gt;&quot;&#39;");
});
it("resetIndexForms", function () { it("resetIndexForms", function () {
jQueryDummy = { jQueryDummy = {
val: function () { val: function () {
@ -2819,46 +2583,9 @@
it("rerender", function () { it("rerender", function () {
spyOn(view, "clearTable"); spyOn(arangoDocsStoreDummy, "getDocuments");
spyOn(view, "drawTable");
spyOn(view, "renderPagination");
view.collection = {
getTotal: function () {
throw "Should be a spy";
},
getDocuments: function () {
throw "Should be a spy";
}
};
spyOn(view.collection, "getDocuments");
spyOn(view.collection, "getTotal");
jQueryDummy = {
css: function () {
throw "Should be a spy";
},
html: function() {
throw "Should be a spy";
}
};
spyOn(jQueryDummy, "css");
spyOn(jQueryDummy, "html");
spyOn(window, "$").andReturn(jQueryDummy);
view.rerender(); view.rerender();
expect(arangoDocsStoreDummy.getDocuments).toHaveBeenCalledWith(view.getDocsCallback.bind(view));
expect(view.clearTable).toHaveBeenCalled();
expect(view.collection.getDocuments).toHaveBeenCalled();
expect(view.collection.getTotal).toHaveBeenCalled();
expect(view.drawTable).toHaveBeenCalled();
expect(view.renderPagination).toHaveBeenCalled();
expect(view.index).toEqual(undefined);
expect(window.$).toHaveBeenCalledWith('#documents_last');
expect(window.$).toHaveBeenCalledWith('#documents_first');
expect(jQueryDummy.css).toHaveBeenCalledWith("visibility", "hidden");
}); });
it("setCollectionId", function () { it("setCollectionId", function () {