]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/components/modal/modal.component.spec.ts
import ceph 16.2.7
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / components / modal / modal.component.spec.ts
index d3ee1ca2abd19feb7f58f5ef52dff2a2b9f61352..cf08bef10090d7713f8740131dd256a7711b64e0 100644 (file)
@@ -1,4 +1,6 @@
 import { ComponentFixture, TestBed } from '@angular/core/testing';
+import { Router } from '@angular/router';
+import { RouterTestingModule } from '@angular/router/testing';
 
 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
 
@@ -8,14 +10,18 @@ import { ModalComponent } from './modal.component';
 describe('ModalComponent', () => {
   let component: ModalComponent;
   let fixture: ComponentFixture<ModalComponent>;
+  let routerNavigateSpy: jasmine.Spy;
 
   configureTestBed({
-    declarations: [ModalComponent]
+    declarations: [ModalComponent],
+    imports: [RouterTestingModule]
   });
 
   beforeEach(() => {
     fixture = TestBed.createComponent(ModalComponent);
     component = fixture.componentInstance;
+    routerNavigateSpy = spyOn(TestBed.inject(Router), 'navigate');
+    routerNavigateSpy.and.returnValue(true);
     fixture.detectChanges();
   });
 
@@ -38,4 +44,11 @@ describe('ModalComponent', () => {
     component.close();
     expect(component.modalRef.close).toHaveBeenCalled();
   });
+
+  it('should hide the routed modal', () => {
+    component.pageURL = 'hosts';
+    component.close();
+    expect(routerNavigateSpy).toHaveBeenCalledTimes(1);
+    expect(routerNavigateSpy).toHaveBeenCalledWith(['hosts', { outlets: { modal: null } }]);
+  });
 });