]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/components/pwd-expiration-notification/pwd-expiration-notification.component.spec.ts
import 15.2.5
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / components / pwd-expiration-notification / pwd-expiration-notification.component.spec.ts
index 3273a4e84f23d05ac36b39749c829f0bbc6a83a5..7ebd64075eb2638f947bf237ce047d2dd64f4cd2 100644 (file)
@@ -25,6 +25,11 @@ describe('PwdExpirationNotificationComponent', () => {
 
   const routes: Routes = [{ path: 'login', component: FakeComponent }];
 
+  const spyOnDate = (fakeDate: string) => {
+    const dateValue = Date;
+    spyOn(global, 'Date').and.callFake((date) => new dateValue(date ? date : fakeDate));
+  };
+
   configureTestBed({
     declarations: [PwdExpirationNotificationComponent, FakeComponent],
     imports: [
@@ -64,42 +69,29 @@ describe('PwdExpirationNotificationComponent', () => {
     });
 
     it('should calculate password expiration in days', () => {
-      const dateValue = Date;
-      spyOn(global, 'Date').and.callFake((date) => {
-        if (date) {
-          return new dateValue(date);
-        } else {
-          return new Date('2022-02-18T00:00:00.000Z');
-        }
-      });
+      spyOnDate('2022-02-18T00:00:00.000Z');
       component.ngOnInit();
       expect(component['expirationDays']).toBe(4);
     });
 
     it('should set alert type warning correctly', () => {
-      const dateValue = Date;
-      spyOn(global, 'Date').and.callFake((date) => {
-        if (date) {
-          return new dateValue(date);
-        } else {
-          return new Date('2022-02-14T00:00:00.000Z');
-        }
-      });
+      spyOnDate('2022-02-14T00:00:00.000Z');
       component.ngOnInit();
       expect(component['alertType']).toBe('warning');
+      expect(component.displayNotification).toBeTruthy();
     });
 
     it('should set alert type danger correctly', () => {
-      const dateValue = Date;
-      spyOn(global, 'Date').and.callFake((date) => {
-        if (date) {
-          return new dateValue(date);
-        } else {
-          return new Date('2022-02-18T00:00:00.000Z');
-        }
-      });
+      spyOnDate('2022-02-18T00:00:00.000Z');
       component.ngOnInit();
       expect(component['alertType']).toBe('danger');
+      expect(component.displayNotification).toBeTruthy();
+    });
+
+    it('should not display if date is far', () => {
+      spyOnDate('2022-01-01T00:00:00.000Z');
+      component.ngOnInit();
+      expect(component.displayNotification).toBeFalsy();
     });
   });