Skip to content

Commit bfb1ef0

Browse files
authored
ADD: errors store (#53)
* FIX: issue with frontendUrl * FIX: serialization * ADD: errors store * FIX: entries generation issue * ADD: scrollbar * ADD: functional test review fixes * fixed test
1 parent 5a24f50 commit bfb1ef0

File tree

12 files changed

+150
-144
lines changed

12 files changed

+150
-144
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.ericsson.ei.frontend;
2+
3+
import com.ericsson.ei.frontend.pageobjects.IndexPage;
4+
import com.ericsson.ei.frontend.pageobjects.TestRulesPage;
5+
import org.junit.Test;
6+
import org.openqa.selenium.By;
7+
8+
import java.io.IOException;
9+
import java.util.stream.IntStream;
10+
11+
import static org.junit.Assert.assertEquals;
12+
13+
public class TestAlarm extends SeleniumBaseClass {
14+
15+
@Test
16+
public void testAlarm() throws IOException {
17+
//Load index page
18+
IndexPage indexPageObject = new IndexPage(null, driver, baseUrl);
19+
indexPageObject.loadPage();
20+
21+
//Generate exception
22+
TestRulesPage testRulesPage = indexPageObject.clickTestRulesPage();
23+
testRulesPage.clickRemoveRuleNumber(0);
24+
testRulesPage.clickRemoveEventNumber(0);
25+
26+
//Click alarm button few times
27+
IntStream.range(0, 5).forEachOrdered(i -> indexPageObject.clickAlarmButton());
28+
assertEquals(3, driver.findElements(By.className("dropdown-item")).size());
29+
}
30+
}

src/functionaltest/java/com/ericsson/ei/frontend/pageobjects/IndexPage.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public TestRulesPage clickTestRulesPage() throws IOException {
4545
waitForJQueryToLoad();
4646
return testRulesPage;
4747
}
48-
48+
4949
public SubscriptionPage clickSubscriptionPage() throws IOException {
5050
new WebDriverWait(driver, TIMEOUT_TIMER).until(ExpectedConditions.elementToBeClickable(By.id("subscriptionBtn")));
5151
WebElement subscriptionBtn = driver.findElement(By.id("subscriptionBtn"));
@@ -96,5 +96,11 @@ public void clickSwitchBackendButton() {
9696
switcherBtn.click();
9797
waitForJQueryToLoad();
9898
}
99-
}
10099

100+
public void clickAlarmButton(){
101+
new WebDriverWait(driver, TIMEOUT_TIMER).until(ExpectedConditions.elementToBeClickable(By.id("alertsDropdown")));
102+
WebElement alarmBtn = driver.findElement(By.id("alertsDropdown"));
103+
alarmBtn.click();
104+
waitForJQueryToLoad();
105+
}
106+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.dropdown-menu {
2+
max-height: 400px;
3+
overflow-y: auto;
4+
margin-left: -50px;
5+
}

src/main/resources/static/js/add-instances.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function instanceModel() {
2525
contentType: 'application/json; charset=utf-8',
2626
cache: false,
2727
error: function (XMLHttpRequest, textStatus, errorThrown) {
28-
$.jGrowl(XMLHttpRequest.responseText, {sticky: false, theme: 'Error'});
28+
window.logMessages(XMLHttpRequest.responseText);
2929
},
3030
success: function (responseData, XMLHttpRequest, textStatus) {
3131
$.jGrowl("Added new backend instance", {sticky: false, theme: 'Notify'});

src/main/resources/static/js/eiInfo.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ jQuery(document).ready(function() {
137137
contentType : 'application/json;charset=UTF-8',
138138
type: 'GET',
139139
error : function (XMLHttpRequest, textStatus, errorThrown) {
140+
window.logMessages(XMLHttpRequest.responseText);
140141
if (XMLHttpRequest.responseText == "") {
141142
document.getElementById("eiPageFrame").innerHTML = "<h3 style=\"text-align: center;\">There is no response from backend</h3>";
142143
} else {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
var errorsStore = new Array();
2+
let msg = JSON.parse(sessionStorage.getItem('errorsStore'));
3+
if(msg){
4+
for(var i=0; i<msg.length; i++){
5+
errorsStore.push(msg[i]);
6+
}
7+
}
8+
function viewModel(message){
9+
this.message = ko.observable(message);
10+
}
11+
function model(data){
12+
var self = this;
13+
self.errorMessages = ko.observableArray([]);
14+
var json = JSON.parse(ko.toJSON(data));
15+
json.reverse();
16+
for(var i = 0; i < json.length; i++) {
17+
var obj = json[i];
18+
let msgErr = new viewModel(obj.message);
19+
self.errorMessages.push(msgErr);
20+
}
21+
}
22+
function logMessages(messageErr){
23+
$.jGrowl(messageErr, {sticky: false, theme: 'Error'});
24+
errorsStore.push({message:messageErr});
25+
sessionStorage.setItem('errorsStore', JSON.stringify(errorsStore));
26+
$('div.dropdown-menu').replaceWith("<div id=\"alerts\" style=\"display: none;\" class=\"dropdown-menu\" aria-labelledby=\"alertsDropdown\" data-bind=\"foreach: errorMessages\">" +
27+
"<div class=\"dropdown-divider\"> </div>" +
28+
"<a class=\"dropdown-item\">" +
29+
"<div class=\"dropdown-message small\" data-bind=\"text: message, attr: {title: message}\"></div>" +
30+
"</a>" +
31+
"</div>");
32+
ko.cleanNode($("#alerts")[0]);
33+
ko.applyBindings(new model(errorsStore),$("#alerts")[0]);
34+
}
35+
$(document).mouseup(function(e){
36+
var container = $("#alerts");
37+
var bell = $("i.fa.fa-fw.fa-bell");
38+
var click = $("#alertsDropdown");
39+
var x = document.getElementById("alerts");
40+
let msg = JSON.parse(sessionStorage.getItem('errorsStore'));
41+
if (!container.is(e.target) && container.has(e.target).length === 0 && x.style.display === "block"){
42+
container.hide();
43+
} else if(msg && x.style.display === "none" && (click.is(e.target) || bell.is(e.target))){
44+
container.show();
45+
}
46+
});
47+
ko.cleanNode($("#alerts")[0]);
48+
ko.applyBindings(new model(errorsStore),$("#alerts")[0]);

src/main/resources/static/js/login.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ var frontendServiceUrl = $('#frontendServiceUrl').text();
1212
this.login = function(userState, remember) {
1313
var dataJSON = ko.toJSON(userState);
1414
if(JSON.parse(dataJSON).username == "" || JSON.parse(dataJSON).password == "") {
15-
$.jGrowl("Username and password fields cannot be empty", {
16-
sticky : false,
17-
theme : 'Error'
18-
});
15+
window.logMessages("Username and password fields cannot be empty");
1916
} else {
2017
var token = window.btoa(JSON.parse(dataJSON).username + ":" + JSON.parse(dataJSON).password);
2118
sendLoginRequest(frontendServiceUrl + "/auth/login", "GET", token);
@@ -33,7 +30,7 @@ var frontendServiceUrl = $('#frontendServiceUrl').text();
3330
request.setRequestHeader("Authorization", "Basic " + token);
3431
},
3532
error : function (request, textStatus, errorThrown) {
36-
$.jGrowl("Bad credentials", { sticky : false, theme : 'Error' });
33+
window.logMessages("Bad credentials");
3734
},
3835
success : function (responseData, textStatus) {
3936
var currentUser = JSON.parse(ko.toJSON(responseData)).user;

src/main/resources/static/js/main.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ jQuery(document).ready(function() {
7474
$("#userName").text("Guest");
7575
$("#loginBlock").show();
7676
$("#logoutBlock").hide();
77+
localStorage.setItem('errorsStore', []);
7778
}
7879

7980
function loadDocumentLinks(){
@@ -135,7 +136,7 @@ jQuery(document).ready(function() {
135136
contentType: 'application/json; charset=utf-8',
136137
cache: false,
137138
error: function (XMLHttpRequest, textStatus, errorThrown) {
138-
$.jGrowl(XMLHttpRequest.responseText, {sticky: false, theme: 'Error'});
139+
window.logMessages(XMLHttpRequest.responseText);
139140
},
140141
success: function (responseData, XMLHttpRequest, textStatus) {
141142
$.jGrowl(XMLHttpRequest.responseText, {sticky: false, theme: 'Notify'});
@@ -152,10 +153,12 @@ jQuery(document).ready(function() {
152153
contentType: 'application/json; charset=utf-8',
153154
cache: false,
154155
error: function (XMLHttpRequest, textStatus, errorThrown) {
155-
$.jGrowl("Failure when trying to load backend instances", {sticky: false, theme: 'Error'});
156+
window.logMessages("Failure when trying to load backend instances");
156157
},
157158
success: function (responseData, XMLHttpRequest, textStatus) {
158-
ko.applyBindings(new viewModel(responseData));
159+
var observableObject = $("#selectInstances")[0];
160+
ko.cleanNode(observableObject);
161+
ko.applyBindings(new viewModel(responseData),observableObject);
159162
}
160163
});
161164
});

src/main/resources/static/js/subscription.js

Lines changed: 20 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jQuery(document).ready(function() {
2929
},
3030
error : function (XMLHttpRequest, textStatus, errorThrown) {
3131
callback.error(XMLHttpRequest, textStatus, errorThrown);
32+
window.logMessages(XMLHttpRequest.responseText);
3233
},
3334
success : function (data, textStatus) {
3435
callback.success(data, textStatus);
@@ -86,6 +87,7 @@ jQuery(document).ready(function() {
8687
$("#loginBlock").show();
8788
$("#logoutBlock").hide();
8889
$(".show_if_authorized").hide();
90+
localStorage.setItem('errorsStore', []);
8991
}
9092

9193
// Check if EI Backend Server is online every X seconds
@@ -454,6 +456,7 @@ jQuery(document).ready(function() {
454456
reload_table();
455457
},
456458
error : function (XMLHttpRequest, textStatus, errorThrown) {
459+
window.logMessages(XMLHttpRequest.responseText);
457460
reload_table();
458461
var responseJSON = JSON.parse(XMLHttpRequest.responseText);
459462
for (var i = 0; i < responseJSON.length; i++) {
@@ -512,6 +515,7 @@ jQuery(document).ready(function() {
512515
try {
513516
jsonLintResult = jsonlint.parse(fileContent);
514517
} catch (e) {
518+
window.logMessages("JSON Format Check Failed:\n" + e.name + "\n" + e.message);
515519
$.alert("JSON Format Check Failed:\n" + e.name + "\n" + e.message);
516520
return false;
517521
}
@@ -547,8 +551,8 @@ jQuery(document).ready(function() {
547551
}
548552
},
549553
error : function (XMLHttpRequest, textStatus, errorThrown) {
554+
window.logMessages("Failed to create next Subscriptions");
550555
reload_table();
551-
$.jGrowl("Failed to create next Subscriptions", {sticky: false, theme: 'Error'});
552556
var responseJSON = JSON.parse(XMLHttpRequest.responseText);
553557
for (var i = 0; i < responseJSON.length; i++) {
554558
$.jGrowl(responseJSON[i].subscription + " :: " + responseJSON[i].reason, {sticky: true, theme: 'Error'});
@@ -635,10 +639,7 @@ jQuery(document).ready(function() {
635639
populate_json(data, mode);
636640
},
637641
error : function (XMLHttpRequest, textStatus, errorThrown) {
638-
$.jGrowl("Error: " + XMLHttpRequest.responseText, {
639-
sticky : true,
640-
theme : 'Error'
641-
});
642+
window.logMessages("Error: " + XMLHttpRequest.responseText);
642643
},
643644
complete : function () {}
644645
};
@@ -730,50 +731,32 @@ jQuery(document).ready(function() {
730731

731732
//START: Make sure all datatables field has a value
732733
if (!(/[a-z]|[A-Z]|[0-9]|[\_]/.test(String(vm.subscription()[0].subscriptionName()).slice(-1)))) {
733-
$.jGrowl("Only numbers,letters and underscore is valid to type in subscriptionName field.", {
734-
sticky : false,
735-
theme : 'Error'
736-
});
734+
window.logMessages("Only numbers,letters and underscore is valid to type in subscriptionName field.");
737735
return;
738736
}
739737

740738
//Currently a free-form field
741739
/*
742740
if (!(/[a-z]|[A-Z]|[0-9]|[\:\/\.]/.test(String(vm.subscription()[0].notificationMeta()).slice(-1)))) {
743-
$.jGrowl("Only numbers and letters is valid to type in notificationMeta field.", {
744-
sticky : false,
745-
theme : 'Error'
746-
});
741+
window.logMessages("Only numbers and letters is valid to type in notificationMeta field.");
747742
return;
748743
}
749744
*/
750745

751746
if (vm.subscription()[0].subscriptionName() == "") {
752-
$.jGrowl("Error: SubscriptionName field must have a value", {
753-
sticky : true,
754-
theme : 'Error'
755-
});
747+
window.logMessages("Error: SubscriptionName field must have a value");
756748
return;
757749
}
758750
if (vm.subscription()[0].notificationType() == null) {
759-
$.jGrowl("Error: notificationType field must boolean a value", {
760-
sticky : true,
761-
theme : 'Error'
762-
});
751+
window.logMessages("Error: notificationType field must boolean a value");
763752
return;
764753
}
765754
if (vm.subscription()[0].notificationMeta() == "") {
766-
$.jGrowl("Error: notificationMeta field must have a value", {
767-
sticky : true,
768-
theme : 'Error'
769-
});
755+
window.logMessages("Error: notificationMeta field must have a value");
770756
return;
771757
}
772758
if (vm.subscription()[0].repeat() == null) {
773-
$.jGrowl("Error: repeat field must have a boolean value", {
774-
sticky : true,
775-
theme : 'Error'
776-
});
759+
window.logMessages("Error: repeat field must have a boolean value");
777760
return;
778761
}
779762
//END OF: Make sure all datatables field has a value
@@ -785,35 +768,21 @@ jQuery(document).ready(function() {
785768
var test_value = ko.toJSON(notificationMessageKeyValuesArray[i].formvalue());
786769
if(vm.formpostkeyvaluepairs()){
787770
if(test_key.replace(/\s/g, "") === '""' || test_value.replace(/\s/g, "") === '""'){
788-
$.jGrowl("Error: Value & Key in notificationMessage must have a values!", {
789-
sticky: true,
790-
theme: 'Error'
791-
});
771+
window.logMessages("Error: Value & Key in notificationMessage must have a values!");
792772
return;
793773
}
794774
}
795-
else
796-
{
797-
if(notificationMessageKeyValuesArray.length !== 1)
798-
{
799-
$.jGrowl("Error: Only one array is allowed for notificationMessage when NOT using key/value pairs!", {
800-
sticky: true,
801-
theme: 'Error'
802-
});
775+
else{
776+
if(notificationMessageKeyValuesArray.length !== 1){
777+
window.logMessages("Error: Only one array is allowed for notificationMessage when NOT using key/value pairs!");
803778
return;
804779
}
805780
else if(test_key !== '""'){
806-
$.jGrowl("Error: Key in notificationMessage must be empty when NOT using key/value pairs!", {
807-
sticky: true,
808-
theme: 'Error'
809-
});
781+
window.logMessages("Error: Key in notificationMessage must be empty when NOT using key/value pairs!");
810782
return;
811783
}
812784
else if(test_value.replace(/\s/g, "") === '""'){
813-
$.jGrowl("Error: Value in notificationMessage must have a value when NOT using key/value pairs!", {
814-
sticky: true,
815-
theme: 'Error'
816-
});
785+
window.logMessages("Error: Value in notificationMessage must have a value when NOT using key/value pairs!");
817786
return;
818787
}
819788
}
@@ -826,10 +795,7 @@ jQuery(document).ready(function() {
826795
for (k=0; k < conditionsArray.length; k++) {
827796
var test_me = ko.toJSON(conditionsArray[k].jmespath());
828797
if (test_me === '""') {
829-
$.jGrowl("Error: jmepath field must have a value", {
830-
sticky: true,
831-
theme: 'Error'
832-
});
798+
window.logMessages("Error: jmepath field must have a value");
833799
return;
834800
}
835801
}
@@ -911,10 +877,7 @@ jQuery(document).ready(function() {
911877

912878
},
913879
error : function (XMLHttpRequest, textStatus, errorThrown) {
914-
$.jGrowl("Error: " + XMLHttpRequest.responseText, {
915-
sticky : true,
916-
theme : 'Error'
917-
});
880+
window.logMessages("Error: " + XMLHttpRequest.responseText);
918881
},
919882
complete : function () {
920883
}
@@ -935,9 +898,5 @@ jQuery(document).ready(function() {
935898
});
936899
});
937900
// /Stop ## Delete Subscription #########################################
938-
939-
940-
941-
942901
}); // $(document).ready(function() {
943902

src/main/resources/static/js/switch-instances.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function multipleInstancesModel(data) {
3333
contentType: 'application/json; charset=utf-8',
3434
cache: false,
3535
error: function (XMLHttpRequest, textStatus, errorThrown) {
36-
$.jGrowl(XMLHttpRequest.responseText, {sticky: false, theme: 'Error'});
36+
window.logMessages(XMLHttpRequest.responseText);
3737
},
3838
success: function (responseData, XMLHttpRequest, textStatus) {
3939
$.jGrowl("Backend instance was deleted", {sticky: false, theme: 'Notify'});
@@ -59,7 +59,7 @@ function multipleInstancesModel(data) {
5959
contentType: 'application/json; charset=utf-8',
6060
cache: false,
6161
error: function (XMLHttpRequest, textStatus, errorThrown) {
62-
$.jGrowl(XMLHttpRequest.responseText, {sticky: false, theme: 'Error'});
62+
window.logMessages(XMLHttpRequest.responseText);
6363
},
6464
success: function (responseData, XMLHttpRequest, textStatus) {
6565
$(location).attr('href', frontendServiceUrl)
@@ -73,7 +73,7 @@ $.ajax({
7373
contentType: 'application/json; charset=utf-8',
7474
cache: false,
7575
error: function (XMLHttpRequest, textStatus, errorThrown) {
76-
$.jGrowl("Failure when trying to load backend instances", {sticky: false, theme: 'Error'});
76+
window.logMessages("Failure when trying to load backend instances");
7777
},
7878
success: function (responseData, XMLHttpRequest, textStatus) {
7979
var observableObject = $("#instancesModel")[0];

0 commit comments

Comments
 (0)