Hey is a decentralized and permissionless social media app built with Lens Protocol 🌿

test: add cases for formatRelativeOrAbsolute (#5982)

authored by yoginth.com and committed by

GitHub efc1e81f 3e9a638f

+46 -5
+1 -5
apps/web/src/components/Composer/Actions/CollectSettings/CollectForm.tsx
··· 7 7 import { Button } from "@/components/Shared/UI"; 8 8 import { useCollectActionStore } from "@/store/non-persisted/post/useCollectActionStore"; 9 9 import { usePostLicenseStore } from "@/store/non-persisted/post/usePostLicenseStore"; 10 - import { useAccountStore } from "@/store/persisted/useAccountStore"; 11 10 import { EXPANSION_EASE } from "@/variants"; 12 11 import AmountConfig from "./AmountConfig"; 13 12 import CollectLimitConfig from "./CollectLimitConfig"; ··· 20 19 } 21 20 22 21 const CollectForm = ({ setShowModal }: CollectFormProps) => { 23 - const { currentAccount } = useAccountStore(); 24 22 const { collectAction, setCollectAction, reset } = useCollectActionStore(); 25 23 const { setLicense } = usePostLicenseStore(); 26 24 ··· 84 82 <AmountConfig setCollectType={setCollectType} /> 85 83 {collectAction.payToCollect?.erc20?.value && ( 86 84 <SplitConfig 87 - isRecipientsDuplicated={ 88 - validationChecks.isRecipientsDuplicated 89 - } 85 + isRecipientsDuplicated={validationChecks.isRecipientsDuplicated} 90 86 setCollectType={setCollectType} 91 87 /> 92 88 )}
+45
apps/web/src/helpers/datetime/formatRelativeOrAbsolute.test.ts
··· 1 + import { afterAll, beforeAll, describe, expect, it, vi } from "vitest"; 2 + import formatRelativeOrAbsolute from "./formatRelativeOrAbsolute"; 3 + 4 + describe("formatRelativeOrAbsolute", () => { 5 + const now = new Date("2024-05-15T12:00:00Z"); 6 + 7 + beforeAll(() => { 8 + vi.useFakeTimers(); 9 + vi.setSystemTime(now); 10 + }); 11 + 12 + afterAll(() => { 13 + vi.useRealTimers(); 14 + }); 15 + 16 + it("formats seconds ago", () => { 17 + const date = new Date(now.getTime() - 30 * 1000); 18 + expect(formatRelativeOrAbsolute(date)).toBe("30s"); 19 + }); 20 + 21 + it("formats minutes ago", () => { 22 + const date = new Date(now.getTime() - 3 * 60 * 1000); 23 + expect(formatRelativeOrAbsolute(date)).toBe("3m"); 24 + }); 25 + 26 + it("formats hours ago", () => { 27 + const date = new Date(now.getTime() - 2 * 60 * 60 * 1000); 28 + expect(formatRelativeOrAbsolute(date)).toBe("2h"); 29 + }); 30 + 31 + it("formats days ago within a week", () => { 32 + const date = new Date(now.getTime() - 5 * 24 * 60 * 60 * 1000); 33 + expect(formatRelativeOrAbsolute(date)).toBe("5d"); 34 + }); 35 + 36 + it("formats more than a week in same year", () => { 37 + const date = new Date(now.getTime() - 14 * 24 * 60 * 60 * 1000); 38 + expect(formatRelativeOrAbsolute(date)).toBe("May 1"); 39 + }); 40 + 41 + it("formats dates from previous year", () => { 42 + const date = new Date("2023-12-20T12:00:00Z"); 43 + expect(formatRelativeOrAbsolute(date)).toBe("Dec 20, 2023"); 44 + }); 45 + });