Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sidebar #2

Merged
merged 7 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^13.0.0",
"@testing-library/user-event": "^13.2.1",
"date-fns": "^3.6.0",
"flowbite-react": "^0.9.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down
23 changes: 23 additions & 0 deletions src/__tests__/NotesCard.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from "react"
import { render, screen } from "@testing-library/react"
import { BrowserRouter } from "react-router-dom"
import NotesCard from "../components/NotesCard"

test("renders the NotesCard component", () => {
const note = {
id: 1,
title: "Wary message for Rhea Pollster",
creator: 1,
created_at: "May 10, 2024"
}
render(
<BrowserRouter>
<NotesCard key={note.id} note={note} />
</BrowserRouter>
)
const notesCardTitle = screen.getByText(note.title)
expect(notesCardTitle).toBeInTheDocument()

const notesCardDate = screen.getByText(note.created_at)
expect(notesCardDate).toBeInTheDocument()
})
14 changes: 14 additions & 0 deletions src/__tests__/Sidebar.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from "react"
import { render, screen } from "@testing-library/react"
import { BrowserRouter } from "react-router-dom"
import Sidebar from "../components/SideBar"

test("renders the Sidebar component", () => {
render(
<BrowserRouter>
<Sidebar />
</BrowserRouter>
)
const sidebarTitle = screen.getByTestId("sidebar-component")
expect(sidebarTitle).toBeInTheDocument()
})
30 changes: 30 additions & 0 deletions src/components/NotesCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from "react"
import { format } from "date-fns"
import { Link } from "react-router-dom"
import { useFetchGet } from "../utilities/useFetchGet"

const NotesCard = ({ note }) => {
const { title, creator, created_at } = note
const formattedDate = format(created_at, "MMMM dd, yyyy")

const { data } = useFetchGet(`user/${creator}`)
const user = data
return (
<div className=" p1 border-b p-1">
<Link>
<div>
<h1 className="text-ellipsis text-nowrap font-extrabold">{title}</h1>
<div className=" flex justify-between p-1">
<h3 className="text-xs opacity-40">
{" "}
Creator: {user && user.username}
</h3>
<h3 className="text-xs opacity-40">{formattedDate}</h3>
</div>
</div>
</Link>
</div>
)
}

export default NotesCard
10 changes: 6 additions & 4 deletions src/components/SideBar.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React from "react"

import NotesCard from "./NotesCard"
const SideBar = ({ notes }) => {
return (
<>
{notes?.map((note) => (
<div key={note.id}>{note.title}</div>
))}
<div data-testid="sidebar-component" className="h-screen overflow-scroll">
{notes?.map((note) => (
<NotesCard key={note.id} note={note} />
))}
</div>
</>
)
}
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3764,6 +3764,11 @@ data-view-byte-offset@^1.0.0:
es-errors "^1.3.0"
is-data-view "^1.0.1"

date-fns@^3.6.0:
version "3.6.0"
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-3.6.0.tgz#f20ca4fe94f8b754951b24240676e8618c0206bf"
integrity sha512-fRHTG8g/Gif+kSh50gaGEdToemgfj74aRX3swtiouboip5JDLAyDE9F11nHMIcvOaXeOC6D7SpNhi7uFyB7Uww==

[email protected]:
version "2.0.0"
resolved "https://registry.yarnpkg.com/debounce/-/debounce-2.0.0.tgz#b2f914518a1481466f4edaee0b063e4d473ad549"
Expand Down
Loading