diff --git a/app/revalidate/route.ts b/app/revalidate/route.ts
new file mode 100644
index 0000000..4593109
--- /dev/null
+++ b/app/revalidate/route.ts
@@ -0,0 +1,6 @@
+import { revalidatePath } from "next/cache";
+
+export async function GET() {
+ revalidatePath("/", "layout")
+ return Response.json({revalidated: true})
+}
\ No newline at end of file
diff --git a/components/badge/badge.test.tsx b/components/badge/badge.test.tsx
index a2c9d2f..5b24306 100644
--- a/components/badge/badge.test.tsx
+++ b/components/badge/badge.test.tsx
@@ -1,25 +1,39 @@
-import { render } from '@/lib/test-utils'
+import { render, screen } from '@/lib/test-utils'
-import { Badge, BadgeType } from './badge'
+import { Badge } from './badge'
describe('', () => {
- const today = new Date().toString()
+
+ const today = "2024-01-26T15:00:00.000Z"
+ const yesterday = "2024-01-25T15:00:00.000Z"
+ const lastWeek = "2024-01-18T15:00:00.000Z"
+
test('renders the new badge', () => {
- const { getByText } = render()
+ const { getByText } = render()
expect(getByText('new')).toBeInTheDocument()
})
- test('renders the updated badge', () => {
- const yesterday = new Date()
- yesterday.setDate(yesterday.getDate() - 1)
+ test('renders the updated badge', () => {
const { getByText } = render(
)
expect(getByText('updated')).toBeInTheDocument()
})
+
+ test('renders the updated badge', () => {
+ render(
+
+ )
+
+ expect(screen.queryByTestId('badge')).not.toBeInTheDocument();
+ })
+
test('renders nothing', () => {
const { queryByText } = render()
expect(queryByText('new')).not.toBeInTheDocument()
diff --git a/components/sidebar-menu/sidebar-menu-item.tsx b/components/sidebar-menu/sidebar-menu-item.tsx
index 42a30b4..14555a0 100644
--- a/components/sidebar-menu/sidebar-menu-item.tsx
+++ b/components/sidebar-menu/sidebar-menu-item.tsx
@@ -13,7 +13,7 @@ export const SidebarMenuItem = ({ items }: SidebarMenuItemProps) => {
{item.name}{' '}
-
+
)
diff --git a/lib/date-utils.test.ts b/lib/date-utils.test.ts
index e90cee5..aea68af 100644
--- a/lib/date-utils.test.ts
+++ b/lib/date-utils.test.ts
@@ -1,4 +1,4 @@
-import { isThisWeekButNotToday, isToday } from './date-utils'
+import { isUpdated, isToday } from './date-utils'
describe('date-utils', () => {
describe('isToday', () => {
@@ -15,24 +15,24 @@ describe('date-utils', () => {
})
})
- describe('isThisWeekButNotToday', () => {
+ describe('isUpdated', () => {
test('returns true if date is this week but not today', () => {
const today = new Date()
const tomorrow = new Date(today)
tomorrow.setDate(today.getDate() + 1)
- expect(isThisWeekButNotToday(tomorrow)).toBe(true)
+ expect(isUpdated(tomorrow)).toBe(true)
})
test('returns false if date is not this week', () => {
const today = new Date()
const nextWeek = new Date(today)
nextWeek.setDate(today.getDate() + 7)
- expect(isThisWeekButNotToday(nextWeek)).toBe(false)
+ expect(isUpdated(nextWeek)).toBe(false)
})
- test('returns false if date is today', () => {
- const today = new Date()
- expect(isThisWeekButNotToday(today)).toBe(false)
+ test('returns true if updated date is today', () => {
+ const updatedToday = new Date()
+ expect(isUpdated(updatedToday)).toBe(true)
})
})
})
diff --git a/lib/date-utils.ts b/lib/date-utils.ts
index 5d0053f..cc75c97 100644
--- a/lib/date-utils.ts
+++ b/lib/date-utils.ts
@@ -8,14 +8,14 @@ export const isToday = (date: Date) => {
)
}
-export const isThisWeekButNotToday = (date: Date) => {
+export const isUpdated = (updatedAt: Date) => {
+ if(isToday(updatedAt)) return true
+
const today = new Date()
const isSameWeek =
- date.getDate() - today.getDate() >= -today.getDay() &&
- date.getDate() - today.getDate() <= 6 - today.getDay()
-
- const isNotToday = !isToday(date)
+ updatedAt.getDate() - today.getDate() >= -today.getDay() &&
+ updatedAt.getDate() - today.getDate() <= 6 - today.getDay()
- return isSameWeek && isNotToday
+ return isSameWeek
}
diff --git a/lib/utils.ts b/lib/utils.ts
index 2ab4345..9c98c80 100644
--- a/lib/utils.ts
+++ b/lib/utils.ts
@@ -3,7 +3,7 @@ import { twMerge } from 'tailwind-merge'
import { BadgeType } from '@/components/badge/badge'
-import { isThisWeekButNotToday, isToday } from './date-utils'
+import { isUpdated, isToday } from './date-utils'
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
@@ -14,7 +14,7 @@ export const getBadgeType = (createdAt: Date, updatedAt: Date) => {
return BadgeType.new
}
- if (isThisWeekButNotToday(updatedAt)) {
+ if (isUpdated(updatedAt)) {
return BadgeType.updated
}