1
0
Fork 0

reformated tests

This commit is contained in:
scottashton 2014-03-31 14:31:39 +02:00
parent 75d123eea4
commit f7ceebe35b
2 changed files with 558 additions and 545 deletions

View File

@ -2,46 +2,46 @@
/*global window, $, Backbone, document, arangoCollectionModel*/ /*global window, $, Backbone, document, arangoCollectionModel*/
/*global arangoHelper,dashboardView,arangoDatabase*/ /*global arangoHelper,dashboardView,arangoDatabase*/
(function() { (function () {
"use strict"; "use strict";
window.Router = Backbone.Router.extend({ window.Router = Backbone.Router.extend({
routes: { routes: {
"" : "dashboard", "": "dashboard",
"dashboard" : "dashboard", "dashboard": "dashboard",
"collection/:colid" : "collection", "collection/:colid": "collection",
"collections" : "collections", "collections": "collections",
"collectionInfo/:colid" : "collectionInfo", "collectionInfo/:colid": "collectionInfo",
"new" : "newCollection", "new": "newCollection",
"login" : "login", "login": "login",
"collection/:colid/documents/:pageid" : "documents", "collection/:colid/documents/:pageid": "documents",
"collection/:colid/:docid" : "document", "collection/:colid/:docid": "document",
"shell" : "shell", "shell": "shell",
"query" : "query", "query": "query",
"logs" : "logs", "logs": "logs",
"api" : "api", "api": "api",
"databases" : "databases", "databases": "databases",
"application/installed/:key" : "applicationEdit", "application/installed/:key": "applicationEdit",
"application/available/:key" : "applicationInstall", "application/available/:key": "applicationInstall",
"applications" : "applications", "applications": "applications",
"application/documentation/:key" : "appDocumentation", "application/documentation/:key": "appDocumentation",
"graph" : "graph", "graph": "graph",
"graphManagement" : "graphManagement", "graphManagement": "graphManagement",
"graphManagement/add" : "graphAddNew", "graphManagement/add": "graphAddNew",
"graphManagement/delete/:name" : "graphDelete", "graphManagement/delete/:name": "graphDelete",
"userManagement" : "userManagement", "userManagement": "userManagement",
"userProfile" : "userProfile", "userProfile": "userProfile",
"testing" : "testview" "testing": "testview"
}, },
testview: function() { testview: function () {
this.testView = new window.testView(); this.testView = new window.testView();
this.testView.render(); this.testView.render();
}, },
initialize: function () { initialize: function () {
var self = this; var self = this;
this.bind('all', function(trigger, args) { this.bind('all', function (trigger, args) {
var routeData = trigger.split(":"); var routeData = trigger.split(":");
if (trigger === "route") { if (trigger === "route") {
if (self.currentRoute === "dashboard" && self.dashboardView) { if (self.currentRoute === "dashboard" && self.dashboardView) {
@ -101,8 +101,7 @@
this.initVersionCheck(); this.initVersionCheck();
var self = this; $(window).resize(function () {
$(window).resize(function() {
self.handleResize(); self.handleResize();
}); });
//this.handleResize(); //this.handleResize();
@ -117,19 +116,22 @@
async: true, async: true,
crossDomain: true, crossDomain: true,
dataType: "jsonp", dataType: "jsonp",
url: "https://www.arangodb.org/repositories/versions.php?callback=parseVersions", url: "https://www.arangodb.org/repositories/versions.php" +
"?callback=parseVersions",
success: function (json) { success: function (json) {
if (typeof json !== 'object') { if (typeof json !== 'object') {
return; return;
} }
// turn our own version string into a version object // turn our own version string into a version object
var currentVersion = window.versionHelper.fromString(self.footerView.system.version); var currentVersion =
window.versionHelper.fromString(self.footerView.system.version);
// get our mainline version // get our mainline version
var mainLine = window.versionHelper.toStringMainLine(currentVersion); var mainLine = window.versionHelper.toStringMainLine(currentVersion);
var mainLines = Object.keys(json).sort(window.versionHelper.compareVersionStrings); var mainLines = Object.keys(json).
sort(window.versionHelper.compareVersionStrings);
var latestMainLine; var latestMainLine;
mainLines.forEach(function (l) { mainLines.forEach(function (l) {
if (json[l].stable) { if (json[l].stable) {
@ -145,7 +147,8 @@
if (latestMainLine !== undefined && if (latestMainLine !== undefined &&
Object.keys(latestMainLine.versions).length > 0) { Object.keys(latestMainLine.versions).length > 0) {
mainLineVersions = Object.keys(latestMainLine.versions); mainLineVersions = Object.keys(latestMainLine.versions);
mainLineVersions = mainLineVersions.sort(window.versionHelper.compareVersionStrings); mainLineVersions = mainLineVersions.
sort(window.versionHelper.compareVersionStrings);
latest = mainLineVersions[mainLineVersions.length - 1]; latest = mainLineVersions[mainLineVersions.length - 1];
update = { update = {
@ -163,7 +166,8 @@
Object.keys(json[mainLine].versions).length > 0) { Object.keys(json[mainLine].versions).length > 0) {
// sort by version numbers // sort by version numbers
mainLineVersions = Object.keys(json[mainLine].versions); mainLineVersions = Object.keys(json[mainLine].versions);
mainLineVersions = mainLineVersions.sort(window.versionHelper.compareVersionStrings); mainLineVersions = mainLineVersions.
sort(window.versionHelper.compareVersionStrings);
latest = mainLineVersions[mainLineVersions.length - 1]; latest = mainLineVersions[mainLineVersions.length - 1];
var result = window.versionHelper.compareVersions( var result = window.versionHelper.compareVersions(
@ -220,7 +224,7 @@
this.naviView.selectMenuItem(''); this.naviView.selectMenuItem('');
}, },
collections: function() { collections: function () {
var naviView = this.naviView; var naviView = this.naviView;
window.arangoCollectionsStore.fetch({ window.arangoCollectionsStore.fetch({
success: function () { success: function () {
@ -230,7 +234,7 @@
}); });
}, },
collection: function(colid) { collection: function (colid) {
if (!this.collectionView) { if (!this.collectionView) {
this.collectionView = new window.CollectionView(); this.collectionView = new window.CollectionView();
} }
@ -238,7 +242,7 @@
this.collectionView.render(); this.collectionView.render();
this.naviView.selectMenuItem('collections-menu'); this.naviView.selectMenuItem('collections-menu');
}, },
collectionInfo: function(colid) { collectionInfo: function (colid) {
if (!this.collectionInfoView) { if (!this.collectionInfoView) {
this.collectionInfoView = new window.CollectionInfoView(); this.collectionInfoView = new window.CollectionInfoView();
} }
@ -246,7 +250,7 @@
this.collectionInfoView.render(); this.collectionInfoView.render();
this.naviView.selectMenuItem('collections-menu'); this.naviView.selectMenuItem('collections-menu');
}, },
newCollection: function() { newCollection: function () {
if (!this.newCollectionView) { if (!this.newCollectionView) {
this.newCollectionView = new window.newCollectionView({}); this.newCollectionView = new window.newCollectionView({});
} }
@ -254,7 +258,7 @@
this.naviView.selectMenuItem('collections-menu'); this.naviView.selectMenuItem('collections-menu');
}, },
documents: function(colid, pageid) { documents: function (colid, pageid) {
if (!window.documentsView) { if (!window.documentsView) {
window.documentsView.initTable(colid, pageid); window.documentsView.initTable(colid, pageid);
} }
@ -267,7 +271,7 @@
window.arangoDocumentsStore.getDocuments(colid, pageid); window.arangoDocumentsStore.getDocuments(colid, pageid);
}, },
document: function(colid, docid) { document: function (colid, docid) {
window.documentView.colid = colid; window.documentView.colid = colid;
window.documentView.docid = docid; window.documentView.docid = docid;
window.documentView.render(); window.documentView.render();
@ -276,7 +280,7 @@
window.documentView.typeCheck(type); window.documentView.typeCheck(type);
}, },
shell: function() { shell: function () {
if (!this.shellView) { if (!this.shellView) {
this.shellView = new window.shellView(); this.shellView = new window.shellView();
} }
@ -284,7 +288,7 @@
this.naviView.selectMenuItem('tools-menu'); this.naviView.selectMenuItem('tools-menu');
}, },
query: function() { query: function () {
if (!this.queryView) { if (!this.queryView) {
this.queryView = new window.queryView(); this.queryView = new window.queryView();
} }
@ -292,7 +296,7 @@
this.naviView.selectMenuItem('query-menu'); this.naviView.selectMenuItem('query-menu');
}, },
api: function() { api: function () {
if (!this.apiView) { if (!this.apiView) {
this.apiView = new window.apiView(); this.apiView = new window.apiView();
} }
@ -300,7 +304,7 @@
this.naviView.selectMenuItem('tools-menu'); this.naviView.selectMenuItem('tools-menu');
}, },
databases: function() { databases: function () {
if (arangoHelper.databaseAllowed() === true) { if (arangoHelper.databaseAllowed() === true) {
if (!this.databaseView) { if (!this.databaseView) {
this.databaseView = new window.databaseView({ this.databaseView = new window.databaseView({
@ -313,13 +317,13 @@
else { else {
this.navigate("#", {trigger: true}); this.navigate("#", {trigger: true});
this.naviView.selectMenuItem('dashboard-menu'); this.naviView.selectMenuItem('dashboard-menu');
$('#databaseNavi').css('display','none'); $('#databaseNavi').css('display', 'none');
$('#databaseNaviSelect').css('display','none'); $('#databaseNaviSelect').css('display', 'none');
} }
}, },
logs: function() { logs: function () {
if (! this.logsAllowed()) { if (!this.logsAllowed()) {
this.navigate('', { trigger: true }); this.navigate('', { trigger: true });
return; return;
} }
@ -336,12 +340,12 @@
this.naviView.selectMenuItem('tools-menu'); this.naviView.selectMenuItem('tools-menu');
}, },
dashboard: function() { dashboard: function () {
this.naviView.selectMenuItem('dashboard-menu'); this.naviView.selectMenuItem('dashboard-menu');
if (this.statisticsDescriptionCollection === undefined) { if (this.statisticsDescriptionCollection === undefined) {
this.statisticsDescriptionCollection = new window.StatisticsDescriptionCollection(); this.statisticsDescriptionCollection = new window.StatisticsDescriptionCollection();
this.statisticsDescriptionCollection.fetch({ this.statisticsDescriptionCollection.fetch({
async:false async: false
}); });
} }
if (this.statistics === undefined) { if (this.statistics === undefined) {
@ -352,13 +356,13 @@
collection: this.statisticsCollection, collection: this.statisticsCollection,
description: this.statisticsDescriptionCollection, description: this.statisticsDescriptionCollection,
documentStore: window.arangoDocumentsStore, documentStore: window.arangoDocumentsStore,
dygraphConfig : window.dygraphConfig dygraphConfig: window.dygraphConfig
}); });
} }
this.dashboardView.render(); this.dashboardView.render();
}, },
graph: function() { graph: function () {
var self = this; var self = this;
window.arangoCollectionsStore.fetch({ window.arangoCollectionsStore.fetch({
success: function () { success: function () {
@ -368,15 +372,16 @@
}); });
}, },
graphManagement: function() { graphManagement: function () {
if (!this.graphManagementView) { if (!this.graphManagementView) {
this.graphManagementView = new window.GraphManagementView({collection: this.graphs}); this.graphManagementView =
new window.GraphManagementView({collection: this.graphs});
} }
this.graphManagementView.render(); this.graphManagementView.render();
this.naviView.selectMenuItem('graphviewer-menu'); this.naviView.selectMenuItem('graphviewer-menu');
}, },
graphAddNew: function() { graphAddNew: function () {
if (!this.addNewGraphView) { if (!this.addNewGraphView) {
this.addNewGraphView = new window.AddNewGraphView({ this.addNewGraphView = new window.AddNewGraphView({
collection: window.arangoCollectionsStore, collection: window.arangoCollectionsStore,
@ -387,7 +392,7 @@
this.naviView.selectMenuItem('graphviewer-menu'); this.naviView.selectMenuItem('graphviewer-menu');
}, },
graphDelete: function(name) { graphDelete: function (name) {
if (!this.deleteGraphView) { if (!this.deleteGraphView) {
this.deleteGraphView = new window.DeleteGraphView({ this.deleteGraphView = new window.DeleteGraphView({
collection: this.graphs collection: this.graphs
@ -397,7 +402,7 @@
this.naviView.selectMenuItem('graphviewer-menu'); this.naviView.selectMenuItem('graphviewer-menu');
}, },
applications: function() { applications: function () {
if (this.applicationsView === undefined) { if (this.applicationsView === undefined) {
this.applicationsView = new window.ApplicationsView({ this.applicationsView = new window.ApplicationsView({
collection: this.foxxList collection: this.foxxList
@ -407,15 +412,17 @@
this.naviView.selectMenuItem('applications-menu'); this.naviView.selectMenuItem('applications-menu');
}, },
applicationEdit: function(appkey) { applicationEdit: function (appkey) {
this.foxxList.fetch({ this.foxxList.fetch({
async: false async: false
}); });
var editAppView = new window.foxxEditView({model: this.foxxList.findWhere({_key: appkey})}); var editAppView = new window.foxxEditView(
{model: this.foxxList.findWhere({_key: appkey})}
);
editAppView.render(); editAppView.render();
}, },
applicationInstall: function(appkey) { applicationInstall: function (appkey) {
this.foxxList.fetch({ this.foxxList.fetch({
async: false async: false
}); });
@ -427,7 +434,7 @@
this.installAppView.render(appkey); this.installAppView.render(appkey);
}, },
appDocumentation: function(key) { appDocumentation: function (key) {
var docuView = new window.AppDocumentationView({key: key}); var docuView = new window.AppDocumentationView({key: key});
docuView.render(); docuView.render();
this.naviView.selectMenuItem('applications-menu'); this.naviView.selectMenuItem('applications-menu');
@ -447,8 +454,8 @@
var spanWidth = 243; var spanWidth = 243;
var divider = containerWidth / spanWidth; var divider = containerWidth / spanWidth;
var roundDiv = parseInt(divider, 10); var roundDiv = parseInt(divider, 10);
var newWidth = roundDiv*spanWidth -2; var newWidth = roundDiv * spanWidth - 2;
var marginWidth = ((containerWidth+30) - newWidth)/2; var marginWidth = ((containerWidth + 30) - newWidth) / 2;
/* /*
$('#content').width(newWidth) $('#content').width(newWidth)
.css('margin-left', marginWidth) .css('margin-left', marginWidth)
@ -461,7 +468,7 @@
} }
}, },
userManagement: function() { userManagement: function () {
if (!this.userManagementView) { if (!this.userManagementView) {
this.userManagementView = new window.userManagementView({ this.userManagementView = new window.userManagementView({
collection: window.userCollection collection: window.userCollection
@ -471,7 +478,7 @@
this.naviView.selectMenuItem('tools-menu'); this.naviView.selectMenuItem('tools-menu');
}, },
userProfile: function() { userProfile: function () {
if (!this.userProfileView) { if (!this.userProfileView) {
this.userProfileView = new window.userProfileView({ this.userProfileView = new window.userProfileView({
collection: window.userCollection collection: window.userCollection

View File

@ -1,5 +1,5 @@
/*jslint indent: 2, nomen: true, maxlen: 100, white: true plusplus: true, browser: true*/ /*jslint indent: 2, nomen: true, maxlen: 100, white: true plusplus: true, browser: true*/
/*global describe, beforeEach, afterEach, it, spyOn, expect*/ /*global describe, beforeEach, arangoHelper, afterEach, it, console, spyOn, expect*/
/*global $, jasmine, _*/ /*global $, jasmine, _*/
(function () { (function () {
@ -89,12 +89,12 @@
id: "statisticsDescription", id: "statisticsDescription",
fetch: function () { fetch: function () {
} }
} };
statisticsCollectionDummy = { statisticsCollectionDummy = {
id: "statisticsCollection", id: "statisticsCollection",
fetch: function () { fetch: function () {
} }
} };
fakeDB = { fakeDB = {
id: "fakeDB", id: "fakeDB",
fetch: function () { fetch: function () {
@ -150,14 +150,15 @@
spyOn(window, "DocumentsView").andReturn(documentsViewDummy); spyOn(window, "DocumentsView").andReturn(documentsViewDummy);
spyOn(window, "DocumentView").andReturn(documentViewDummy); spyOn(window, "DocumentView").andReturn(documentViewDummy);
;
spyOn(window, "arangoCollections").andReturn(storeDummy); spyOn(window, "arangoCollections").andReturn(storeDummy);
spyOn(window, "ArangoUsers").andReturn(sessionDummy); spyOn(window, "ArangoUsers").andReturn(sessionDummy);
spyOn(window, "arangoDocuments").andReturn(documentsDummy); spyOn(window, "arangoDocuments").andReturn(documentsDummy);
spyOn(window, "arangoDocument").andReturn(documentDummy); spyOn(window, "arangoDocument").andReturn(documentDummy);
spyOn(window, "GraphCollection").andReturn(graphsDummy); spyOn(window, "GraphCollection").andReturn(graphsDummy);
spyOn(window, "FoxxCollection").andReturn(foxxDummy); spyOn(window, "FoxxCollection").andReturn(foxxDummy);
spyOn(window, "StatisticsDescriptionCollection").andReturn(statisticsDescriptionCollectionDummy); spyOn(window, "StatisticsDescriptionCollection").andReturn(
statisticsDescriptionCollectionDummy
);
spyOn(window, "StatisticsCollection").andReturn(statisticsCollectionDummy); spyOn(window, "StatisticsCollection").andReturn(statisticsCollectionDummy);
spyOn(window, "CollectionsView").andReturn(collectionsViewDummy); spyOn(window, "CollectionsView").andReturn(collectionsViewDummy);
spyOn(window, "LogsView").andReturn(logsViewDummy); spyOn(window, "LogsView").andReturn(logsViewDummy);
@ -275,7 +276,9 @@
beforeEach(function () { beforeEach(function () {
r = new window.Router(); r = new window.Router();
simpleNavigationCheck = function (url, viewName, navTo, initObject, funcList, shouldNotRender, shouldNotCache) { simpleNavigationCheck =
function (url, viewName, navTo, initObject,
funcList, shouldNotRender, shouldNotCache) {
var route, var route,
view = {}, view = {},
checkFuncExec = function () { checkFuncExec = function () {
@ -419,8 +422,6 @@
return msg; return msg;
}; };
return true; return true;
return leftDiff.length === 0
&& rightDiff.length === 0;
} }
}); });
expect(available).toDefineTheRoutes(expected); expect(available).toDefineTheRoutes(expected);
@ -881,7 +882,8 @@
}); });
it("initVersionCheck with installed Version 2.0.1, latest 2.0.1, stablee 2.0.1", function () { it("initVersionCheck with installed Version 2.0.1, latest 2.0.1, stablee 2.0.1",
function () {
spyOn(window, "setTimeout").andCallFake(function (a, int) { spyOn(window, "setTimeout").andCallFake(function (a, int) {
if (int === 5000) { if (int === 5000) {
a(); a();
@ -918,7 +920,8 @@
expect(arangoHelper.arangoNotification).not.toHaveBeenCalled(); expect(arangoHelper.arangoNotification).not.toHaveBeenCalled();
}); });
it("initVersionCheck with installed Version 1.4.5, latest 2.0.1, stable 2.0.1", function () { it("initVersionCheck with installed Version 1.4.5, " +
"latest 2.0.1, stable 2.0.1", function () {
spyOn(window, "setTimeout").andCallFake(function (a, int) { spyOn(window, "setTimeout").andCallFake(function (a, int) {
if (int === 5000) { if (int === 5000) {
a(); a();
@ -957,13 +960,15 @@
spyOn(arangoHelper, "arangoNotification"); spyOn(arangoHelper, "arangoNotification");
r.initVersionCheck(); r.initVersionCheck();
var changes = "https:\/\/www.arangodb.org\/2.0.1"; var changes = "https:\/\/www.arangodb.org\/2.0.1";
expect(arangoHelper.arangoNotification).toHaveBeenCalledWith("A newer version of ArangoDB (2.0.1" + expect(arangoHelper.arangoNotification).toHaveBeenCalledWith(
"A newer version of ArangoDB (2.0.1" +
") has become available. You may want to check the " + ") has become available. You may want to check the " +
"changelog at <a href=\"" + changes + "\">" + "changelog at <a href=\"" + changes + "\">" +
changes + "</a>", 15000); changes + "</a>", 15000);
}); });
it("initVersionCheck with installed Version 2.0.0, latest 2.0.2, stable 2.0.1", function () { it("initVersionCheck with installed Version 2.0.0, latest 2.0.2, stable 2.0.1",
function () {
spyOn(window, "setTimeout").andCallFake(function (a, int) { spyOn(window, "setTimeout").andCallFake(function (a, int) {
if (int === 5000) { if (int === 5000) {
a(); a();
@ -996,7 +1001,8 @@
spyOn(arangoHelper, "arangoNotification"); spyOn(arangoHelper, "arangoNotification");
r.initVersionCheck(); r.initVersionCheck();
var changes = "https:\/\/www.arangodb.org\/2.1.1"; var changes = "https:\/\/www.arangodb.org\/2.1.1";
expect(arangoHelper.arangoNotification).toHaveBeenCalledWith("A newer version of ArangoDB (2.1.1" + expect(arangoHelper.arangoNotification).toHaveBeenCalledWith(
"A newer version of ArangoDB (2.1.1" +
") has become available. You may want to check the " + ") has become available. You may want to check the " +
"changelog at <a href=\"" + changes + "\">" + "changelog at <a href=\"" + changes + "\">" +
changes + "</a>", 15000); changes + "</a>", 15000);