diff --git a/src/app/(main)/my-voyage/[teamId]/features/components/Card.test.tsx b/src/app/(main)/my-voyage/[teamId]/features/components/Card.test.tsx new file mode 100644 index 00000000..e7aaea03 --- /dev/null +++ b/src/app/(main)/my-voyage/[teamId]/features/components/Card.test.tsx @@ -0,0 +1,107 @@ +import { render } from "@testing-library/react"; +import { configureStore } from "@reduxjs/toolkit"; +import { Provider } from "react-redux"; +import React from "react"; +import Card from "./Card"; +import { type Feature, features } from "./fixtures/Features"; +import { rootReducer } from "@/store/store"; +import { useUser } from "@/store/hooks"; + +jest.mock("./EditPopover", () =>
mock child component
); +jest.mock("@/store/hooks", () => ({ + useUser: jest.fn(), +})); +jest.mock("@hello-pangea/dnd", () => ({ + DragDropContext: ({ children }: { children: React.ReactNode }) => ( +
{children}
+ ), + Droppable: ({ + children, + }: { + children: (provided: { + droppableProps: Record; + innerRef: React.RefObject; + }) => React.ReactNode; + }) => ( +
+ {children({ + droppableProps: {}, + innerRef: React.createRef(), + })} +
+ ), + Draggable: ({ + children, + }: { + children: (provided: { + draggableProps: Record; + dragHandleProps: Record; + innerRef: React.RefObject; + }) => React.ReactNode; + }) => ( +
+ {children({ + draggableProps: {}, + dragHandleProps: {}, + innerRef: React.createRef(), + })} +
+ ), +})); + +// "current user" id is 25b7b76c-1567-4910-9d50-e78819daccf1 +const renderWithStore = (feature: Feature, userId: string) => { + const store = configureStore({ + reducer: rootReducer, + }); + + (useUser as jest.Mock).mockReturnValue({ id: userId }); + + return render( + + + , + ); +}; + +describe("Feature Card component", () => { + beforeEach(() => { + jest.clearAllMocks(); + }); + + it("renders edit button if current user's id matches id of user who added feature", () => { + const card = renderWithStore( + features[0], + "25b7b76c-1567-4910-9d50-e78819daccf1", + ); + + const cardAction = card.getByRole("button", { name: /feature menu/i }); + const avatar = card.queryByRole("img", { name: /avatar/i }); + + expect(cardAction).toBeInTheDocument(); + expect(avatar).not.toBeInTheDocument(); + }); + + it("renders avatar if current user's id doesn't match id of user who added feature", () => { + const card = renderWithStore( + features[0], + "5d6eb1aa-6e9c-4b26-a363-6a35e5d76daa", + ); + + const cardAction = card.queryByRole("button", { name: /feature menu/i }); + const avatar = card.getByRole("img", { name: /avatar/i }); + + expect(cardAction).not.toBeInTheDocument(); + expect(avatar).toBeInTheDocument(); + }); + + it("wraps long word to new line", () => { + const card = renderWithStore( + features[0], + "5d6eb1aa-6e9c-4b26-a363-6a35e5d76daa", + ); + + const description = card.getByText(features[0].description); + expect(description.closest("span")).toHaveClass("break-all"); + }); +}); diff --git a/src/app/(main)/my-voyage/[teamId]/features/components/Card.tsx b/src/app/(main)/my-voyage/[teamId]/features/components/Card.tsx index 800e8397..a8502957 100644 --- a/src/app/(main)/my-voyage/[teamId]/features/components/Card.tsx +++ b/src/app/(main)/my-voyage/[teamId]/features/components/Card.tsx @@ -67,7 +67,9 @@ export default function Card({ feature, index, setEditMode }: CardProps) { )}
- {description} + + {description} + {`Added by ${ isCurrentUser ? "you" : firstName + " " + lastName }`} diff --git a/src/app/(main)/my-voyage/[teamId]/features/components/fixtures/Features.ts b/src/app/(main)/my-voyage/[teamId]/features/components/fixtures/Features.ts index 82035022..9c646b10 100644 --- a/src/app/(main)/my-voyage/[teamId]/features/components/fixtures/Features.ts +++ b/src/app/(main)/my-voyage/[teamId]/features/components/fixtures/Features.ts @@ -23,289 +23,89 @@ export interface FeaturesList { features: Feature[]; } -export const featuresLists: FeaturesList[] = [ +export const features = [ { - categoryId: 25, - categoryName: "must have", - features: [ - { - id: 50, - description: "User Accounts", - order: 0, - teamMemberId: 33, - category: { - id: 25, - name: "must have", - }, - addedBy: { - member: { - id: "25b7b76c-1567-4910-9d50-e78819daccf1", - avatar: - "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=wavatar&r=x", - firstName: "Joso", - lastName: "Mađar", - }, - }, - }, - { - id: 51, - description: "Admin dashboard", - order: 1, - teamMemberId: 33, - category: { - id: 25, - name: "must have", - }, - addedBy: { - member: { - id: "25b7b76c-1567-4910-9d50-e78819daccf1", - avatar: - "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=wavatar&r=x", - firstName: "Joso", - lastName: "Mađar", - }, - }, - }, - { - id: 52, - description: "Friend List", - order: 2, - teamMemberId: 35, - category: { - id: 25, - name: "must have", - }, - addedBy: { - member: { - id: "5d6eb1aa-6e9c-4b26-a363-6a35e5d76daa", - avatar: - "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=monsterid&r=x", - firstName: "Larry", - lastName: "Castro", - }, - }, - }, - { - id: 62, - description: "Stripe integration", - order: 3, - teamMemberId: 36, - category: { - id: 25, - name: "must have", - }, - addedBy: { - member: { - id: "dff75faa-1f39-446d-a60c-9589e5ead90f", - avatar: - "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=identicon&r=x", - firstName: "Leonarda", - lastName: "Rowe", - }, - }, + id: 50, + description: "User Accounts", + order: 0, + teamMemberId: 33, + category: { + id: 25, + name: "must have", + }, + addedBy: { + member: { + id: "25b7b76c-1567-4910-9d50-e78819daccf1", + avatar: + "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=wavatar&r=x", + firstName: "Joso", + lastName: "Mađar", }, - ], + }, }, { - categoryId: 26, - categoryName: "should have", - features: [ - { - id: 49, - description: "Themes", - order: 0, - teamMemberId: 33, - category: { - id: 26, - name: "should have", - }, - addedBy: { - member: { - id: "25b7b76c-1567-4910-9d50-e78819daccf1", - avatar: - "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=wavatar&r=x", - firstName: "Joso", - lastName: "Mađar", - }, - }, - }, - { - id: 54, - description: "Save links", - order: 1, - teamMemberId: 35, - category: { - id: 26, - name: "should have", - }, - addedBy: { - member: { - id: "5d6eb1aa-6e9c-4b26-a363-6a35e5d76daa", - avatar: - "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=monsterid&r=x", - firstName: "Larry", - lastName: "Castro", - }, - }, - }, - { - id: 55, - description: "Charts and Graphs", - order: 2, - teamMemberId: 34, - category: { - id: 26, - name: "should have", - }, - addedBy: { - member: { - id: "3eca1a73-01aa-448c-8410-dce17ff08938", - avatar: - "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x", - firstName: "Jessica", - lastName: "Williamson", - }, - }, - }, - { - id: 56, - description: "Chat", - order: 3, - teamMemberId: 34, - category: { - id: 26, - name: "should have", - }, - addedBy: { - member: { - id: "dff75faa-1f39-446d-a60c-9589e5ead90f", - avatar: - "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=identicon&r=x", - firstName: "Leonarda", - lastName: "Rowe", - }, - }, - }, - { - id: 57, - description: "Share images", - order: 4, - teamMemberId: 34, - category: { - id: 26, - name: "should have", - }, - addedBy: { - member: { - id: "3eca1a73-01aa-448c-8410-dce17ff08938", - avatar: - "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=robohash&r=x", - firstName: "Jessica", - lastName: "Williamson", - }, - }, - }, - { - id: 60, - description: "Notifications", - order: 5, - teamMemberId: 36, - category: { - id: 26, - name: "should have", - }, - addedBy: { - member: { - id: "dff75faa-1f39-446d-a60c-9589e5ead90f", - avatar: - "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=identicon&r=x", - firstName: "Leonarda", - lastName: "Rowe", - }, - }, + id: 51, + description: "Admin dashboard", + order: 1, + teamMemberId: 33, + category: { + id: 25, + name: "must have", + }, + addedBy: { + member: { + id: "25b7b76c-1567-4910-9d50-e78819daccf1", + avatar: + "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=wavatar&r=x", + firstName: "Joso", + lastName: "Mađar", }, - { - id: 61, - description: "Mobile app", - order: 6, - teamMemberId: 36, - category: { - id: 26, - name: "should have", - }, - addedBy: { - member: { - id: "dff75faa-1f39-446d-a60c-9589e5ead90f", - avatar: - "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=identicon&r=x", - firstName: "Leonarda", - lastName: "Rowe", - }, - }, - }, - ], + }, }, { - categoryId: 27, - categoryName: "nice to have", - features: [ - { - id: 53, - description: "Share on LinkedIn", - order: 0, - teamMemberId: 35, - category: { - id: 27, - name: "nice to have", - }, - addedBy: { - member: { - id: "5d6eb1aa-6e9c-4b26-a363-6a35e5d76daa", - avatar: - "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=monsterid&r=x", - firstName: "Larry", - lastName: "Castro", - }, - }, - }, - { - id: 58, - description: "Share PDF", - order: 1, - teamMemberId: 36, - category: { - id: 27, - name: "nice to have", - }, - addedBy: { - member: { - id: "dff75faa-1f39-446d-a60c-9589e5ead90f", - avatar: - "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=identicon&r=x", - firstName: "Leonarda", - lastName: "Rowe", - }, - }, + id: 52, + description: "Friend List", + order: 2, + teamMemberId: 35, + category: { + id: 25, + name: "must have", + }, + addedBy: { + member: { + id: "5d6eb1aa-6e9c-4b26-a363-6a35e5d76daa", + avatar: + "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=monsterid&r=x", + firstName: "Larry", + lastName: "Castro", }, - { - id: 59, - description: "Upload files", - order: 2, - teamMemberId: 36, - category: { - id: 27, - name: "nice to have", - }, - addedBy: { - member: { - id: "dff75faa-1f39-446d-a60c-9589e5ead90f", - avatar: - "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=identicon&r=x", - firstName: "Leonarda", - lastName: "Rowe", - }, - }, + }, + }, + { + id: 62, + description: "Stripe integration", + order: 3, + teamMemberId: 36, + category: { + id: 25, + name: "must have", + }, + addedBy: { + member: { + id: "dff75faa-1f39-446d-a60c-9589e5ead90f", + avatar: + "https://gravatar.com/avatar/3bfaef00e02a22f99e17c66e7a9fdd31?s=400&d=identicon&r=x", + firstName: "Leonarda", + lastName: "Rowe", }, - ], + }, + }, +]; + +export const featuresLists: FeaturesList[] = [ + { + categoryId: 25, + categoryName: "must have", + features, }, ]; diff --git a/src/components/navbar/ChinguMenu.tsx b/src/components/navbar/ChinguMenu.tsx index 8b1b35be..4809b082 100644 --- a/src/components/navbar/ChinguMenu.tsx +++ b/src/components/navbar/ChinguMenu.tsx @@ -5,19 +5,20 @@ import routePaths from "@/utils/routePaths"; export default function ChinguMenu() { return ( - -
- Chingu Logo -

- Chingu -

-
+ + Chingu Logo +

+ Chingu +

); } diff --git a/src/components/navbar/Navbar.tsx b/src/components/navbar/Navbar.tsx index f8f2efe2..84097420 100644 --- a/src/components/navbar/Navbar.tsx +++ b/src/components/navbar/Navbar.tsx @@ -6,11 +6,11 @@ interface NavbarProps { export default function Navbar({ children }: NavbarProps) { return ( -