From 7a44726645d49f3af90d7277dcd52fb69582c696 Mon Sep 17 00:00:00 2001 From: Volker Theile Date: Thu, 11 Oct 2018 15:02:39 +0200 Subject: [PATCH] mgr/dashboard: Confirmation modal doesn't close Fixes: https://tracker.ceph.com/issues/24729 Signed-off-by: Volker Theile --- .../confirmation-modal.component.html | 2 +- .../components/modal/modal.component.html | 2 +- .../components/modal/modal.component.spec.ts | 17 +++++++++++++++++ .../shared/components/modal/modal.component.ts | 15 ++++++++++++++- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/confirmation-modal/confirmation-modal.component.html b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/confirmation-modal/confirmation-modal.component.html index c710cbf6b8c..e3457f96cfe 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/confirmation-modal/confirmation-modal.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/confirmation-modal/confirmation-modal.component.html @@ -1,4 +1,4 @@ - + {{ titleText }}
+ (click)="close()"> diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/modal/modal.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/modal/modal.component.spec.ts index 56f4a146ebd..2df82edb223 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/modal/modal.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/modal/modal.component.spec.ts @@ -1,6 +1,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ModalModule } from 'ngx-bootstrap/modal'; +import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service'; import { configureTestBed } from '../../../../testing/unit-test-helper'; import { ModalComponent } from './modal.component'; @@ -23,4 +24,20 @@ describe('ModalComponent', () => { it('should create', () => { expect(component).toBeTruthy(); }); + + it('should call the hide callback function', () => { + spyOn(component.hide, 'emit'); + const nativeElement = fixture.nativeElement; + const button = nativeElement.querySelector('button'); + button.dispatchEvent(new Event('click')); + fixture.detectChanges(); + expect(component.hide.emit).toHaveBeenCalled(); + }); + + it('should hide the modal', () => { + component.modalRef = new BsModalRef(); + spyOn(component.modalRef, 'hide'); + component.close(); + expect(component.modalRef.hide).toHaveBeenCalled(); + }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/modal/modal.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/modal/modal.component.ts index 38f3b27c902..4ed3e532bb0 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/modal/modal.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/modal/modal.component.ts @@ -1,4 +1,4 @@ -import { Component, Input } from '@angular/core'; +import { Component, EventEmitter, Input, Output } from '@angular/core'; import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service'; @@ -11,5 +11,18 @@ export class ModalComponent { @Input() modalRef: BsModalRef; + /** + * Should be a function that is triggered when the modal is hidden. + */ + @Output() + hide = new EventEmitter(); + constructor() {} + + close() { + if (this.modalRef) { + this.modalRef.hide(); + } + this.hide.emit(); + } } -- 2.39.5