Skip to content

Commit

Permalink
feat: apim-3748 notification banner when expire today
Browse files Browse the repository at this point in the history
  • Loading branch information
mstasgravitee authored and ThibaudAV committed Jan 26, 2024
1 parent 5ccd611 commit 2695eec
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,32 @@ describe('GioLicenseExpirationNotificationComponent', () => {
});

it('should display expiration message', async () => {
component.expirationDate = new Date();
const expirationDate = new Date();
expirationDate.setDate(expirationDate.getDate() - 1);

component.expirationDate = expirationDate;
fixture.detectChanges();

const harness = await loader.getHarness(GioLicenseExpirationNotificationHarness);
expect(await harness.getTitleText()).toEqual('Your license has expired');
});

it('should display expiration message when expires today', async () => {
const expirationDate = new Date();
expirationDate.setMinutes(expirationDate.getMinutes() + 1);

component.expirationDate = expirationDate;
fixture.detectChanges();

const harness = await loader.getHarness(GioLicenseExpirationNotificationHarness);
expect(await harness.getTitleText()).toEqual('Your license will expire today');
});

it('should display expiration message when expired today 1 minute ago', async () => {
const expirationDate = new Date();
expirationDate.setMinutes(expirationDate.getMinutes() - 1);

component.expirationDate = expirationDate;
fixture.detectChanges();

const harness = await loader.getHarness(GioLicenseExpirationNotificationHarness);
Expand Down Expand Up @@ -170,8 +195,22 @@ describe('GioLicenseExpirationNotificationComponent', () => {
expect(await harness.isColor('orange')).toEqual(true);
});

it('should be orange if expires today', async () => {
const expirationDate = new Date();
expirationDate.setMinutes(expirationDate.getMinutes() + 1);

component.expirationDate = expirationDate;
fixture.detectChanges();

const harness = await loader.getHarness(GioLicenseExpirationNotificationHarness);
expect(await harness.isColor('orange')).toEqual(true);
});

it('should be red if expired', async () => {
component.expirationDate = new Date();
const expirationDate = new Date();
expirationDate.setDate(expirationDate.getDate() - 1);

component.expirationDate = expirationDate;
fixture.detectChanges();

const harness = await loader.getHarness(GioLicenseExpirationNotificationHarness);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,16 @@ export class GioLicenseExpirationNotificationComponent implements OnInit, OnChan
return;
}

const timeRemaining = this.transformDateWithoutHours(this.expirationDate) - this.transformDateWithoutHours(new Date());
const date = new Date();
const timeRemaining = this.transformDateWithoutHours(this.expirationDate) - this.transformDateWithoutHours(date);
this.daysRemaining = timeRemaining / (1000 * 3600 * 24);

if (this.daysRemaining <= 0) {
if (this.expirationDate.getTime() - date.getTime() < 0) {
this.title = 'Your license has expired';
this.statusColor = 'red';
} else if (this.daysRemaining === 0) {
this.title = `Your license will expire today`;
this.statusColor = 'orange';
} else {
this.title = `Your license will expire in ${this.daysRemaining} day${this.daysRemaining === 1 ? '' : 's'}`;
this.statusColor = this.daysRemaining > 5 ? 'blue' : 'orange';
Expand Down

0 comments on commit 2695eec

Please sign in to comment.