From c8ea525dce023e320a873f666a7084fd7be6c871 Mon Sep 17 00:00:00 2001 From: Julian Gassner Date: Fri, 10 Jan 2025 03:18:59 +0100 Subject: [PATCH 1/4] Change submission time calculation --- src/main/webapp/app/shared/pipes/artemis-time-ago.pipe.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/webapp/app/shared/pipes/artemis-time-ago.pipe.ts b/src/main/webapp/app/shared/pipes/artemis-time-ago.pipe.ts index 2b669b1f0b57..1b0b0cadc37d 100644 --- a/src/main/webapp/app/shared/pipes/artemis-time-ago.pipe.ts +++ b/src/main/webapp/app/shared/pipes/artemis-time-ago.pipe.ts @@ -2,6 +2,7 @@ import { ChangeDetectorRef, NgZone, OnDestroy, Pipe, PipeTransform } from '@angu import dayjs from 'dayjs/esm'; import { isDate } from 'app/shared/util/utils'; import { TranslateService } from '@ngx-translate/core'; +import { ArtemisServerDateService } from 'app/shared/server-date.service'; @Pipe({ name: 'artemisTimeAgo', @@ -21,10 +22,11 @@ export class ArtemisTimeAgoPipe implements PipeTransform, OnDestroy { private cdRef: ChangeDetectorRef, private ngZone: NgZone, private translateService: TranslateService, + private serverDateService: ArtemisServerDateService, ) {} format(date: dayjs.Dayjs) { - return date.locale(this.lastLocale).from(dayjs(), this.lastOmitSuffix); + return date.locale(this.lastLocale).from(this.serverDateService.now(), this.lastOmitSuffix); } transform(value: dayjs.ConfigType, omitSuffix?: boolean, formatFn?: (m: dayjs.Dayjs) => string): string { From c3312d0fb34c8cf131b9a7845efde015ed10c5d2 Mon Sep 17 00:00:00 2001 From: Julian Gassner Date: Fri, 10 Jan 2025 03:28:20 +0100 Subject: [PATCH 2/4] Fix test --- src/test/javascript/spec/pipe/artemis-time-ago.pipe.spec.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/javascript/spec/pipe/artemis-time-ago.pipe.spec.ts b/src/test/javascript/spec/pipe/artemis-time-ago.pipe.spec.ts index 60a26821d6ea..e5af76368ef3 100644 --- a/src/test/javascript/spec/pipe/artemis-time-ago.pipe.spec.ts +++ b/src/test/javascript/spec/pipe/artemis-time-ago.pipe.spec.ts @@ -3,12 +3,14 @@ import { ArtemisTimeAgoPipe } from 'app/shared/pipes/artemis-time-ago.pipe'; import { TestBed, fakeAsync, tick } from '@angular/core/testing'; import { TranslateService } from '@ngx-translate/core'; import { ChangeDetectorRef, NgZone } from '@angular/core'; +import { ArtemisServerDateService } from 'app/shared/server-date.service'; import dayjs from 'dayjs/esm'; describe('ArtemisTimeAgoPipe', () => { let pipe: ArtemisTimeAgoPipe; let translateService: TranslateService; let cdRef: ChangeDetectorRef; + let serverTimeService: ArtemisServerDateService; beforeEach(() => { TestBed.configureTestingModule({ @@ -22,7 +24,7 @@ describe('ArtemisTimeAgoPipe', () => { translateService = TestBed.inject(TranslateService); translateService.use('en'); const ngZone = TestBed.inject(NgZone); - pipe = new ArtemisTimeAgoPipe(cdRef, ngZone, translateService); + pipe = new ArtemisTimeAgoPipe(cdRef, ngZone, translateService, serverTimeService); }); }); From db171a68f5623a841011c7e81556e438e581bfc7 Mon Sep 17 00:00:00 2001 From: Julian Gassner Date: Fri, 10 Jan 2025 03:41:13 +0100 Subject: [PATCH 3/4] Inject ArtemisServerDateService to test --- src/test/javascript/spec/pipe/artemis-time-ago.pipe.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/javascript/spec/pipe/artemis-time-ago.pipe.spec.ts b/src/test/javascript/spec/pipe/artemis-time-ago.pipe.spec.ts index e5af76368ef3..d279b9404c55 100644 --- a/src/test/javascript/spec/pipe/artemis-time-ago.pipe.spec.ts +++ b/src/test/javascript/spec/pipe/artemis-time-ago.pipe.spec.ts @@ -23,6 +23,7 @@ describe('ArtemisTimeAgoPipe', () => { translateService = TestBed.inject(TranslateService); translateService.use('en'); + serverTimeService = TestBed.inject(ArtemisServerDateService); const ngZone = TestBed.inject(NgZone); pipe = new ArtemisTimeAgoPipe(cdRef, ngZone, translateService, serverTimeService); }); From 6708a73ac9b3485839c33cc4200722884059b4eb Mon Sep 17 00:00:00 2001 From: Julian Gassner Date: Fri, 10 Jan 2025 04:29:27 +0100 Subject: [PATCH 4/4] Add mock for tests --- .../mocks/service/mock-artemis-server-date.service.ts | 7 +++++++ .../javascript/spec/pipe/artemis-time-ago.pipe.spec.ts | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/test/javascript/spec/helpers/mocks/service/mock-artemis-server-date.service.ts diff --git a/src/test/javascript/spec/helpers/mocks/service/mock-artemis-server-date.service.ts b/src/test/javascript/spec/helpers/mocks/service/mock-artemis-server-date.service.ts new file mode 100644 index 000000000000..fc222ae1d9b2 --- /dev/null +++ b/src/test/javascript/spec/helpers/mocks/service/mock-artemis-server-date.service.ts @@ -0,0 +1,7 @@ +import dayjs from 'dayjs/esm'; + +export class MockArtemisServerDateService { + now(): dayjs.Dayjs { + return dayjs(); + } +} diff --git a/src/test/javascript/spec/pipe/artemis-time-ago.pipe.spec.ts b/src/test/javascript/spec/pipe/artemis-time-ago.pipe.spec.ts index d279b9404c55..6d2f2fcbaa7d 100644 --- a/src/test/javascript/spec/pipe/artemis-time-ago.pipe.spec.ts +++ b/src/test/javascript/spec/pipe/artemis-time-ago.pipe.spec.ts @@ -5,6 +5,7 @@ import { TranslateService } from '@ngx-translate/core'; import { ChangeDetectorRef, NgZone } from '@angular/core'; import { ArtemisServerDateService } from 'app/shared/server-date.service'; import dayjs from 'dayjs/esm'; +import { MockArtemisServerDateService } from '../helpers/mocks/service/mock-artemis-server-date.service'; describe('ArtemisTimeAgoPipe', () => { let pipe: ArtemisTimeAgoPipe; @@ -15,7 +16,10 @@ describe('ArtemisTimeAgoPipe', () => { beforeEach(() => { TestBed.configureTestingModule({ declarations: [ArtemisTimeAgoPipe], - providers: [{ provide: TranslateService, useClass: MockTranslateService }], + providers: [ + { provide: TranslateService, useClass: MockTranslateService }, + { provide: ArtemisServerDateService, useClass: MockArtemisServerDateService }, + ], }) .compileComponents() .then(() => {