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
|
||||
// and disable the save functionality
|
||||
var boolTemp = false;
|
||||
this.customQueries.some(function(query){
|
||||
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;
|
||||
}
|
||||
var found = this.customQueries.some(function(query){
|
||||
return query.name === saveName;
|
||||
});
|
||||
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 () {
|
||||
|
@ -372,9 +366,9 @@
|
|||
});
|
||||
|
||||
//old storage method
|
||||
if (localStorage.getItem("customQueries")) {
|
||||
|
||||
var queries = JSON.parse(localStorage.getItem("customQueries"));
|
||||
var item = localStorage.getItem("customQueries");
|
||||
if (item) {
|
||||
var queries = JSON.parse(item);
|
||||
//save queries in user collections extra attribute
|
||||
_.each(queries, function(oldQuery) {
|
||||
self.collection.add({
|
||||
|
|
|
@ -61,12 +61,46 @@
|
|||
document.body.appendChild(div);
|
||||
|
||||
queryCollection = {
|
||||
__content: [],
|
||||
fetch: function() {},
|
||||
each: function() {},
|
||||
add: function() {},
|
||||
saveCollectionQueries: function() {}
|
||||
};
|
||||
__content: [],
|
||||
fetch: function() {},
|
||||
findWhere: function(ex) {
|
||||
var i, k, found;
|
||||
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({
|
||||
collection: queryCollection,
|
||||
|
@ -338,12 +372,8 @@
|
|||
|
||||
spyOn(view, "renderSelectboxes");
|
||||
spyOn(view, "updateTable");
|
||||
spyOn(localStorage, "setItem");
|
||||
|
||||
view.deleteAQL(e);
|
||||
expect(localStorage.setItem).toHaveBeenCalledWith(
|
||||
"customQueries", JSON.stringify(view.customQueries)
|
||||
);
|
||||
expect(view.renderSelectboxes).toHaveBeenCalled();
|
||||
expect(view.updateTable).toHaveBeenCalled();
|
||||
});
|
||||
|
@ -366,13 +396,13 @@
|
|||
|
||||
spyOn(e, "stopPropagation");
|
||||
spyOn(window.modalView, "hide");
|
||||
spyOn(localStorage, "setItem");
|
||||
spyOn(view, "renderSelectboxes");
|
||||
spyOn(queryCollection, "add");
|
||||
|
||||
view.saveAQL(e);
|
||||
|
||||
expect(e.stopPropagation).toHaveBeenCalled();
|
||||
expect(localStorage.setItem).toHaveBeenCalled();
|
||||
expect(queryCollection.add).toHaveBeenCalled();
|
||||
expect(view.renderSelectboxes).toHaveBeenCalled();
|
||||
expect(window.modalView.hide).toHaveBeenCalled();
|
||||
document.body.removeChild(div2);
|
||||
|
@ -420,7 +450,7 @@
|
|||
throw "Should be a spy";
|
||||
}
|
||||
};
|
||||
localStorageFake = JSON.stringify(customQueries);
|
||||
localStorageFake.value = JSON.stringify(customQueries);
|
||||
view.initialize();
|
||||
|
||||
div2 = document.createElement("div");
|
||||
|
@ -452,7 +482,7 @@
|
|||
throw "Should be a spy";
|
||||
}
|
||||
};
|
||||
localStorageFake = JSON.stringify(customQueries);
|
||||
localStorageFake.value = JSON.stringify(customQueries);
|
||||
view.initialize();
|
||||
|
||||
div2 = document.createElement("div");
|
||||
|
@ -462,13 +492,13 @@
|
|||
|
||||
spyOn(e, "stopPropagation");
|
||||
spyOn(window.modalView, "hide");
|
||||
spyOn(localStorage, "setItem");
|
||||
spyOn(view, "renderSelectboxes");
|
||||
spyOn(queryCollection, "add");
|
||||
|
||||
view.saveAQL(e);
|
||||
|
||||
expect(e.stopPropagation).toHaveBeenCalled();
|
||||
expect(localStorage.setItem).not.toHaveBeenCalled();
|
||||
expect(queryCollection.add).not.toHaveBeenCalled();
|
||||
expect(view.renderSelectboxes).not.toHaveBeenCalled();
|
||||
expect(window.modalView.hide).toHaveBeenCalled();
|
||||
document.body.removeChild(div2);
|
||||
|
@ -480,7 +510,7 @@
|
|||
value: "for var yx do something"
|
||||
}],
|
||||
returnValue;
|
||||
localStorageFake = JSON.stringify(customQueries);
|
||||
localStorageFake.value = JSON.stringify(customQueries);
|
||||
view.initialize();
|
||||
|
||||
returnValue = view.getCustomQueryValueByName("hallotest");
|
||||
|
@ -492,31 +522,26 @@
|
|||
div2.id = "test123";
|
||||
document.body.appendChild(div2);
|
||||
|
||||
localStorageFake = 5000;
|
||||
localStorageFake.value = 5000;
|
||||
|
||||
view.initialize();
|
||||
spyOn(localStorage, "getItem");
|
||||
view.render();
|
||||
expect(localStorage.getItem).toHaveBeenCalledWith("querySize");
|
||||
expect(localStorage.getItem).toHaveBeenCalledWith("customQueries");
|
||||
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() {
|
||||
// not finished yet
|
||||
spyOn(view, "deselect");
|
||||
var old = window.progressView;
|
||||
window.progressView = {
|
||||
show: function() {}
|
||||
};
|
||||
spyOn(window.progressView, "show");
|
||||
view.submitQuery();
|
||||
expect(view.deselect).toHaveBeenCalled();
|
||||
expect(window.progressView.show).toHaveBeenCalled();
|
||||
window.progressView = old;
|
||||
});
|
||||
|
||||
it("should just run basic functionality of ace editor", function() {
|
||||
|
@ -539,7 +564,7 @@
|
|||
}
|
||||
};
|
||||
$('#findme').val('findme');
|
||||
localStorageFake = JSON.stringify(customQueries);
|
||||
localStorageFake.value = JSON.stringify(customQueries);
|
||||
view.initialize();
|
||||
|
||||
view.importSelected(e);
|
||||
|
@ -590,14 +615,14 @@
|
|||
view.customQueries = customQueries;
|
||||
|
||||
spyOn(view, "sortQueries");
|
||||
spyOn(arangoHelper, "escapeHtml");
|
||||
spyOn(_, "escape");
|
||||
|
||||
view.renderSelectboxes();
|
||||
|
||||
expect(view.sortQueries).toHaveBeenCalled();
|
||||
expect(jQueryDummy.empty).toHaveBeenCalled();
|
||||
expect(jQueryDummy.append).toHaveBeenCalled();
|
||||
expect(arangoHelper.escapeHtml).toHaveBeenCalled();
|
||||
expect(_.escape).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue