diff --git a/src/components/Announcements/TabContent.tsx b/src/components/Announcements/TabContent.tsx index 2176b5e5..d9beeee0 100644 --- a/src/components/Announcements/TabContent.tsx +++ b/src/components/Announcements/TabContent.tsx @@ -5,23 +5,31 @@ const TabContent = ({ posts }) => { return (
{posts.map((post, index) => ( - <> - -
-

- {Math.floor((new Date().getTime() - new Date(post.node.frontmatter.date).getTime()) / (1000 * 60 * 60 * 24 * 7))} weeks ago -

+
+ +
+

+ {(() => { + const daysAgo = Math.floor((new Date().getTime() - new Date(post.node.frontmatter.date).getTime()) / (1000 * 60 * 60 * 24)); + if (daysAgo < 7) { + return daysAgo === 1 ? `1 day ago` : `${daysAgo} weeks ago`; + } else { + const weeksAgo = Math.floor(daysAgo / 7); + return weeksAgo === 1 ? `1 week ago` : `${weeksAgo} weeks ago`; + } + })()} +

-

- {post.node.frontmatter.title} -

-

- {post.node.frontmatter.description} -

-
+

+ {post.node.frontmatter.title} +

+

+ {post.node.frontmatter.description} +

+
- +
))}
) diff --git a/src/components/Announcements/__tests__/Annnouncements.test.tsx b/src/components/Announcements/__tests__/Annnouncements.test.tsx index fad38d5f..3d9bce1a 100644 --- a/src/components/Announcements/__tests__/Annnouncements.test.tsx +++ b/src/components/Announcements/__tests__/Annnouncements.test.tsx @@ -3,6 +3,41 @@ import { render } from "@testing-library/react" import { describe, expect, it, vi } from "vitest" import Announcements from ".." +const mockData = ({id, days}) => ({ + node: { + id, + frontmatter: { + title: `Test Announcement ${id}`, + date: Date.now() - 1000 * 60 * 60 * 24 * days, + description: `Description for announcement ${id}`, + tags: ["release-notes"], + }, + fields: { + postPath: `/test-announcement-${id}`, + }, + }, +}) + +vi.mock("gatsby", async () => { + const actualGatsby = await vi.importActual("gatsby") + return { + ...actualGatsby, + // This no-op function prevents the error by simply returning the query string. + graphql: (strings: TemplateStringsArray, ..._args: any[]) => strings[0], + // Provide your test data for useStaticQuery. + useStaticQuery: () => ({ + allMdx: { + edges: [ + mockData({id: 1, days: 1}), // 1 day ago + mockData({id: 2, days: 3}), // 3 days ago + mockData({id: 3, days: 7}), // 1 week ago + mockData({id: 4, days: 60}), // 8 weeks ago + ], + }, + }), + } +}) + describe("Announcements component", () => { it("Announcements renders correctly", () => { const handleCloseMock = vi.fn() diff --git a/src/components/Announcements/__tests__/__snapshots__/Annnouncements.test.tsx.snap b/src/components/Announcements/__tests__/__snapshots__/Annnouncements.test.tsx.snap index 7bcd5bd3..e0ffdbed 100644 --- a/src/components/Announcements/__tests__/__snapshots__/Annnouncements.test.tsx.snap +++ b/src/components/Announcements/__tests__/__snapshots__/Annnouncements.test.tsx.snap @@ -76,87 +76,118 @@ exports[`Announcements component > Announcements renders correctly 1`] = ` class="overflow-auto h-[88%] scroll-sidebar" >
- -
+ -

- 213 - weeks ago -

-

- Mock Title 1 -

-

- Mock Description 1 -

-
- - - -
+ 1 day ago +

+

+ Test Announcement 1 +

+

+ Description for announcement 1 +

+
+
+ + +
+ -

- 213 - weeks ago -

-

- Mock Title 2 -

-

- Mock Description 2 -

-
- - - -
+ 3 weeks ago +

+

+ Test Announcement 2 +

+

+ Description for announcement 2 +

+
+
+ + + + + + +
+ +
- Mock Description 3 -

-
-
- +

+ 8 weeks ago +

+

+ Test Announcement 4 +

+

+ Description for announcement 4 +

+
+ + +
diff --git a/src/components/Announcements/index.tsx b/src/components/Announcements/index.tsx index 261d787b..76803fba 100644 --- a/src/components/Announcements/index.tsx +++ b/src/components/Announcements/index.tsx @@ -7,25 +7,25 @@ const Announcements = ({ handleClose }) => { const data = useStaticQuery(graphql` query { allMdx(sort: {frontmatter: {date: DESC}}) { - edges { - node { - id - frontmatter { - title - date - description - tags - } - fields { - postPath + edges { + node { + id + frontmatter { + title + date + description + tags + } + fields { + postPath + } } } } } - } `) - const latest_posts = data.allMdx.edges.slice(0, 3) + const latest_posts = data.allMdx.edges.slice(0, 4) const latest_releases = data.allMdx.edges.filter( ({ node }) => node.frontmatter.tags.includes("release-notes") ) @@ -65,7 +65,7 @@ const Announcements = ({ handleClose }) => {
{active === "Updates" && } - {active === "Events" && } + {/* {active === "Events" && } */} {active === "Releases" && }