Commit c6489b26 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

unit tests for remove confirmation button

parent cc9b1cc3
......@@ -139,7 +139,7 @@ CommentsAdminPanel.prototype.onProjectChange = function () {
dataTable.clear().rows.add(data).draw();
$("[name='commentsTable']", self.getElement()).on("click", "[name='removeComment']", function () {
var button = this;
return self.askConfirmRemoval().then(function (param) {
return self.askConfirmRemoval({title: "Why do you want to remove this comment?"}).then(function (param) {
if (param.status) {
return ServerConnector.removeComment({
commentId: $(button).attr("data"),
......@@ -211,18 +211,22 @@ CommentsAdminPanel.prototype.destroy = function () {
}
};
CommentsAdminPanel.prototype.askConfirmRemoval = function () {
CommentsAdminPanel.prototype.askConfirmRemoval = function (params) {
return new Promise(function (resolve) {
$('<form><input type="text" style="z-index:10000" name="name"><br></form>').dialog({
modal: true,
title: "Why do you want to remove this comment?",
title: params.title,
close: function () {
$(this).dialog('destroy').remove();
resolve({status: false});
},
buttons: {
'OK': function () {
$(this).dialog('close');
$(this).dialog('destroy').remove();
resolve({reason: $('input[name="name"]').val(), status: true});
},
'Cancel': function () {
$(this).dialog('close');
$(this).dialog('destroy').remove();
resolve({status: false});
}
}
......
"use strict";
require("../../mocha-config");
var CommentsAdminPanel = require('../../../../main/js/gui/admin/CommentsAdminPanel');
var ServerConnector = require('../../ServerConnector-mock');
var logger = require('../../logger');
var fs = require("fs");
var chai = require('chai');
var assert = chai.assert;
describe('CommentsAdminPanel', function () {
function createDialog() {
return ServerConnector.getConfiguration().then(function (configuration) {
return new CommentsAdminPanel({
element: testDiv,
configuration: configuration,
customMap: null
});
});
}
describe('askConfirmRemoval', function () {
it('check question', function () {
helper.loginAsAdmin();
return createDialog().then(function (dialog) {
var title = "Question?";
dialog.askConfirmRemoval({title: title});
assert.ok($(".ui-dialog-title").html().indexOf(title) >= 0);
$("button:contains(Cancel)").click();
return dialog.destroy();
});
});
it('check ok status', function () {
helper.loginAsAdmin();
var dialog;
return createDialog().then(function (result) {
dialog = result;
var promise = dialog.askConfirmRemoval({title: "Question?"});
$("button:contains(OK)").click();
return promise;
}).then(function (result) {
assert.ok(result.status);
return dialog.destroy();
});
});
it('check cancel status', function () {
helper.loginAsAdmin();
var dialog;
return createDialog().then(function (result) {
dialog = result;
var promise = dialog.askConfirmRemoval({title: "Question?"});
$("button:contains(Cancel)").click();
return promise;
}).then(function (result) {
assert.notOk(result.status);
return dialog.destroy();
});
});
it('check close confirmation status', function () {
helper.loginAsAdmin();
var dialog;
return createDialog().then(function (result) {
dialog = result;
var promise = dialog.askConfirmRemoval({title: "Question?"});
$(".ui-dialog-titlebar-close").click();
return promise;
}).then(function (result) {
assert.notOk(result.status);
return dialog.destroy();
});
});
});
});
......@@ -356,7 +356,6 @@ describe('AbstractCustomMap', function () {
var reaction = helper.createReaction(map);
var center = map.getGoogleMap().getCenter();
return map.fitBounds([reaction]).then(function () {
var center2 = map.getGoogleMap().getCenter();
assert.ok(center.lat() !== center2.lat() || center.lng() !== center2.lng());
})
......
......@@ -159,5 +159,15 @@ afterEach(function () {
$(window).off("resize");
this.test.error(new Error("Test didn't left clean resize events handlers."));
}
} else {
//when failed don't forget to clean events
if ($._data(window, "events").resize) {
logger.warn("Clearing events: " + $._data(window, "events").resize);
$(window).off("resize");
}
if (document.body.hasChildNodes()) {
logger.warn("Clearing html");
document.body.innerHTML = "";
}
}
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment