metron-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sard...@apache.org
Subject [metron] branch master updated: METRON-1944 Unable to Delete a Comment in Alerts UI (ruffle1986 via sardell) closes apache/metron#1307
Date Mon, 25 Feb 2019 09:41:39 GMT
This is an automated email from the ASF dual-hosted git repository.

sardell pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/metron.git


The following commit(s) were added to refs/heads/master by this push:
     new 792e796  METRON-1944 Unable to Delete a Comment in Alerts UI (ruffle1986 via sardell)
closes apache/metron#1307
792e796 is described below

commit 792e7962f32b8154cd501edb65fa3fb5819758dc
Author: ruffle1986 <ftamas.mail@gmail.com>
AuthorDate: Mon Feb 25 10:40:55 2019 +0100

    METRON-1944 Unable to Delete a Comment in Alerts UI (ruffle1986 via sardell) closes apache/metron#1307
---
 .../alert-details/alert-details.component.html     |  24 ++++-
 .../alert-details/alert-details.component.spec.ts  | 108 +++++++++++++++++++++
 .../alert-details/alert-details.component.ts       |  12 +--
 3 files changed, 133 insertions(+), 11 deletions(-)

diff --git a/metron-interface/metron-alerts/src/app/alerts/alert-details/alert-details.component.html
b/metron-interface/metron-alerts/src/app/alerts/alert-details/alert-details.component.html
index f8fdc1d..abc01ca 100644
--- a/metron-interface/metron-alerts/src/app/alerts/alert-details/alert-details.component.html
+++ b/metron-interface/metron-alerts/src/app/alerts/alert-details/alert-details.component.html
@@ -17,12 +17,22 @@
             <div class="nav-container" *ngIf="!isMetaAlert">
                 <ul class="nav flex-column">
                     <li class="nav-item">
-                        <a class="nav-link" [ngClass]="{'active': activeTab === tabs.DETAILS}"
(click)="activeTab=tabs.DETAILS">
+                        <a
+                            class="nav-link"
+                            [ngClass]="{'active': activeTab === tabs.DETAILS}"
+                            (click)="activeTab=tabs.DETAILS"
+                            data-qe-id="details"
+                        >
                             <i class="fa fa-info-circle" aria-hidden="true"></i>
                         </a>
                     </li>
                     <li class="nav-item">
-                        <a class="nav-link" [ngClass]="{'active': activeTab === tabs.COMMENTS}"
(click)="activeTab=tabs.COMMENTS">
+                        <a
+                            class="nav-link"
+                            [ngClass]="{'active': activeTab === tabs.COMMENTS}"
+                            (click)="activeTab=tabs.COMMENTS"
+                            data-qe-id="comments"
+                        >
                             <i class="fa fa-comment" aria-hidden="true"></i>
                         </a>
                     </li>
@@ -86,8 +96,14 @@
                         <button class="btn btn-mine_shaft_2" [disabled]="alertCommentStr.trim().length
=== 0" (click)="onAddComment()">ADD COMMENT</button>
                         <ng-container *ngFor="let alertCommentWrapper of alertCommentsWrapper;
let i = index">
                             <hr>
-                            <div class="comment-container">
-                                <i class="fa fa-trash-o" aria-hidden="true" (click)="onDeleteComment(i)"></i>
+                            <div class="comment-container" data-qe-id="comment">
+                                <i
+                                    class="fa fa-trash-o"
+                                    aria-hidden="true"
+                                    (click)="onDeleteComment(i)"
+                                    data-qe-id="delete-comment"
+                                >
+                                </i>
                                 <div class="comment"> {{ alertCommentWrapper.alertComment.comment
}} </div>
                                 <div class="font-italic username-timestamp"> - {{ alertCommentWrapper.alertComment.username
}} - {{alertCommentWrapper.displayTime}}</div>
                             </div>
diff --git a/metron-interface/metron-alerts/src/app/alerts/alert-details/alert-details.component.spec.ts
b/metron-interface/metron-alerts/src/app/alerts/alert-details/alert-details.component.spec.ts
new file mode 100644
index 0000000..b875613
--- /dev/null
+++ b/metron-interface/metron-alerts/src/app/alerts/alert-details/alert-details.component.spec.ts
@@ -0,0 +1,108 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import { async, ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
+
+import { AlertDetailsComponent, AlertCommentWrapper } from './alert-details.component';
+import { SharedModule } from 'app/shared/shared.module';
+import { AlertDetailsKeysPipe } from './alert-details-keys.pipe';
+import { AuthenticationService } from 'app/service/authentication.service';
+import { AlertsService } from 'app/service/alerts.service';
+import { UpdateService } from 'app/service/update.service';
+import { RouterTestingModule } from '@angular/router/testing';
+import { SearchService } from 'app/service/search.service';
+import { HttpClientTestingModule } from '@angular/common/http/testing';
+import { AppConfigService } from 'app/service/app-config.service';
+import { GlobalConfigService } from 'app/service/global-config.service';
+import { DataSource } from 'app/service/data-source';
+import { ElasticSearchLocalstorageImpl } from 'app/service/elasticsearch-localstorage-impl';
+import { DialogService } from 'app/service/dialog.service';
+import { By } from '@angular/platform-browser';
+import { AlertComment } from './alert-comment';
+import { Subject } from 'rxjs';
+import { ConfirmationType } from 'app/model/confirmation-type';
+
+describe('AlertDetailsComponent', () => {
+  let component: AlertDetailsComponent;
+  let fixture: ComponentFixture<AlertDetailsComponent>;
+
+  beforeEach(async(() => {
+    TestBed.configureTestingModule({
+      imports: [
+        SharedModule,
+        HttpClientTestingModule,
+        RouterTestingModule.withRoutes([])
+      ],
+      declarations: [ AlertDetailsComponent, AlertDetailsKeysPipe ],
+      providers: [
+        SearchService,
+        AuthenticationService,
+        AlertsService,
+        UpdateService,
+        GlobalConfigService,
+        {
+          provide: DialogService,
+          useValue: {
+            launchDialog: () => {
+              const confirmed = new Subject<ConfirmationType>();
+              setTimeout(() => {
+                confirmed.next(ConfirmationType.Confirmed);
+              });
+              return confirmed;
+            }
+          }
+        },
+        {
+          provide: AppConfigService, useValue: {
+          appConfigStatic: {},
+          getApiRoot: () => {},
+        } },
+        {
+          provide: DataSource,
+          useClass: ElasticSearchLocalstorageImpl
+        },
+      ],
+    })
+    .compileComponents();
+  }));
+
+  beforeEach(() => {
+    fixture = TestBed.createComponent(AlertDetailsComponent);
+    component = fixture.componentInstance;
+    fixture.detectChanges();
+  });
+
+  it('should delete a comment.', fakeAsync(() => {
+    expect(component).toBeTruthy();
+    component.alertCommentsWrapper = [
+      new AlertCommentWrapper(
+        new AlertComment('lorem ipsum', 'user', Date.now()),
+        (new Date()).toString()
+      )
+    ];
+    const element = fixture.debugElement.query(By.css('[data-qe-id="comments"]'));
+    element.nativeElement.click();
+    fixture.detectChanges();
+    const deleteComment = fixture.debugElement.query(By.css('[data-qe-id="delete-comment"]'));
+    deleteComment.nativeElement.click();
+    tick(500);
+    fixture.detectChanges();
+    expect(component.alertCommentsWrapper.length).toEqual(0);
+    const comments = fixture.debugElement.queryAll(By.css('[data-qe-id="comment"]'));
+    expect(comments.length).toEqual(0);
+  }));
+});
diff --git a/metron-interface/metron-alerts/src/app/alerts/alert-details/alert-details.component.ts
b/metron-interface/metron-alerts/src/app/alerts/alert-details/alert-details.component.ts
index 4c0b18b..73458a6 100644
--- a/metron-interface/metron-alerts/src/app/alerts/alert-details/alert-details.component.ts
+++ b/metron-interface/metron-alerts/src/app/alerts/alert-details/alert-details.component.ts
@@ -42,7 +42,7 @@ export enum Tabs {
   DETAILS, COMMENTS
 }
 
-class AlertCommentWrapper {
+export class AlertCommentWrapper {
   alertComment: AlertComment;
   displayTime: string;
 
@@ -255,14 +255,12 @@ export class AlertDetailsComponent implements OnInit {
         let deletedCommentWrapper = this.alertCommentsWrapper.splice(index, 1)[0];
         let commentRequest = new CommentAddRemoveRequest();
         commentRequest.guid = this.alertSource.guid;
-        commentRequest.comment = this.alertCommentsWrapper[index].alertComment.comment;
-        commentRequest.username = this.alertCommentsWrapper[index].alertComment.username;
-        commentRequest.timestamp = this.alertCommentsWrapper[index].alertComment.timestamp;
+        commentRequest.comment = deletedCommentWrapper.alertComment.comment;
+        commentRequest.username = deletedCommentWrapper.alertComment.username;
+        commentRequest.timestamp = deletedCommentWrapper.alertComment.timestamp;
         commentRequest.sensorType = this.alertSourceType;
         this.updateService.removeComment(commentRequest).subscribe(
-            () => {
-              this.alertCommentsWrapper.map(alertsWrapper => alertsWrapper.alertComment)
-            },
+            null,
             () => {
               // add the deleted comment back
               this.alertCommentsWrapper.unshift(deletedCommentWrapper);


Mime
View raw message