]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.spec.ts
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / core / navigation / navigation / navigation.component.spec.ts
index 29dc31546895bc0e254c5363f667d7f10173e052..8e1662f41925c5f6023fe2eb07031686636406b1 100644 (file)
@@ -2,11 +2,15 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
 
 import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
 import { AppModule } from '../../../app.module';
+import { PrometheusService } from '../../../shared/api/prometheus.service';
+import { Permissions } from '../../../shared/models/permissions';
+import { AuthStorageService } from '../../../shared/services/auth-storage.service';
 import { NavigationComponent } from './navigation.component';
 
 describe('NavigationComponent', () => {
   let component: NavigationComponent;
   let fixture: ComponentFixture<NavigationComponent>;
+  let ifAlertmanagerConfiguredSpy: jasmine.Spy;
 
   configureTestBed({
     imports: [AppModule],
@@ -14,12 +18,30 @@ describe('NavigationComponent', () => {
   });
 
   beforeEach(() => {
+    ifAlertmanagerConfiguredSpy = spyOn(
+      TestBed.get(PrometheusService),
+      'ifAlertmanagerConfigured'
+    ).and.stub();
     fixture = TestBed.createComponent(NavigationComponent);
     component = fixture.componentInstance;
     fixture.detectChanges();
   });
 
-  it('should create', () => {
+  it('should create and PrometheusService methods should not have been called', () => {
     expect(component).toBeTruthy();
+    expect(ifAlertmanagerConfiguredSpy).toHaveBeenCalledTimes(0);
+  });
+
+  it('PrometheusService methods should have been called', () => {
+    const authStorageServiceSpy = spyOn(
+      TestBed.get(AuthStorageService),
+      'getPermissions'
+    ).and.returnValue(new Permissions({ 'config-opt': ['read'] }));
+    TestBed.overrideProvider(AuthStorageService, { useValue: authStorageServiceSpy });
+    fixture = TestBed.createComponent(NavigationComponent);
+    component = fixture.componentInstance;
+    fixture.detectChanges();
+
+    expect(ifAlertmanagerConfiguredSpy).toHaveBeenCalledTimes(1);
   });
 });