2025-02-24 21:01:55 +00:00
|
|
|
import { dateAgo, monthDayYearFormat, addedFromNow, uploadedFromNow } from ".";
|
2024-03-26 14:46:33 +00:00
|
|
|
|
2024-08-29 22:51:46 +00:00
|
|
|
describe("date_format utilities", () => {
|
2024-03-26 14:46:33 +00:00
|
|
|
describe("uploadedFromNow util", () => {
|
2025-02-24 21:01:55 +00:00
|
|
|
it("returns an user friendly uploaded message", () => {
|
2024-03-26 14:46:33 +00:00
|
|
|
const currentDate = new Date();
|
|
|
|
|
currentDate.setDate(currentDate.getDate() - 2);
|
|
|
|
|
const twoDaysAgo = currentDate.toISOString();
|
|
|
|
|
|
|
|
|
|
expect(uploadedFromNow(twoDaysAgo)).toEqual("Uploaded 2 days ago");
|
|
|
|
|
});
|
|
|
|
|
});
|
2024-08-29 22:51:46 +00:00
|
|
|
|
2025-02-24 21:01:55 +00:00
|
|
|
describe("addedFromNow util", () => {
|
|
|
|
|
it("returns an user friendly added message", () => {
|
|
|
|
|
const currentDate = new Date();
|
|
|
|
|
currentDate.setDate(currentDate.getDate() - 2);
|
|
|
|
|
const twoDaysAgo = currentDate.toISOString();
|
|
|
|
|
|
|
|
|
|
expect(addedFromNow(twoDaysAgo)).toEqual("Added 2 days ago");
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2024-08-29 22:51:46 +00:00
|
|
|
describe("monthDayYearFormat util", () => {
|
|
|
|
|
it("returns a date in the format of 'MonthName Date, Year' (e.g. January 01, 2024)", () => {
|
|
|
|
|
const date = "2024-11-29T00:00:00Z";
|
|
|
|
|
expect(monthDayYearFormat(date)).toEqual("November 29, 2024");
|
|
|
|
|
});
|
|
|
|
|
});
|
2025-01-20 10:39:46 +00:00
|
|
|
|
|
|
|
|
describe("dateAgo util", () => {
|
|
|
|
|
it("returns a user friendly date ago message from a date string", () => {
|
|
|
|
|
const currentDate = new Date();
|
|
|
|
|
currentDate.setDate(currentDate.getDate() - 2);
|
|
|
|
|
const twoDaysAgo = currentDate.toISOString();
|
|
|
|
|
|
|
|
|
|
expect(dateAgo(twoDaysAgo)).toEqual("2 days ago");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("returns a user friendly date ago message from a Date object", () => {
|
|
|
|
|
const date = new Date();
|
|
|
|
|
date.setDate(date.getDate() - 2);
|
|
|
|
|
|
|
|
|
|
expect(dateAgo(date)).toEqual("2 days ago");
|
|
|
|
|
});
|
|
|
|
|
});
|
2024-03-26 14:46:33 +00:00
|
|
|
});
|