Feat/filter activity inbox (#1032)
* Move files * Add filtering for tasks inbox * Add filter dropdown for single entity * Minor * Fill empty button * Refine logic for filter dropdown * remove log * Fix unwanted change * Set current user as default filter * Add avatar on filter * Improve initialization of assignee filter * Add story for Tasks page * Add more stories * Add sotry with no tasks * Improve dates * Enh tests --------- Co-authored-by: Charles Bochet <charlesBochet@users.noreply.github.com>
This commit is contained in:
@ -3,6 +3,7 @@ import { DateTime } from 'luxon';
|
||||
|
||||
import {
|
||||
beautifyExactDate,
|
||||
beautifyExactDateTime,
|
||||
beautifyPastDateAbsolute,
|
||||
beautifyPastDateRelativeToNow,
|
||||
DEFAULT_DATE_LOCALE,
|
||||
@ -12,14 +13,46 @@ import { logError } from '../logError';
|
||||
|
||||
jest.mock('~/utils/logError');
|
||||
|
||||
describe('beautifyExactDate', () => {
|
||||
it('should return the correct relative date', () => {
|
||||
describe('beautifyExactDateTime', () => {
|
||||
it('should return the date in the correct format with time', () => {
|
||||
const mockDate = '2023-01-01T12:13:24';
|
||||
const actualDate = new Date(mockDate);
|
||||
const expected = DateTime.fromJSDate(actualDate)
|
||||
.setLocale(DEFAULT_DATE_LOCALE)
|
||||
.toFormat('DD · T');
|
||||
|
||||
const result = beautifyExactDateTime(mockDate);
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
it('should return the time in the correct format for a datetime that is today', () => {
|
||||
const todayString = DateTime.local().toISODate();
|
||||
const mockDate = `${todayString}T12:13:24`;
|
||||
const actualDate = new Date(mockDate);
|
||||
const expected = DateTime.fromJSDate(actualDate)
|
||||
.setLocale(DEFAULT_DATE_LOCALE)
|
||||
.toFormat('T');
|
||||
|
||||
const result = beautifyExactDateTime(mockDate);
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('beautifyExactDate', () => {
|
||||
it('should return the past date in the correct format without time', () => {
|
||||
const mockDate = '2023-01-01T12:13:24';
|
||||
const actualDate = new Date(mockDate);
|
||||
const expected = DateTime.fromJSDate(actualDate)
|
||||
.setLocale(DEFAULT_DATE_LOCALE)
|
||||
.toFormat('DD');
|
||||
|
||||
const result = beautifyExactDate(mockDate);
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
it('should return "Today" if the date is today', () => {
|
||||
const todayString = DateTime.local().toISODate();
|
||||
const mockDate = `${todayString}T12:13:24`;
|
||||
const expected = 'Today';
|
||||
|
||||
const result = beautifyExactDate(mockDate);
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
@ -29,17 +29,32 @@ export function parseDate(dateToParse: Date | string | number) {
|
||||
return formattedDate.setLocale(DEFAULT_DATE_LOCALE);
|
||||
}
|
||||
|
||||
export function beautifyExactDate(dateToBeautify: Date | string | number) {
|
||||
try {
|
||||
const parsedDate = parseDate(dateToBeautify);
|
||||
function isSameDay(a: DateTime, b: DateTime): boolean {
|
||||
return a.hasSame(b, 'day') && a.hasSame(b, 'month') && a.hasSame(b, 'year');
|
||||
}
|
||||
|
||||
return parsedDate.toFormat('DD · T');
|
||||
function formatDate(dateToFormat: Date | string | number, format: string) {
|
||||
try {
|
||||
const parsedDate = parseDate(dateToFormat);
|
||||
return parsedDate.toFormat(format);
|
||||
} catch (error) {
|
||||
logError(error);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
export function beautifyExactDateTime(dateToBeautify: Date | string | number) {
|
||||
const isToday = isSameDay(parseDate(dateToBeautify), DateTime.local());
|
||||
const dateFormat = isToday ? 'T' : 'DD · T';
|
||||
return formatDate(dateToBeautify, dateFormat);
|
||||
}
|
||||
|
||||
export function beautifyExactDate(dateToBeautify: Date | string | number) {
|
||||
const isToday = isSameDay(parseDate(dateToBeautify), DateTime.local());
|
||||
const dateFormat = isToday ? "'Today'" : 'DD';
|
||||
return formatDate(dateToBeautify, dateFormat);
|
||||
}
|
||||
|
||||
export function beautifyPastDateRelativeToNow(
|
||||
pastDate: Date | string | number,
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user