From: Tiago Melo Date: Wed, 1 Jul 2020 14:31:59 +0000 (+0000) Subject: mgr/dashboard: Hide password notification when expiration date is far X-Git-Tag: v16.1.0~1812^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F35874%2Fhead;p=ceph.git mgr/dashboard: Hide password notification when expiration date is far Fixes: https://tracker.ceph.com/issues/46306 Signed-off-by: Tiago Melo --- diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/pwd-expiration-notification/pwd-expiration-notification.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/pwd-expiration-notification/pwd-expiration-notification.component.spec.ts index 07c9a8a4d8ea..63f59601f501 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/pwd-expiration-notification/pwd-expiration-notification.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/pwd-expiration-notification/pwd-expiration-notification.component.spec.ts @@ -23,6 +23,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: [NgbAlertModule, HttpClientTestingModule, RouterTestingModule.withRoutes(routes)], @@ -58,42 +63,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(); }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/pwd-expiration-notification/pwd-expiration-notification.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/pwd-expiration-notification/pwd-expiration-notification.component.ts index 83e1664643bd..c713d4c7b6db 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/pwd-expiration-notification/pwd-expiration-notification.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/pwd-expiration-notification/pwd-expiration-notification.component.ts @@ -31,8 +31,9 @@ export class PwdExpirationNotificationComponent implements OnInit, OnDestroy { } else { this.alertType = 'warning'; } - this.displayNotification = true; - this.authStorageService.isPwdDisplayedSource.next(true); + this.displayNotification = + this.expirationDays <= this.pwdExpirationSettings.pwdExpirationWarning1; + this.authStorageService.isPwdDisplayedSource.next(this.displayNotification); } }); }