]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.spec.ts
import 15.2.5
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / core / navigation / navigation / navigation.component.spec.ts
index 8fa84bf65ae7dc65a65bdf77ff2b3d131925ed07..25fb4d6f7897cf7cadccb66147e51e64158d1655 100644 (file)
@@ -1,10 +1,10 @@
 import { ComponentFixture, TestBed } from '@angular/core/testing';
 import { By } from '@angular/platform-browser';
 
-import { configureTestSuite } from 'ng-bullet';
 import { MockModule } from 'ng-mocks';
 import { of } from 'rxjs';
 
+import { configureTestBed } from '../../../../testing/unit-test-helper';
 import { Permission, Permissions } from '../../../shared/models/permissions';
 import { AuthStorageService } from '../../../shared/services/auth-storage.service';
 import {
@@ -49,23 +49,22 @@ describe('NavigationComponent', () => {
   let component: NavigationComponent;
   let fixture: ComponentFixture<NavigationComponent>;
 
-  configureTestSuite(() => {
-    TestBed.configureTestingModule({
-      declarations: [NavigationComponent],
-      imports: [MockModule(NavigationModule)],
-      providers: [
-        {
-          provide: AuthStorageService,
-          useValue: {
-            getPermissions: jest.fn(),
-            isPwdDisplayed$: { subscribe: jest.fn() }
-          }
-        },
-        { provide: SummaryService, useValue: { subscribe: jest.fn() } },
-        { provide: FeatureTogglesService, useValue: { get: jest.fn() } },
-        { provide: PrometheusAlertService, useValue: { alerts: [] } }
-      ]
-    });
+  configureTestBed({
+    declarations: [NavigationComponent],
+    imports: [MockModule(NavigationModule)],
+    providers: [
+      {
+        provide: AuthStorageService,
+        useValue: {
+          getPermissions: jest.fn(),
+          isPwdDisplayed$: { subscribe: jest.fn() },
+          telemetryNotification$: { subscribe: jest.fn() }
+        }
+      },
+      { provide: SummaryService, useValue: { subscribe: jest.fn() } },
+      { provide: FeatureTogglesService, useValue: { get: jest.fn() } },
+      { provide: PrometheusAlertService, useValue: { alerts: [] } }
+    ]
   });
 
   beforeEach(() => {
@@ -182,4 +181,56 @@ describe('NavigationComponent', () => {
       });
     }
   });
+
+  describe('showTopNotification', () => {
+    const notification1 = 'notificationName1';
+    const notification2 = 'notificationName2';
+
+    beforeEach(() => {
+      component.notifications = [];
+    });
+
+    it('should show notification', () => {
+      component.showTopNotification(notification1, true);
+      expect(component.notifications.includes(notification1)).toBeTruthy();
+      expect(component.notifications.length).toBe(1);
+    });
+
+    it('should not add a second notification if it is already shown', () => {
+      component.showTopNotification(notification1, true);
+      component.showTopNotification(notification1, true);
+      expect(component.notifications.includes(notification1)).toBeTruthy();
+      expect(component.notifications.length).toBe(1);
+    });
+
+    it('should add a second notification if the first one is different', () => {
+      component.showTopNotification(notification1, true);
+      component.showTopNotification(notification2, true);
+      expect(component.notifications.includes(notification1)).toBeTruthy();
+      expect(component.notifications.includes(notification2)).toBeTruthy();
+      expect(component.notifications.length).toBe(2);
+    });
+
+    it('should hide an active notification', () => {
+      component.showTopNotification(notification1, true);
+      expect(component.notifications.includes(notification1)).toBeTruthy();
+      expect(component.notifications.length).toBe(1);
+      component.showTopNotification(notification1, false);
+      expect(component.notifications.length).toBe(0);
+    });
+
+    it('should not fail if it tries to hide an inactive notification', () => {
+      expect(() => component.showTopNotification(notification1, false)).not.toThrow();
+      expect(component.notifications.length).toBe(0);
+    });
+
+    it('should keep other notifications if it hides one', () => {
+      component.showTopNotification(notification1, true);
+      component.showTopNotification(notification2, true);
+      expect(component.notifications.length).toBe(2);
+      component.showTopNotification(notification2, false);
+      expect(component.notifications.length).toBe(1);
+      expect(component.notifications.includes(notification1)).toBeTruthy();
+    });
+  });
 });