-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MARP-1205 add timeperiod below publisher of a feedback comment (#208)
Co-authored-by: nntthuy-axonivy <[email protected]>
- Loading branch information
1 parent
c65c39c
commit d598a43
Showing
13 changed files
with
334 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export enum TimeAgo { | ||
YEAR_AGO = 'common.timeAgo.yearAgo', | ||
YEARS_AGO = 'common.timeAgo.yearsAgo', | ||
MONTH_AGO = 'common.timeAgo.monthAgo', | ||
MONTHS_AGO = 'common.timeAgo.monthsAgo', | ||
WEEK_AGO = 'common.timeAgo.weekAgo', | ||
WEEKS_AGO = 'common.timeAgo.weeksAgo', | ||
DAY_AGO = 'common.timeAgo.dayAgo', | ||
DAYS_AGO = 'common.timeAgo.daysAgo', | ||
HOUR_AGO = 'common.timeAgo.hourAgo', | ||
HOURS_AGO = 'common.timeAgo.hoursAgo', | ||
MINUTE_AGO = 'common.timeAgo.minuteAgo', | ||
MINUTES_AGO = 'common.timeAgo.minutesAgo', | ||
SECOND_AGO = 'common.timeAgo.secondAgo', | ||
SECONDS_AGO = 'common.timeAgo.secondsAgo', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
marketplace-ui/src/app/shared/pipes/time-ago.pipe.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { | ||
MissingTranslationHandler, | ||
TranslateLoader, | ||
TranslateModule, | ||
TranslateService | ||
} from '@ngx-translate/core'; | ||
import { Language } from '../enums/language.enum'; | ||
import { TimeAgo } from '../enums/time-ago.enum'; | ||
import { TimeAgoPipe } from './time-ago.pipe'; | ||
import { httpLoaderFactory } from '../../core/configs/translate.config'; | ||
|
||
describe('TimeAgoPipe', () => { | ||
let pipe: TimeAgoPipe; | ||
let translateService: TranslateService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
TranslateModule.forRoot({ | ||
loader: { | ||
provide: TranslateLoader, | ||
useFactory: httpLoaderFactory | ||
}, | ||
missingTranslationHandler: { | ||
provide: MissingTranslationHandler, | ||
useValue: { handle: () => 'Translation missing' } | ||
} | ||
}) | ||
], | ||
providers: [TimeAgoPipe] | ||
}); | ||
|
||
translateService = TestBed.inject(TranslateService); | ||
pipe = TestBed.inject(TimeAgoPipe); | ||
}); | ||
|
||
it('should render the text 1 year ago', () => { | ||
const oneYearAgo = new Date(); | ||
oneYearAgo.setFullYear(new Date().getFullYear() - 1); | ||
expect(pipe.getTimeAgoValue(oneYearAgo)).toBe( | ||
translateService.instant(TimeAgo.YEAR_AGO) | ||
); | ||
}); | ||
|
||
it('should render the text 2 years ago', () => { | ||
const twoYearsAgo = new Date(); | ||
twoYearsAgo.setFullYear(new Date().getFullYear() - 2); | ||
expect(pipe.getTimeAgoValue(twoYearsAgo)).toBe( | ||
translateService.instant(TimeAgo.YEARS_AGO, { number: 2 }) | ||
); | ||
}); | ||
|
||
it('should render the text 1 month ago', () => { | ||
const oneMonthAgo = new Date(); | ||
oneMonthAgo.setMonth(new Date().getMonth() - 1); | ||
expect(pipe.getTimeAgoValue(oneMonthAgo)).toBe( | ||
translateService.instant(TimeAgo.MONTH_AGO) | ||
); | ||
}); | ||
|
||
it('should render the text 2 months ago', () => { | ||
const twoMonthsAgo = new Date(); | ||
twoMonthsAgo.setMonth(new Date().getMonth() - 2); | ||
expect(pipe.getTimeAgoValue(twoMonthsAgo)).toBe( | ||
translateService.instant(TimeAgo.MONTHS_AGO, { number: 2 }) | ||
); | ||
}); | ||
|
||
it('should render the text 1 week ago', () => { | ||
const oneWeekAgo = new Date(); | ||
oneWeekAgo.setDate(new Date().getDate() - 7); | ||
expect(pipe.getTimeAgoValue(oneWeekAgo)).toBe( | ||
translateService.instant(TimeAgo.WEEK_AGO) | ||
); | ||
}); | ||
|
||
it('should render the text 2 weeks ago', () => { | ||
const twoWeeksAgo = new Date(); | ||
twoWeeksAgo.setDate(new Date().getDate() - 14); | ||
expect(pipe.getTimeAgoValue(twoWeeksAgo)).toBe( | ||
translateService.instant(TimeAgo.WEEKS_AGO, { number: 2 }) | ||
); | ||
}); | ||
|
||
it('should render the text 1 day ago', () => { | ||
const oneDayAgo = new Date(); | ||
oneDayAgo.setDate(new Date().getDate() - 1); | ||
expect(pipe.getTimeAgoValue(oneDayAgo)).toBe( | ||
translateService.instant(TimeAgo.DAY_AGO) | ||
); | ||
}); | ||
|
||
it('should render the text 2 days ago', () => { | ||
const twoDaysAgo = new Date(); | ||
twoDaysAgo.setDate(new Date().getDate() - 2); | ||
expect(pipe.getTimeAgoValue(twoDaysAgo)).toBe( | ||
translateService.instant(TimeAgo.DAYS_AGO, { number: 2 }) | ||
); | ||
}); | ||
|
||
it('should render the text 1 hour ago', () => { | ||
const oneHourAgo = new Date(); | ||
oneHourAgo.setHours(new Date().getHours() - 1); | ||
expect(pipe.getTimeAgoValue(oneHourAgo)).toBe( | ||
translateService.instant(TimeAgo.HOUR_AGO) | ||
); | ||
}); | ||
|
||
it('should render the text 2 hours ago', () => { | ||
const twoHoursAgo = new Date(); | ||
twoHoursAgo.setHours(new Date().getHours() - 2); | ||
expect(pipe.getTimeAgoValue(twoHoursAgo)).toBe( | ||
translateService.instant(TimeAgo.HOURS_AGO, { number: 2 }) | ||
); | ||
}); | ||
|
||
it('should render the text 1 minute ago', () => { | ||
const oneMinuteAgo = new Date(); | ||
oneMinuteAgo.setMinutes(new Date().getMinutes() - 1); | ||
expect(pipe.getTimeAgoValue(oneMinuteAgo)).toBe( | ||
translateService.instant(TimeAgo.MINUTE_AGO) | ||
); | ||
}); | ||
|
||
it('should render the text 2 minutes ago', () => { | ||
const twoMinutesAgo = new Date(); | ||
twoMinutesAgo.setMinutes(new Date().getMinutes() - 2); | ||
expect(pipe.getTimeAgoValue(twoMinutesAgo)).toBe( | ||
translateService.instant(TimeAgo.MINUTES_AGO, { number: 2 }) | ||
); | ||
}); | ||
|
||
it('should render the text 1 second ago', () => { | ||
expect(pipe.getTimeAgoValue(new Date())).toBe( | ||
translateService.instant(TimeAgo.SECOND_AGO) | ||
); | ||
pipe.transform(new Date(), Language.EN).then(result => { | ||
expect(result).toBe(translateService.instant(TimeAgo.SECOND_AGO)); | ||
}); | ||
|
||
const oneSecondAgo = new Date(); | ||
oneSecondAgo.setSeconds(new Date().getSeconds() - 1); | ||
expect(pipe.getTimeAgoValue(oneSecondAgo)).toBe( | ||
translateService.instant(TimeAgo.SECOND_AGO) | ||
); | ||
}); | ||
|
||
it('should render the text 2 seconds ago', () => { | ||
const twoSecondsAgo = new Date(); | ||
twoSecondsAgo.setSeconds(new Date().getSeconds() - 2); | ||
expect(pipe.getTimeAgoValue(twoSecondsAgo)).toBe( | ||
translateService.instant(TimeAgo.SECONDS_AGO, { number: 2 }) | ||
); | ||
}); | ||
}); |
Oops, something went wrong.