From 2c1981ea1b50a506dadcc758b9f1533e30d0a63d Mon Sep 17 00:00:00 2001 From: scottashton Date: Wed, 26 Mar 2014 14:44:06 +0100 Subject: [PATCH] finished frontend/collections tests --- .../js/collections/arangoDocuments.js | 2 +- .../frontend/js/collections/arangoSession.js | 0 .../frontend/js/collections/arangoUsers.js | 4 - js/apps/system/aardvark/manifest.json | 2 +- js/apps/system/aardvark/test/karma/files.json | 11 + .../test/karma/karma_coverage.conf.js | 3 +- .../test/karma/karma_coverage_local.conf.js | 5 +- .../specs/collections/arangoDocumentsSpec.js | 362 ++++++++++++------ .../test/specs/collections/arangoLogsSpec.js | 118 ++++++ .../collections/arangoReplicationSpec.js | 65 ++++ .../arangoStatisticsCollectionSpec.js | 20 + ...angoStatisticsDescriptionCollectionSpec.js | 21 + .../test/specs/collections/arangoUsersSpec.js | 170 ++++++++ .../specs/collections/foxxCollectionSpec.js | 22 ++ .../specs/collections/graphCollectionSpec.js | 24 ++ .../collections/notificationCollectionSpec.js | 22 ++ 16 files changed, 718 insertions(+), 133 deletions(-) delete mode 100644 js/apps/system/aardvark/frontend/js/collections/arangoSession.js create mode 100644 js/apps/system/aardvark/test/specs/collections/arangoLogsSpec.js create mode 100644 js/apps/system/aardvark/test/specs/collections/arangoReplicationSpec.js create mode 100644 js/apps/system/aardvark/test/specs/collections/arangoStatisticsCollectionSpec.js create mode 100644 js/apps/system/aardvark/test/specs/collections/arangoStatisticsDescriptionCollectionSpec.js create mode 100644 js/apps/system/aardvark/test/specs/collections/arangoUsersSpec.js create mode 100644 js/apps/system/aardvark/test/specs/collections/foxxCollectionSpec.js create mode 100644 js/apps/system/aardvark/test/specs/collections/graphCollectionSpec.js create mode 100644 js/apps/system/aardvark/test/specs/collections/notificationCollectionSpec.js diff --git a/js/apps/system/aardvark/frontend/js/collections/arangoDocuments.js b/js/apps/system/aardvark/frontend/js/collections/arangoDocuments.js index 50820b3ba0..a4a7f344e8 100644 --- a/js/apps/system/aardvark/frontend/js/collections/arangoDocuments.js +++ b/js/apps/system/aardvark/frontend/js/collections/arangoDocuments.js @@ -182,7 +182,7 @@ ) { this.currentPage = 1; } - if (this.totalPages === 0) { + if (this.totalPages === 0 || this.totalPages === undefined) { this.totalPages = 1; } diff --git a/js/apps/system/aardvark/frontend/js/collections/arangoSession.js b/js/apps/system/aardvark/frontend/js/collections/arangoSession.js deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/js/apps/system/aardvark/frontend/js/collections/arangoUsers.js b/js/apps/system/aardvark/frontend/js/collections/arangoUsers.js index 3629e983c2..5e584d94d7 100644 --- a/js/apps/system/aardvark/frontend/js/collections/arangoUsers.js +++ b/js/apps/system/aardvark/frontend/js/collections/arangoUsers.js @@ -17,10 +17,6 @@ window.ArangoUsers = Backbone.Collection.extend({ return obj.get("user").toLowerCase(); }, - initialize: function() { - //check cookies / local storage - }, - login: function (username, password) { this.activeUser = username; return true; diff --git a/js/apps/system/aardvark/manifest.json b/js/apps/system/aardvark/manifest.json index b311b9d72e..ac764f34f8 100644 --- a/js/apps/system/aardvark/manifest.json +++ b/js/apps/system/aardvark/manifest.json @@ -163,7 +163,7 @@ "clusterFrontend/js/collections/**", "frontend/js/views/footerView.js", "frontend/js/views/dashboardView.js", - "frontend/js/collections/arangoStatisticsCollection.js", + "frontend/js/collections/arangoStatisticsCollectionSpec.js", "frontend/js/collections/arangoDocuments.js", "frontend/js/models/arangoDocument.js", "frontend/js/config/dygraphConfig.js", diff --git a/js/apps/system/aardvark/test/karma/files.json b/js/apps/system/aardvark/test/karma/files.json index f19af2bb3a..5e925c1e01 100755 --- a/js/apps/system/aardvark/test/karma/files.json +++ b/js/apps/system/aardvark/test/karma/files.json @@ -110,11 +110,14 @@ "frontend/js/collections/arangoDocument.js", "frontend/js/collections/arangoDatabase.js", "frontend/js/collections/arangoLogs.js", + "frontend/js/collections/arangoReplication.js", "frontend/js/collections/arangoUsers.js", "frontend/js/collections/arangoStatisticsCollection.js", "frontend/js/collections/arangoStatisticsDescriptionCollection.js", + "frontend/js/collections/arangoUsers.js", "frontend/js/collections/foxxCollection.js", "frontend/js/collections/graphCollection.js", + "frontend/js/collections/notificationCollection.js", "clusterFrontend/js/collections/clusterServers.js", "clusterFrontend/js/collections/clusterCoordinators.js", "clusterFrontend/js/collections/clusterDatabases.js", @@ -216,6 +219,14 @@ "test/specs/collections/arangoDatabaseSpec.js", "test/specs/collections/arangoDocumentSpec.js", "test/specs/collections/arangoDocumentsSpec.js", + "test/specs/collections/arangoLogsSpec.js", + "test/specs/collections/arangoReplicationSpec.js", + "test/specs/collections/arangoStatisticsCollectionSpec.js", + "test/specs/collections/arangoStatisticsDescriptionCollectionSpec.js", + "test/specs/collections/arangoUsersSpec.js", + "test/specs/collections/foxxCollectionSpec.js", + "test/specs/collections/graphCollectionSpec.js", + "test/specs/collections/notificationCollectionSpec.js", "test/specs/views/editListEntryViewSpec.js", diff --git a/js/apps/system/aardvark/test/karma/karma_coverage.conf.js b/js/apps/system/aardvark/test/karma/karma_coverage.conf.js index f382140f40..61547c765e 100644 --- a/js/apps/system/aardvark/test/karma/karma_coverage.conf.js +++ b/js/apps/system/aardvark/test/karma/karma_coverage.conf.js @@ -27,7 +27,8 @@ module.exports = function(karma) { preprocessors: { 'test/karma/files.json': ['html2js'], - 'frontend/js/**/**.js': ['coverage'] + 'frontend/js/**/**.js': ['coverage'], + 'clusterFrontend/js/**/**.js': ['coverage'] }, // test results reporter to use diff --git a/js/apps/system/aardvark/test/karma/karma_coverage_local.conf.js b/js/apps/system/aardvark/test/karma/karma_coverage_local.conf.js index 21ad94dcc9..98debacf70 100644 --- a/js/apps/system/aardvark/test/karma/karma_coverage_local.conf.js +++ b/js/apps/system/aardvark/test/karma/karma_coverage_local.conf.js @@ -1,7 +1,7 @@ // Karma configuration // Generated on Thu Jul 04 2013 11:39:34 GMT+0200 (CEST) -filesJSON = require("./file.json"); +filesJSON = require("./files.json"); module.exports = function(karma) { @@ -25,7 +25,8 @@ module.exports = function(karma) { ], preprocessors: { - 'frontend/js/**/**.js': ['coverage'] + 'frontend/js/**/**.js': ['coverage'], + 'clusterFrontend/js/**/**.js': ['coverage'] }, // test results reporter to use diff --git a/js/apps/system/aardvark/test/specs/collections/arangoDocumentsSpec.js b/js/apps/system/aardvark/test/specs/collections/arangoDocumentsSpec.js index b8fa899e46..fac96b0349 100644 --- a/js/apps/system/aardvark/test/specs/collections/arangoDocumentsSpec.js +++ b/js/apps/system/aardvark/test/specs/collections/arangoDocumentsSpec.js @@ -16,6 +16,12 @@ }); it("should getFirstDocuments", function() { + expect(col.currentPage).toEqual(1); + expect(col.collectionID).toEqual(1); + expect(col.totalPages).toEqual(1); + expect(col.documentsPerPage).toEqual(10); + expect(col.documentsCount).toEqual(1); + expect(col.offset).toEqual(0); col.currentPage = 2; window.location.hash = "a/b/c" col.getFirstDocuments(); @@ -44,7 +50,7 @@ expect(window.location.hash).toEqual("#a/b/c/3"); }); - it("should getDocuments and succeed", function() { + it("should getDocuments starting on first page and succeed", function() { var colid = "12345"; var currpage = "0"; spyOn($, "ajax").andCallFake(function(opt) { @@ -82,6 +88,43 @@ expect(window.documentsView.renderPagination).toHaveBeenCalledWith(10); }); + it("should getDocuments starting on undefined page and succeed", function() { + var colid = "12345"; + spyOn($, "ajax").andCallFake(function(opt) { + if (opt.type === "GET") { + expect(opt.url).toEqual("/_api/collection/" + colid + "/count"); + expect(opt.contentType).toEqual("application/json"); + expect(opt.cache).toEqual(false); + expect(opt.async).toEqual(false); + expect(opt.processData).toEqual(false); + opt.success({count : 100}); + } else if (opt.type === "POST") { + expect(opt.url).toEqual('/_api/cursor'); + expect(opt.contentType).toEqual("application/json"); + expect(opt.cache).toEqual(false); + expect(opt.async).toEqual(false); + expect(opt.data).toEqual(JSON.stringify({ + query : "FOR x in @@collection SORT TO_NUMBER(x._key) == 0 " + + "? x._key : TO_NUMBER(x._key) LIMIT @offset, @count RETURN x", + bindVars : { + "@collection" : colid, + "offset": 0, + "count": 10 + } + })); + opt.success({result : [{_id : 1, _rev : 2, _key : 4}, {_id : 2, _rev : 2, _key : 4}, + {_id : 3, _rev : 2, _key : 4}] + }); + } + }); + spyOn(window.arangoDocumentsStore, "reset"); + spyOn(window.documentsView, "drawTable"); + spyOn(window.documentsView, "renderPagination"); + spyOn(window.documentsView, "initTable"); + var result = col.getDocuments(colid); + expect(window.documentsView.renderPagination).toHaveBeenCalledWith(10); + }); + it("should getDocuments with exceeding sort count", function() { var colid = "12345"; var currpage = "2"; @@ -157,133 +200,204 @@ expect(window.documentsView.initTable).toHaveBeenCalled(); }); -/* - - getFilteredDocuments: function (colid, currpage, filter, bindValues) { - var self = this; - this.collectionID = colid; - this.currentPage = currpage; - this.currentFilterPage = currpage; - var filterString; - if(filter.length === 0){ - filterString =""; - } else { - filterString = ' FILTER' + filter.join(' && '); - } - var sortCount = 10000; - - var sortString = ''; - if (this.documentsCount <= sortCount) { - //sorted - sortString = " SORT TO_NUMBER(u._key) == 0 ? u._key : TO_NUMBER(u._key)"; - } - - var myQueryVal = "FOR u in @@collection" + filterString + sortString + - " LIMIT @offset, @count RETURN u"; - - this.offset = (this.currentPage - 1) * this.documentsPerPage; - - var myQuery = { - query: myQueryVal, - bindVars: { - "@collection": this.collectionID, - "count": this.documentsPerPage, - "offset": this.offset - }, - options: { - fullCount: true - } - }; - - $.each(bindValues, function(k,v) { - myQuery.bindVars[k] = v; - }); - - $.ajax({ - cache: false, - type: 'POST', - async: false, - url: '/_api/cursor', - data: JSON.stringify(myQuery), - contentType: "application/json", - success: function(data) { - self.clearDocuments(); - self.documentsCount = data.extra.fullCount; - self.totalPages = Math.ceil(self.documentsCount / self.documentsPerPage); - if ( - isNaN(this.currentPage) - || this.currentPage === undefined - || this.currentPage < 1 - ) { - this.currentPage = 1; - } - if (this.totalPages === 0) { - this.totalPages = 1; - } - - this.offset = (this.currentPage - 1) * this.documentsPerPage; - if (self.documentsCount !== 0) { - $.each(data.result, function(k, v) { - window.arangoDocumentsStore.add({ - "id": v._id, - "rev": v._rev, - "key": v._key, - "content": v - }); - }); - window.documentsView.drawTable(); - window.documentsView.renderPagination(self.totalPages, true); - } - else { - window.documentsView.initTable(); - window.documentsView.drawTable(); - } - }, - error: function(data) { + it("should getDocuments with exceeding sort count", function() { + var colid = "12345"; + var currpage = "2"; + spyOn($, "ajax").andCallFake(function(opt) { + if (opt.type === "GET") { + expect(opt.url).toEqual("/_api/collection/" + colid + "/count"); + expect(opt.contentType).toEqual("application/json"); + expect(opt.cache).toEqual(false); + expect(opt.async).toEqual(false); + expect(opt.processData).toEqual(false); + opt.success({count : 100000}); + } else if (opt.type === "POST") { + expect(opt.url).toEqual('/_api/cursor'); + expect(opt.contentType).toEqual("application/json"); + expect(opt.cache).toEqual(false); + expect(opt.async).toEqual(false); + expect(opt.data).toEqual(JSON.stringify({ + query : "FOR x in @@collection LIMIT @offset, @count RETURN x", + bindVars : { + "@collection" : colid, + "offset": 10, + "count": 10 + } + })); + opt.success({result : [{_id : 1, _rev : 2, _key : 4}, {_id : 2, _rev : 2, _key : 4}, + {_id : 3, _rev : 2, _key : 4}] + }); } }); - }, - clearDocuments: function () { - window.arangoDocumentsStore.reset(); - }, - getStatisticsHistory: function(params) { - var self = this; - var body = { - startDate : params.startDate, - endDate : params.endDate, - figures : params.figures - }; - var server = params.server; - var addAuth = function(){}; - var url = ""; - if (server) { - url = server.endpoint; - url += "/_admin/history"; - if (server.isDBServer) { - url += "?DBserver=" + server.target; - } - addAuth = server.addAuth; - } else { - url = "/_admin/history"; - } - $.ajax({ - cache: false, - type: 'POST', - async: false, - url: url, - data: JSON.stringify(body), - contentType: "application/json", - beforeSend: addAuth, - success: function(data) { - self.history = data.result; - }, - error: function(data) { - } - }); - } -*/ + spyOn(window.arangoDocumentsStore, "reset"); + spyOn(window.documentsView, "drawTable"); + spyOn(window.documentsView, "renderPagination"); + spyOn(window.documentsView, "initTable"); + var result = col.getDocuments(colid, currpage); + expect(window.documentsView.renderPagination).toHaveBeenCalledWith(10000); + }); + it("should sorted getFilteredDocuments with empty filter", function() { + var colid = "12345"; + var currpage = "2"; + spyOn($, "ajax").andCallFake(function(opt) { + expect(opt.type).toEqual("POST"); + expect(opt.url).toEqual('/_api/cursor'); + expect(opt.contentType).toEqual("application/json"); + expect(opt.cache).toEqual(false); + expect(opt.async).toEqual(false); + expect(opt.data).toEqual(JSON.stringify({ + query : "FOR u in @@collection SORT TO_NUMBER(u._key) == 0 ? u._key : TO_NUMBER(u._key)" + + " LIMIT @offset, @count RETURN u", + bindVars :{ + "@collection":"12345","count":10,"offset":10 + }, + options: { + fullCount:true + } + })); + opt.success({result : [{_id : 1, _rev : 2, _key : 4}, {_id : 2, _rev : 2, _key : 4}, + {_id : 3, _rev : 2, _key : 4}], extra : {fullCount : 10} + }); + }); + spyOn(window.arangoDocumentsStore, "reset"); + spyOn(window.arangoDocumentsStore, "add"); + spyOn(window.documentsView, "drawTable"); + spyOn(window.documentsView, "renderPagination"); + spyOn(window.documentsView, "initTable"); + col.documentsCount = 100; + var result = col.getFilteredDocuments(colid, currpage, [], []); + expect(window.documentsView.renderPagination).toHaveBeenCalled(); + }); + + it("should sorted getFilteredDocuments with empty filter and empty result", function() { + var colid = "12345"; + var currpage = "2"; + spyOn($, "ajax").andCallFake(function(opt) { + expect(opt.type).toEqual("POST"); + expect(opt.url).toEqual('/_api/cursor'); + expect(opt.contentType).toEqual("application/json"); + expect(opt.cache).toEqual(false); + expect(opt.async).toEqual(false); + expect(opt.data).toEqual(JSON.stringify({ + query : "FOR u in @@collection SORT TO_NUMBER(u._key) == 0 ? u._key : TO_NUMBER(u._key)" + + " LIMIT @offset, @count RETURN u", + bindVars :{ + "@collection":"12345","count":10,"offset":10 + }, + options: { + fullCount:true + } + })); + opt.success({result : [{_id : 1, _rev : 2, _key : 4}, {_id : 2, _rev : 2, _key : 4}, + {_id : 3, _rev : 2, _key : 4}], extra : {fullCount : 0} + }); + }); + spyOn(window.arangoDocumentsStore, "reset"); + spyOn(window.arangoDocumentsStore, "add"); + spyOn(window.documentsView, "drawTable"); + spyOn(window.documentsView, "renderPagination"); + spyOn(window.documentsView, "initTable"); + col.documentsCount = 100; + var result = col.getFilteredDocuments(colid, currpage, [], []); + expect(window.documentsView.initTable).toHaveBeenCalled(); + }); + + it("should sorted getFilteredDocuments with filter", function() { + var colid = "12345"; + var currpage = "2"; + spyOn($, "ajax").andCallFake(function(opt) { + expect(opt.type).toEqual("POST"); + expect(opt.url).toEqual('/_api/cursor'); + expect(opt.contentType).toEqual("application/json"); + expect(opt.cache).toEqual(false); + expect(opt.async).toEqual(false); + expect(opt.data).toEqual(JSON.stringify({ + query : "FOR u in @@collection FILTER u.NAME = @@name && u.AGE > @age SORT TO_NUMBER(u._key) == 0" + + " ? u._key : TO_NUMBER(u._key)" + + " LIMIT @offset, @count RETURN u", + bindVars: { + "@collection":"12345", + count:10, + offset:10, + name: "Heinz", + age: 4 + }, + options: { + fullCount:true + } + })); + opt.success({result : [{_id : 1, _rev : 2, _key : 4}, {_id : 2, _rev : 2, _key : 4}, + {_id : 3, _rev : 2, _key : 4}], extra : {fullCount : 10} + }); + }); + spyOn(window.arangoDocumentsStore, "reset"); + spyOn(window.arangoDocumentsStore, "add"); + spyOn(window.documentsView, "drawTable"); + spyOn(window.documentsView, "renderPagination"); + spyOn(window.documentsView, "initTable"); + col.documentsCount = 100; + var result = col.getFilteredDocuments(colid, currpage, [' u.NAME = @@name', ' u.AGE > @age'], + {name: "Heinz", age: 4}); + expect(window.documentsView.renderPagination).toHaveBeenCalled(); + }); + + it("should getStatisticsHistory", function() { + spyOn($, "ajax").andCallFake(function(opt) { + expect(opt.type).toEqual("POST"); + expect(opt.url).toEqual("/_admin/history"); + expect(opt.contentType).toEqual("application/json"); + expect(opt.cache).toEqual(false); + expect(opt.async).toEqual(false); + expect(opt.beforeSend).toNotBe(undefined), + expect(opt.data).toEqual(JSON.stringify({startDate : 15000, endDate :18000, figures: ["bytesSend, totalTime"]})); + opt.success({result : [{bytesSend : 1, totalTime : 2, time : 4}, {bytesSend : 2, totalTime : 2, time : 4}, + {bytesSend : 3, totalTime : 2, time : 4}] + }); + }); + var result = col.getStatisticsHistory({startDate : 15000, endDate :18000, figures: ["bytesSend, totalTime"]}); + expect(JSON.stringify(col.history)).toEqual(JSON.stringify([{bytesSend : 1, totalTime : 2, time : 4}, {bytesSend : 2, totalTime : 2, time : 4}, + {bytesSend : 3, totalTime : 2, time : 4}])); + }); + + it("should getStatisticsHistory from remote dispatcher and get an error", function() { + delete col.history; + spyOn($, "ajax").andCallFake(function(opt) { + expect(opt.type).toEqual("POST"); + expect(opt.url).toEqual("endpoint/_admin/history"); + expect(opt.contentType).toEqual("application/json"); + expect(opt.cache).toEqual(false); + expect(opt.async).toEqual(false); + expect(opt.beforeSend).toNotBe(undefined), + expect(opt.data).toEqual(JSON.stringify({startDate : 15000, endDate :18000, + figures: ["bytesSend, totalTime"]})); + opt.error(); + }); + var result = col.getStatisticsHistory({server: {endpoint : "endpoint", isDBServer : false, + addAuth : "authKey"}, + startDate : 15000, endDate :18000, figures: ["bytesSend, totalTime"]}); + expect(col.history).toEqual(undefined); + }); + + it("should getStatisticsHistory from remote dbserver and get an error", function() { + delete col.history; + spyOn($, "ajax").andCallFake(function(opt) { + expect(opt.type).toEqual("POST"); + expect(opt.url).toEqual("endpoint/_admin/history?DBserver=anotherserver"); + expect(opt.contentType).toEqual("application/json"); + expect(opt.cache).toEqual(false); + expect(opt.async).toEqual(false); + expect(opt.beforeSend).toNotBe(undefined), + expect(opt.data).toEqual(JSON.stringify({startDate : 15000, endDate :18000, + figures: ["bytesSend, totalTime"]})); + opt.error(); + }); + var result = col.getStatisticsHistory({server: {endpoint : "endpoint", isDBServer : true, + addAuth : "authKey", target : "anotherserver"}, startDate : 15000, endDate :18000, + figures: ["bytesSend, totalTime"]}); + expect(col.history).toEqual(undefined); + }); }); }()); diff --git a/js/apps/system/aardvark/test/specs/collections/arangoLogsSpec.js b/js/apps/system/aardvark/test/specs/collections/arangoLogsSpec.js new file mode 100644 index 0000000000..592e1ccb28 --- /dev/null +++ b/js/apps/system/aardvark/test/specs/collections/arangoLogsSpec.js @@ -0,0 +1,118 @@ +/*jslint indent: 2, nomen: true, maxlen: 100, vars: true, white: true, plusplus: true */ +/*global require, exports, Backbone, window, $, arangoLog */ +(function () { + + "use strict"; + + describe("ArangoLogs", function() { + + var col; + + beforeEach(function() { + col = new window.ArangoLogs(); + window.arangoLogsStore = new window.ArangoLogs(); + window.logsView = jasmine.createSpyObj(window.LogsView, ['drawTable']); + + }); + + it("should parse", function() { + var result = col.parse({ + level: [3, 2, 3], text : ["bla", "blub", "blaf"], lid : [1, 2, 3], timestamp : [10, 11, 12], totalAmount: 3 + }); + expect(col.url).toEqual('/_admin/log?upto=4&size=10&offset=0'); + expect(col.tables).toEqual(["logTableID", "warnTableID", "infoTableID", "debugTableID", "critTableID"]); + expect(result).toEqual([ + {level : 3, lid: 1, text: "bla", timestamp: 10, totalAmount : 3}, + {level : 2, lid: 2, text: "blub", timestamp: 11, totalAmount : 3}, + {level : 3, lid: 3, text: "blaf", timestamp: 12, totalAmount : 3} + ]); + }); + it("should clearLocalStorage", function() { + spyOn(window.arangoLogsStore, "reset"); + col.clearLocalStorage(); + expect(window.arangoLogsStore.reset).toHaveBeenCalled(); + }); + it("should returnElements", function() { + col.returnElements(); + }); + it("should fillLocalStorage", function() { + spyOn(window.arangoLogsStore, "reset"); + spyOn(window.arangoLogsStore, "add"); + + spyOn($, "getJSON").andCallFake(function(url, callback) { + expect(url).toEqual("/_admin/log?upto=4&size=10&offset=0"); + callback({ + level: [3, 2, 3], text : ["bla", "blub", "blaf"], lid : [1, 2, 3], timestamp : [10, 11, 12], totalAmount: 3 + }) + }); + col.fillLocalStorage(); + expect(window.arangoLogsStore.reset).toHaveBeenCalled(); + expect(window.arangoLogsStore.add).toHaveBeenCalledWith({level : 3, lid: 3, text: "blaf", timestamp: 12, totalAmount : 3}); + expect(window.logsView.drawTable).toHaveBeenCalled(); + }); + + it("should fillLocalStorage for critical table", function() { + spyOn(window.arangoLogsStore, "reset"); + spyOn(window.arangoLogsStore, "add"); + + spyOn($, "getJSON").andCallFake(function(url, callback) { + expect(url).toEqual("/_admin/log?level=1&size=10&offset=0"); + callback({ + level: [3, 2, 3], text : ["bla", "blub", "blaf"], lid : [1, 2, 3], timestamp : [10, 11, 12], totalAmount: 3 + }) + }); + col.fillLocalStorage("critTableID"); + expect(window.arangoLogsStore.reset).toHaveBeenCalled(); + expect(window.arangoLogsStore.add).toHaveBeenCalledWith({level : 3, lid: 3, text: "blaf", timestamp: 12, totalAmount : 3}); + expect(window.logsView.drawTable).toHaveBeenCalled(); + }); + + it("should fillLocalStorage for warnTable table", function() { + spyOn(window.arangoLogsStore, "reset"); + spyOn(window.arangoLogsStore, "add"); + + spyOn($, "getJSON").andCallFake(function(url, callback) { + expect(url).toEqual("/_admin/log?level=2&size=10&offset=0"); + callback({ + level: [3, 2, 3], text : ["bla", "blub", "blaf"], lid : [1, 2, 3], timestamp : [10, 11, 12], totalAmount: 3 + }) + }); + col.fillLocalStorage("warnTableID"); + expect(window.arangoLogsStore.reset).toHaveBeenCalled(); + expect(window.arangoLogsStore.add).toHaveBeenCalledWith({level : 3, lid: 3, text: "blaf", timestamp: 12, totalAmount : 3}); + expect(window.logsView.drawTable).toHaveBeenCalled(); + }); + + it("should fillLocalStorage for infoTable table", function() { + spyOn(window.arangoLogsStore, "reset"); + spyOn(window.arangoLogsStore, "add"); + + spyOn($, "getJSON").andCallFake(function(url, callback) { + expect(url).toEqual("/_admin/log?level=3&size=10&offset=0"); + callback({ + level: [3, 2, 3], text : ["bla", "blub", "blaf"], lid : [1, 2, 3], timestamp : [10, 11, 12], totalAmount: 3 + }) + }); + col.fillLocalStorage("infoTableID"); + expect(window.arangoLogsStore.reset).toHaveBeenCalled(); + expect(window.arangoLogsStore.add).toHaveBeenCalledWith({level : 3, lid: 3, text: "blaf", timestamp: 12, totalAmount : 3}); + expect(window.logsView.drawTable).toHaveBeenCalled(); + }); + + it("should fillLocalStorage for debugTable table", function() { + spyOn(window.arangoLogsStore, "reset"); + spyOn(window.arangoLogsStore, "add"); + + spyOn($, "getJSON").andCallFake(function(url, callback) { + expect(url).toEqual("/_admin/log?level=4&size=10&offset=0"); + callback({ + level: [3, 2, 3], text : ["bla", "blub", "blaf"], lid : [1, 2, 3], timestamp : [10, 11, 12], totalAmount: 3 + }) + }); + col.fillLocalStorage("debugTableID"); + expect(window.arangoLogsStore.reset).toHaveBeenCalled(); + expect(window.arangoLogsStore.add).toHaveBeenCalledWith({level : 3, lid: 3, text: "blaf", timestamp: 12, totalAmount : 3}); + expect(window.logsView.drawTable).toHaveBeenCalled(); + }); + }) +}()); diff --git a/js/apps/system/aardvark/test/specs/collections/arangoReplicationSpec.js b/js/apps/system/aardvark/test/specs/collections/arangoReplicationSpec.js new file mode 100644 index 0000000000..a2a4bc3827 --- /dev/null +++ b/js/apps/system/aardvark/test/specs/collections/arangoReplicationSpec.js @@ -0,0 +1,65 @@ +/*jslint indent: 2, nomen: true, maxlen: 100, vars: true, white: true, plusplus: true */ +/*global require, exports, Backbone, window, $, arangoLog */ +(function () { + + "use strict"; + + describe("ArangoReplication", function() { + + var col; + + beforeEach(function() { + col = new window.ArangoReplication(); + }); + + it("getLogState with success", function() { + expect(col.url).toEqual('../api/user'); + spyOn($, "ajax").andCallFake(function(opt) { + expect(opt.url).toEqual("/_api/replication/logger-state"); + expect(opt.type).toEqual("GET"); + expect(opt.contentType).toEqual("application/json"); + expect(opt.cache).toEqual(false); + expect(opt.processData).toEqual(false); + opt.success("success"); + }); + expect(col.getLogState()).toEqual("success"); + }); + it("getLogState with error", function() { + expect(col.url).toEqual('../api/user'); + spyOn($, "ajax").andCallFake(function(opt) { + expect(opt.url).toEqual("/_api/replication/logger-state"); + expect(opt.type).toEqual("GET"); + expect(opt.contentType).toEqual("application/json"); + expect(opt.cache).toEqual(false); + expect(opt.processData).toEqual(false); + opt.error("error"); + }); + expect(col.getLogState()).toEqual("error"); + }); + + it("getApplyState with success", function() { + expect(col.url).toEqual('../api/user'); + spyOn($, "ajax").andCallFake(function(opt) { + expect(opt.url).toEqual("/_api/replication/applier-state"); + expect(opt.type).toEqual("GET"); + expect(opt.contentType).toEqual("application/json"); + expect(opt.cache).toEqual(false); + expect(opt.processData).toEqual(false); + opt.success("success"); + }); + expect(col.getApplyState()).toEqual("success"); + }); + it("getApplyState with error", function() { + expect(col.url).toEqual('../api/user'); + spyOn($, "ajax").andCallFake(function(opt) { + expect(opt.url).toEqual("/_api/replication/applier-state"); + expect(opt.type).toEqual("GET"); + expect(opt.contentType).toEqual("application/json"); + expect(opt.cache).toEqual(false); + expect(opt.processData).toEqual(false); + opt.error("error"); + }); + expect(col.getApplyState()).toEqual("error"); + }); + }) +}()); diff --git a/js/apps/system/aardvark/test/specs/collections/arangoStatisticsCollectionSpec.js b/js/apps/system/aardvark/test/specs/collections/arangoStatisticsCollectionSpec.js new file mode 100644 index 0000000000..4aff993abe --- /dev/null +++ b/js/apps/system/aardvark/test/specs/collections/arangoStatisticsCollectionSpec.js @@ -0,0 +1,20 @@ +/*jslint indent: 2, nomen: true, maxlen: 100, vars: true, white: true, plusplus: true */ +/*global require, exports, Backbone, window, $, arangoLog */ +(function () { + + "use strict"; + + describe("StatisticsCollection", function() { + + var col; + + beforeEach(function() { + col = new window.StatisticsCollection(); + }); + + it("StatisticsCollection", function() { + expect(col.model).toEqual(window.Statistics); + expect(col.url).toEqual('/_admin/statistics'); + }); + }) +}()); diff --git a/js/apps/system/aardvark/test/specs/collections/arangoStatisticsDescriptionCollectionSpec.js b/js/apps/system/aardvark/test/specs/collections/arangoStatisticsDescriptionCollectionSpec.js new file mode 100644 index 0000000000..cab40ede86 --- /dev/null +++ b/js/apps/system/aardvark/test/specs/collections/arangoStatisticsDescriptionCollectionSpec.js @@ -0,0 +1,21 @@ +/*jslint indent: 2, nomen: true, maxlen: 100, vars: true, white: true, plusplus: true */ +/*global require, exports, Backbone, window, $, arangoLog */ +(function () { + + "use strict"; + + describe("StatisticsDescriptionCollection", function() { + + var col; + + beforeEach(function() { + col = new window.StatisticsDescriptionCollection(); + }); + + it("StatisticsDescriptionCollection", function() { + expect(col.model).toEqual(window.StatisticsDescription); + expect(col.url).toEqual('/_admin/statistics-description'); + expect(col.parse("ee")).toEqual("ee"); + }); + }) +}()); diff --git a/js/apps/system/aardvark/test/specs/collections/arangoUsersSpec.js b/js/apps/system/aardvark/test/specs/collections/arangoUsersSpec.js new file mode 100644 index 0000000000..3846e0f823 --- /dev/null +++ b/js/apps/system/aardvark/test/specs/collections/arangoUsersSpec.js @@ -0,0 +1,170 @@ +/*jslint indent: 2, nomen: true, maxlen: 100, vars: true, white: true, plusplus: true */ +/*global require, exports, Backbone, window, $, arangoLog */ +(function () { + + "use strict"; + + describe("ArangoUsers", function() { + + var col; + + beforeEach(function() { + col = new window.ArangoUsers(); + window.App = jasmine.createSpyObj(window.Router, ["navigate"]); + }); + + it("comparator", function() { + expect(col.model).toEqual(window.Users); + expect(col.activeUser).toEqual(''); + expect(col.activeUserSettings).toEqual({ + "query" : {}, + "shell" : {}, + "testing": true + }); + expect(col.url).toEqual("/_api/user"); + expect(col.comparator({get : function(val) {return "Herbert"}})).toEqual("herbert"); + }); + + it("login", function() { + col.login("user", "pw") + expect(col.activeUser).toEqual("user"); + }); + it("logout", function() { + spyOn(col, "reset"); + spyOn(window.location, "reload"); + spyOn($, "ajax").andCallFake(function(state , opt) { + expect(state).toEqual("unauthorized"); + expect(opt).toEqual({async:false}); + return { + error : function (callback) { + callback(); + } + } + }); + col.logout() + expect(col.activeUser).toEqual(undefined); + expect(col.reset).toHaveBeenCalled(); + expect(window.App.navigate).toHaveBeenCalledWith(""); + expect(window.location.reload).toHaveBeenCalled(); + }); + + it("setUserSettings", function() { + col.setUserSettings("bad", true); + expect(col.activeUserSettings["identifier"]).toEqual(true); + }); + + it("loadUserSettings with success", function() { + col.activeUserSettings = { + "query" : {}, + "shell" : {}, + "testing": true + }; + col.activeUser = "heinz"; + spyOn($, "ajax").andCallFake(function(opt) { + expect(opt.url).toEqual("/_api/user/" + encodeURIComponent(col.activeUser)); + expect(opt.type).toEqual("GET"); + expect(opt.contentType).toEqual("application/json"); + expect(opt.cache).toEqual(false); + expect(opt.processData).toEqual(false); + expect(opt.async).toEqual(false); + opt.success({extra : { + Heinz : "herbert", + Heinz2 : "herbert2" + }}); + }); + col.loadUserSettings(); + expect(col.activeUserSettings).toEqual({ + Heinz : "herbert", + Heinz2 : "herbert2" + }); + }); + + it("loadUserSettings with error", function() { + col.activeUserSettings = { + "query" : {}, + "shell" : {}, + "testing": true + }; + col.activeUser = "heinz"; + spyOn($, "ajax").andCallFake(function(opt) { + expect(opt.url).toEqual("/_api/user/" + encodeURIComponent(col.activeUser)); + expect(opt.type).toEqual("GET"); + expect(opt.contentType).toEqual("application/json"); + expect(opt.cache).toEqual(false); + expect(opt.processData).toEqual(false); + expect(opt.async).toEqual(false); + opt.error({extra : { + Heinz : "herbert", + Heinz2 : "herbert2" + }}); + }); + col.loadUserSettings(); + expect(col.activeUserSettings).toEqual({ + "query" : {}, + "shell" : {}, + "testing": true + }); + }); + it("saveUserSettings with success", function() { + col.activeUser = "heinz"; + col.activeUserSettings = {a : "B"}; + spyOn($, "ajax").andCallFake(function(opt) { + expect(opt.url).toEqual("/_api/user/" + encodeURIComponent(col.activeUser)); + expect(opt.type).toEqual("PUT"); + expect(opt.contentType).toEqual("application/json"); + expect(opt.cache).toEqual(false); + expect(opt.data).toEqual(JSON.stringify({ extra: col.activeUserSettings })); + expect(opt.processData).toEqual(false); + expect(opt.async).toEqual(false); + opt.success(); + }); + col.saveUserSettings(); + expect($.ajax).toHaveBeenCalled(); + }); + + it("saveUserSettings with error", function() { + col.activeUser = "heinz"; + col.activeUserSettings = {a : "B"}; + spyOn($, "ajax").andCallFake(function(opt) { + expect(opt.url).toEqual("/_api/user/" + encodeURIComponent(col.activeUser)); + expect(opt.type).toEqual("PUT"); + expect(opt.contentType).toEqual("application/json"); + expect(opt.cache).toEqual(false); + expect(opt.data).toEqual(JSON.stringify({ extra: col.activeUserSettings })); + expect(opt.processData).toEqual(false); + expect(opt.async).toEqual(false); + opt.error(); + }); + col.saveUserSettings(); + expect($.ajax).toHaveBeenCalled(); + }); + + it("parse", function() { + expect(col.parse({ + result : ["a", "b", "c"] + })).toEqual(["a", "b", "c"]); + }); + + it("whoAmI without activeUser", function() { + col.activeUserSettings = {a : "B"}; + spyOn($, "ajax").andCallFake(function(state , opt) { + expect(state).toEqual("whoAmI"); + expect(opt).toEqual({async:false}); + return { + done : function (callback) { + callback({name : "heinz"}); + } + } + }); + expect(col.whoAmI()).toEqual("heinz"); + }); + + it("whoAmI with activeUser", function() { + col.activeUser = "heinz"; + expect(col.whoAmI()).toEqual("heinz"); + }); + + + }) +}()); + diff --git a/js/apps/system/aardvark/test/specs/collections/foxxCollectionSpec.js b/js/apps/system/aardvark/test/specs/collections/foxxCollectionSpec.js new file mode 100644 index 0000000000..e0817e8ac5 --- /dev/null +++ b/js/apps/system/aardvark/test/specs/collections/foxxCollectionSpec.js @@ -0,0 +1,22 @@ +/*jslint indent: 2, nomen: true, maxlen: 100, vars: true, white: true, plusplus: true */ +/*global require, exports, Backbone, window, $, arangoLog */ +(function () { + + "use strict"; + + describe("FoxxCollection", function() { + + var col; + + beforeEach(function() { + col = new window.FoxxCollection(); + }); + + it("FoxxCollection", function() { + expect(col.model).toEqual(window.Foxx); + expect(col.url).toEqual("/_admin/aardvark/foxxes"); + }); + + }) +}()); + diff --git a/js/apps/system/aardvark/test/specs/collections/graphCollectionSpec.js b/js/apps/system/aardvark/test/specs/collections/graphCollectionSpec.js new file mode 100644 index 0000000000..36a98fab95 --- /dev/null +++ b/js/apps/system/aardvark/test/specs/collections/graphCollectionSpec.js @@ -0,0 +1,24 @@ +/*jslint indent: 2, nomen: true, maxlen: 100, vars: true, white: true, plusplus: true */ +/*global require, exports, Backbone, window, $, arangoLog */ +(function () { + + "use strict"; + + describe("GraphCollection", function() { + + var col; + + beforeEach(function() { + col = new window.GraphCollection(); + }); + + it("parse", function() { + expect(col.model).toEqual(window.Graph); + expect(col.comparator).toEqual("_key"); + expect(col.url).toEqual("/_api/graph"); + expect(col.parse({error: false, graphs : "blub"})).toEqual("blub"); + expect(col.parse({error: true, graphs : "blub"})).toEqual(undefined); + }); + + }) +}()); diff --git a/js/apps/system/aardvark/test/specs/collections/notificationCollectionSpec.js b/js/apps/system/aardvark/test/specs/collections/notificationCollectionSpec.js new file mode 100644 index 0000000000..265b29aa5d --- /dev/null +++ b/js/apps/system/aardvark/test/specs/collections/notificationCollectionSpec.js @@ -0,0 +1,22 @@ +/*jslint indent: 2, nomen: true, maxlen: 100, vars: true, white: true, plusplus: true */ +/*global require, exports, Backbone, window, $, arangoLog */ +(function () { + + "use strict"; + + describe("NotificationCollection", function() { + + var col; + + beforeEach(function() { + col = new window.NotificationCollection(); + }); + + it("NotificationCollection", function() { + expect(col.model).toEqual(window.Notification); + expect(col.url).toEqual(""); + }); + + }) +}()); +