mirror of https://gitee.com/bigwinds/arangodb
Fixed tests for query view
This commit is contained in:
parent
c1a889b87b
commit
614aac3eba
|
@ -119,24 +119,18 @@
|
||||||
|
|
||||||
//check for invalid query names, if present change the box-shadow to red
|
//check for invalid query names, if present change the box-shadow to red
|
||||||
// and disable the save functionality
|
// and disable the save functionality
|
||||||
var boolTemp = false;
|
var found = this.customQueries.some(function(query){
|
||||||
this.customQueries.some(function(query){
|
return query.name === saveName;
|
||||||
if( query.name === saveName ){
|
|
||||||
$('#modalButton1').removeClass('button-success');
|
|
||||||
$('#modalButton1').addClass('button-warning');
|
|
||||||
$('#modalButton1').text('Update');
|
|
||||||
boolTemp = true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$('#modalButton1').removeClass('button-warning');
|
|
||||||
$('#modalButton1').addClass('button-success');
|
|
||||||
$('#modalButton1').text('Save');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (boolTemp) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
if(found){
|
||||||
|
$('#modalButton1').removeClass('button-success');
|
||||||
|
$('#modalButton1').addClass('button-warning');
|
||||||
|
$('#modalButton1').text('Update');
|
||||||
|
} else {
|
||||||
|
$('#modalButton1').removeClass('button-warning');
|
||||||
|
$('#modalButton1').addClass('button-success');
|
||||||
|
$('#modalButton1').text('Save');
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
clearOutput: function () {
|
clearOutput: function () {
|
||||||
|
@ -372,9 +366,9 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
//old storage method
|
//old storage method
|
||||||
if (localStorage.getItem("customQueries")) {
|
var item = localStorage.getItem("customQueries");
|
||||||
|
if (item) {
|
||||||
var queries = JSON.parse(localStorage.getItem("customQueries"));
|
var queries = JSON.parse(item);
|
||||||
//save queries in user collections extra attribute
|
//save queries in user collections extra attribute
|
||||||
_.each(queries, function(oldQuery) {
|
_.each(queries, function(oldQuery) {
|
||||||
self.collection.add({
|
self.collection.add({
|
||||||
|
|
|
@ -61,12 +61,46 @@
|
||||||
document.body.appendChild(div);
|
document.body.appendChild(div);
|
||||||
|
|
||||||
queryCollection = {
|
queryCollection = {
|
||||||
__content: [],
|
__content: [],
|
||||||
fetch: function() {},
|
fetch: function() {},
|
||||||
each: function() {},
|
findWhere: function(ex) {
|
||||||
add: function() {},
|
var i, k, found;
|
||||||
saveCollectionQueries: function() {}
|
for (i = 0; i < this.__content.length; ++i) {
|
||||||
};
|
found = true;
|
||||||
|
for (k in ex) {
|
||||||
|
if (!ex.hasOwnProperty(k) || !this.__content[i].hasOwnProperty(k) || ex[k] !== this.__content[i][k]) {
|
||||||
|
found = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (found) {
|
||||||
|
return this.__content[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
each: function(func) {
|
||||||
|
return this.__content.forEach(func);
|
||||||
|
},
|
||||||
|
some: function(func) {
|
||||||
|
var res = false, i;
|
||||||
|
for (i = 0; i < this.__content.length; ++i) {
|
||||||
|
res = res || func(this.__content[i]);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
},
|
||||||
|
remove: function(obj) {
|
||||||
|
var i;
|
||||||
|
for (i = 0; i < this.__content.length; ++i) {
|
||||||
|
if(this.__content[i] === obj) {
|
||||||
|
this.__content.splice(i, 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
add: function(item) {
|
||||||
|
this.__content.push(new DummyModel(item));
|
||||||
|
},
|
||||||
|
saveCollectionQueries: function() {}
|
||||||
|
};
|
||||||
|
|
||||||
view = new window.queryView({
|
view = new window.queryView({
|
||||||
collection: queryCollection,
|
collection: queryCollection,
|
||||||
|
@ -338,12 +372,8 @@
|
||||||
|
|
||||||
spyOn(view, "renderSelectboxes");
|
spyOn(view, "renderSelectboxes");
|
||||||
spyOn(view, "updateTable");
|
spyOn(view, "updateTable");
|
||||||
spyOn(localStorage, "setItem");
|
|
||||||
|
|
||||||
view.deleteAQL(e);
|
view.deleteAQL(e);
|
||||||
expect(localStorage.setItem).toHaveBeenCalledWith(
|
|
||||||
"customQueries", JSON.stringify(view.customQueries)
|
|
||||||
);
|
|
||||||
expect(view.renderSelectboxes).toHaveBeenCalled();
|
expect(view.renderSelectboxes).toHaveBeenCalled();
|
||||||
expect(view.updateTable).toHaveBeenCalled();
|
expect(view.updateTable).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
@ -366,13 +396,13 @@
|
||||||
|
|
||||||
spyOn(e, "stopPropagation");
|
spyOn(e, "stopPropagation");
|
||||||
spyOn(window.modalView, "hide");
|
spyOn(window.modalView, "hide");
|
||||||
spyOn(localStorage, "setItem");
|
|
||||||
spyOn(view, "renderSelectboxes");
|
spyOn(view, "renderSelectboxes");
|
||||||
|
spyOn(queryCollection, "add");
|
||||||
|
|
||||||
view.saveAQL(e);
|
view.saveAQL(e);
|
||||||
|
|
||||||
expect(e.stopPropagation).toHaveBeenCalled();
|
expect(e.stopPropagation).toHaveBeenCalled();
|
||||||
expect(localStorage.setItem).toHaveBeenCalled();
|
expect(queryCollection.add).toHaveBeenCalled();
|
||||||
expect(view.renderSelectboxes).toHaveBeenCalled();
|
expect(view.renderSelectboxes).toHaveBeenCalled();
|
||||||
expect(window.modalView.hide).toHaveBeenCalled();
|
expect(window.modalView.hide).toHaveBeenCalled();
|
||||||
document.body.removeChild(div2);
|
document.body.removeChild(div2);
|
||||||
|
@ -420,7 +450,7 @@
|
||||||
throw "Should be a spy";
|
throw "Should be a spy";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
localStorageFake = JSON.stringify(customQueries);
|
localStorageFake.value = JSON.stringify(customQueries);
|
||||||
view.initialize();
|
view.initialize();
|
||||||
|
|
||||||
div2 = document.createElement("div");
|
div2 = document.createElement("div");
|
||||||
|
@ -452,7 +482,7 @@
|
||||||
throw "Should be a spy";
|
throw "Should be a spy";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
localStorageFake = JSON.stringify(customQueries);
|
localStorageFake.value = JSON.stringify(customQueries);
|
||||||
view.initialize();
|
view.initialize();
|
||||||
|
|
||||||
div2 = document.createElement("div");
|
div2 = document.createElement("div");
|
||||||
|
@ -462,13 +492,13 @@
|
||||||
|
|
||||||
spyOn(e, "stopPropagation");
|
spyOn(e, "stopPropagation");
|
||||||
spyOn(window.modalView, "hide");
|
spyOn(window.modalView, "hide");
|
||||||
spyOn(localStorage, "setItem");
|
|
||||||
spyOn(view, "renderSelectboxes");
|
spyOn(view, "renderSelectboxes");
|
||||||
|
spyOn(queryCollection, "add");
|
||||||
|
|
||||||
view.saveAQL(e);
|
view.saveAQL(e);
|
||||||
|
|
||||||
expect(e.stopPropagation).toHaveBeenCalled();
|
expect(e.stopPropagation).toHaveBeenCalled();
|
||||||
expect(localStorage.setItem).not.toHaveBeenCalled();
|
expect(queryCollection.add).not.toHaveBeenCalled();
|
||||||
expect(view.renderSelectboxes).not.toHaveBeenCalled();
|
expect(view.renderSelectboxes).not.toHaveBeenCalled();
|
||||||
expect(window.modalView.hide).toHaveBeenCalled();
|
expect(window.modalView.hide).toHaveBeenCalled();
|
||||||
document.body.removeChild(div2);
|
document.body.removeChild(div2);
|
||||||
|
@ -480,7 +510,7 @@
|
||||||
value: "for var yx do something"
|
value: "for var yx do something"
|
||||||
}],
|
}],
|
||||||
returnValue;
|
returnValue;
|
||||||
localStorageFake = JSON.stringify(customQueries);
|
localStorageFake.value = JSON.stringify(customQueries);
|
||||||
view.initialize();
|
view.initialize();
|
||||||
|
|
||||||
returnValue = view.getCustomQueryValueByName("hallotest");
|
returnValue = view.getCustomQueryValueByName("hallotest");
|
||||||
|
@ -492,31 +522,26 @@
|
||||||
div2.id = "test123";
|
div2.id = "test123";
|
||||||
document.body.appendChild(div2);
|
document.body.appendChild(div2);
|
||||||
|
|
||||||
localStorageFake = 5000;
|
localStorageFake.value = 5000;
|
||||||
|
|
||||||
view.initialize();
|
view.initialize();
|
||||||
spyOn(localStorage, "getItem");
|
|
||||||
view.render();
|
view.render();
|
||||||
expect(localStorage.getItem).toHaveBeenCalledWith("querySize");
|
expect(localStorage.getItem).toHaveBeenCalledWith("customQueries");
|
||||||
document.body.removeChild(div2);
|
document.body.removeChild(div2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should change the query size", function() {
|
|
||||||
var e = {
|
|
||||||
currentTarget: {
|
|
||||||
id: "test123"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
spyOn(localStorage, "setItem");
|
|
||||||
view.changeSize(e);
|
|
||||||
expect(localStorage.setItem).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("submit a query and fail without a msg from server", function() {
|
it("submit a query and fail without a msg from server", function() {
|
||||||
// not finished yet
|
// not finished yet
|
||||||
spyOn(view, "deselect");
|
spyOn(view, "deselect");
|
||||||
|
var old = window.progressView;
|
||||||
|
window.progressView = {
|
||||||
|
show: function() {}
|
||||||
|
};
|
||||||
|
spyOn(window.progressView, "show");
|
||||||
view.submitQuery();
|
view.submitQuery();
|
||||||
expect(view.deselect).toHaveBeenCalled();
|
expect(view.deselect).toHaveBeenCalled();
|
||||||
|
expect(window.progressView.show).toHaveBeenCalled();
|
||||||
|
window.progressView = old;
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should just run basic functionality of ace editor", function() {
|
it("should just run basic functionality of ace editor", function() {
|
||||||
|
@ -539,7 +564,7 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
$('#findme').val('findme');
|
$('#findme').val('findme');
|
||||||
localStorageFake = JSON.stringify(customQueries);
|
localStorageFake.value = JSON.stringify(customQueries);
|
||||||
view.initialize();
|
view.initialize();
|
||||||
|
|
||||||
view.importSelected(e);
|
view.importSelected(e);
|
||||||
|
@ -590,14 +615,14 @@
|
||||||
view.customQueries = customQueries;
|
view.customQueries = customQueries;
|
||||||
|
|
||||||
spyOn(view, "sortQueries");
|
spyOn(view, "sortQueries");
|
||||||
spyOn(arangoHelper, "escapeHtml");
|
spyOn(_, "escape");
|
||||||
|
|
||||||
view.renderSelectboxes();
|
view.renderSelectboxes();
|
||||||
|
|
||||||
expect(view.sortQueries).toHaveBeenCalled();
|
expect(view.sortQueries).toHaveBeenCalled();
|
||||||
expect(jQueryDummy.empty).toHaveBeenCalled();
|
expect(jQueryDummy.empty).toHaveBeenCalled();
|
||||||
expect(jQueryDummy.append).toHaveBeenCalled();
|
expect(jQueryDummy.append).toHaveBeenCalled();
|
||||||
expect(arangoHelper.escapeHtml).toHaveBeenCalled();
|
expect(_.escape).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue