From 334e3beecc68417da89e5e52a80d20e27cea15dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Carlos=20S=C3=A1nchez?= Date: Thu, 13 Jun 2024 15:55:37 -0600 Subject: [PATCH] jose tests --- app/(base)/profile/[id]/page.tsx | 11 +++- components/CoWorkersCarousel.tsx | 41 +++---------- components/ComboBoxSearch.tsx | 24 ++++---- components/Draggable.tsx | 1 + components/FormTextInput.tsx | 1 - components/ProjectCard.tsx | 48 +++++++++++---- components/SearchBar.tsx | 72 ++++++++++++----------- components/Slider.tsx | 6 +- components/Tooltip.tsx | 5 +- components/UserIconNavbar.tsx | 10 +++- components/modals/DraggableUser.tsx | 6 +- components/modals/SelectableDragUsers.tsx | 5 +- components/modals/SprintDropRow.tsx | 26 ++++---- components/modals/SprintStepOne.tsx | 5 +- components/modals/SprintStepTwo.tsx | 5 +- cypress/e2e/login.cy.ts | 1 + cypress/e2e/profile.cy.ts | 1 + cypress/e2e/rulerSurvey.cy.ts | 2 + cypress/e2e/signin.cy.ts | 1 + services/notifications.ts | 1 + types/types.ts | 1 + 21 files changed, 156 insertions(+), 117 deletions(-) diff --git a/app/(base)/profile/[id]/page.tsx b/app/(base)/profile/[id]/page.tsx index d29fc2b..2f76aa1 100644 --- a/app/(base)/profile/[id]/page.tsx +++ b/app/(base)/profile/[id]/page.tsx @@ -1,5 +1,9 @@ import React from "react"; -import { getUserInfoById, getUserSkillsById } from "@/services/user"; +import { + getCoWorkers, + getUserInfoById, + getUserSkillsById, +} from "@/services/user"; import ProfileBanner from "@/components/Profile/ProfileBanner"; import ProfileSection from "@/components/Profile/ProfileSection"; import CoWorkersCarousel from "@/components/CoWorkersCarousel"; @@ -9,7 +13,8 @@ import ProfileTraits from "@/components/Profile/ProfileTraits"; const Profile: React.FC<{ params: { id: string } }> = async ({ params }) => { const user = await getUserInfoById(params.id); const traits = await getUserSkillsById(params.id); - + const coworkers: { name: string; id: string; photoUrl: string | null }[] = + await getCoWorkers(params.id); return (
@@ -21,7 +26,7 @@ const Profile: React.FC<{ params: { id: string } }> = async ({ params }) => { userId={params.id} type="coworkers" > - + getCoWorkers(userId), - }); - - if (!coworkersQuery.data) { - return ( -
- - - -
- ); - } - - if (coworkersQuery.data.length === 0) { + if (coworkers.length === 0) { return (
@@ -55,7 +28,7 @@ export default function EmblaCarousel({ userId }: { userId: string }) { return (
    - {coworkersQuery.data.map((user, index) => ( + {coworkers.map((user, index) => (
  • diff --git a/components/ComboBoxSearch.tsx b/components/ComboBoxSearch.tsx index 2ca9e38..46c4228 100644 --- a/components/ComboBoxSearch.tsx +++ b/components/ComboBoxSearch.tsx @@ -15,23 +15,19 @@ interface Person { photoUrl: string; } -const fetchFilteredUsers = async (query: string) => { - const res = await searchUsers(query); // Llama directamente a la función del backend - return res; -}; - const ComboBoxSearch = () => { const [query, setQuery] = useState(""); const router = useRouter(); - const useSearchUsers = (query: string) => { - return useQuery({ - queryKey: ["search-users", query], - queryFn: () => fetchFilteredUsers(query), - }); + const fetchFilteredUsers = async (query: string) => { + const res = await searchUsers(query); // Llama directamente a la función del backend + return res; }; - const { data: people = [], isLoading } = useSearchUsers(query); + const { data: people = [], isLoading } = useQuery({ + queryKey: ["search-users", query], + queryFn: () => fetchFilteredUsers(query), + }); const handleSelect = (person: Person | null) => { if (person) { @@ -59,7 +55,10 @@ const ComboBoxSearch = () => { className={`h-10 ${isExpanded ? "w-80" : "w-32"} rounded-full border border-gray-300 bg-white px-4 shadow-lg transition-all duration-300 focus:border-blue-500 focus:outline-none`} /> */} {query !== "" && ( - + {isLoading ? (
    Loading... @@ -72,6 +71,7 @@ const ComboBoxSearch = () => { people.map((person) => ( `flex cursor-default select-none items-center gap-2 rounded-xl px-2 py-1 text-sm text-gray-900 ${active && "bg-primary-light text-white"}` diff --git a/components/Draggable.tsx b/components/Draggable.tsx index 03966be..701f491 100644 --- a/components/Draggable.tsx +++ b/components/Draggable.tsx @@ -40,6 +40,7 @@ const Draggable = ({ {...attributes} {...listeners} className={className} + data-testid={`draggable-${data.userId}`} > {children}
    diff --git a/components/FormTextInput.tsx b/components/FormTextInput.tsx index c5e87b4..61e505a 100644 --- a/components/FormTextInput.tsx +++ b/components/FormTextInput.tsx @@ -7,7 +7,6 @@ interface FormTextInputProps { const FormTextInput = ({ name, type, label }: FormTextInputProps) => { const toggleInput = () => { - if (type !== "password") return; const input = document.getElementById("password"); const newType = input?.getAttribute("type") === "text" ? "password" : "text"; diff --git a/components/ProjectCard.tsx b/components/ProjectCard.tsx index 3e3a34d..d84e9b3 100644 --- a/components/ProjectCard.tsx +++ b/components/ProjectCard.tsx @@ -20,29 +20,51 @@ export default async function ProjectCard({ const coworkersQuery = await getEmployeesInProjectById(id); return ( -
    +
    -

    {name}

    - {date &&

    {date}

    } +

    + {name} +

    + {date && ( +

    + {date} +

    + )} {description && ( -

    {description}

    +

    + {description} +

    )}

    In progress

      - {coworkersQuery.map((coworker, index) => ( -
    • - -
    • - ))} + {coworkersQuery && + coworkersQuery.map((coworker, index) => ( +
    • + +
    • + ))}
    diff --git a/components/SearchBar.tsx b/components/SearchBar.tsx index d2c954a..2d3a04b 100644 --- a/components/SearchBar.tsx +++ b/components/SearchBar.tsx @@ -32,44 +32,50 @@ const SearchBar = ({ setIsExpanded(false); } }, [value]); + + const handleExpand = () => { + setIsExpanded(!isExpanded); + }; + if (type === "comboboxImput") { return ( - type === "comboboxImput" && ( +
    + + +
    - setIsExpanded(!isExpanded)} - > - - -
    - -
    +
    - ) +
    ); } diff --git a/components/Slider.tsx b/components/Slider.tsx index e87d24c..166c1e7 100644 --- a/components/Slider.tsx +++ b/components/Slider.tsx @@ -7,12 +7,16 @@ interface SliderProps { } const Slider = ({ label, className, onChange, name, value }: SliderProps) => { return ( -
    +
    +
    {children}
    diff --git a/components/UserIconNavbar.tsx b/components/UserIconNavbar.tsx index a0b97e6..d40678c 100644 --- a/components/UserIconNavbar.tsx +++ b/components/UserIconNavbar.tsx @@ -71,10 +71,16 @@ const UserIconNavbar = ({ path }: UserIconInterface) => { leaveFrom="transform opacity-100 scale-100" leaveTo="transform opacity-0 scale-95" > - +
    -

    +

    Hello {user?.name.split(" ")[0]}!

    diff --git a/components/modals/DraggableUser.tsx b/components/modals/DraggableUser.tsx index 57431d5..0a7345d 100644 --- a/components/modals/DraggableUser.tsx +++ b/components/modals/DraggableUser.tsx @@ -13,7 +13,6 @@ interface DraggableUserProps { const DraggableUser = ({ user, times = 0 }: DraggableUserProps) => { const [isDragging, setIsDragging] = useState(false); - return ( { ) : ( {times > 1 && ( - + x{times} )} diff --git a/components/modals/SelectableDragUsers.tsx b/components/modals/SelectableDragUsers.tsx index 0ab67bc..71a06c1 100644 --- a/components/modals/SelectableDragUsers.tsx +++ b/components/modals/SelectableDragUsers.tsx @@ -8,7 +8,10 @@ interface SelectableDragUsersProps { const SelectableDragUsers = ({ users }: SelectableDragUsersProps) => { return ( -
    +
    {users.map( (user, index) => user.times > 0 && ( diff --git a/components/modals/SprintDropRow.tsx b/components/modals/SprintDropRow.tsx index 4743f32..a6a31be 100644 --- a/components/modals/SprintDropRow.tsx +++ b/components/modals/SprintDropRow.tsx @@ -19,23 +19,25 @@ const SprintDropRow = ({ people, }: SprintDropRowProps) => { return ( -
    +

    {title}

    - {colors.map((color, index) => { - return ( - - ); - })} + {colors.map((color, index) => ( + + ))}
    ); }; diff --git a/components/modals/SprintStepOne.tsx b/components/modals/SprintStepOne.tsx index b9c96cb..73ddcd1 100644 --- a/components/modals/SprintStepOne.tsx +++ b/components/modals/SprintStepOne.tsx @@ -35,7 +35,10 @@ const SprintStepOne = ({ }; return ( -
    +
    {questions && questions.map((question, index) => ( +

    Drag and drop the profile picture of yonpmur{" "} co-worker to the box that{" "} diff --git a/cypress/e2e/login.cy.ts b/cypress/e2e/login.cy.ts index 63021be..8973f9a 100644 --- a/cypress/e2e/login.cy.ts +++ b/cypress/e2e/login.cy.ts @@ -1,3 +1,4 @@ +//José Carlos Sánchez Gómez - A01174050 describe("Login", () => { it("Visits Login page, and signs in", () => { cy.visit("/"); diff --git a/cypress/e2e/profile.cy.ts b/cypress/e2e/profile.cy.ts index f62c530..98bd930 100644 --- a/cypress/e2e/profile.cy.ts +++ b/cypress/e2e/profile.cy.ts @@ -1,3 +1,4 @@ +//José Carlos Sánchez Gómez - A01174050 describe("Profile", () => { beforeEach(() => { cy.visit("/profile"); diff --git a/cypress/e2e/rulerSurvey.cy.ts b/cypress/e2e/rulerSurvey.cy.ts index edf1180..1271a19 100644 --- a/cypress/e2e/rulerSurvey.cy.ts +++ b/cypress/e2e/rulerSurvey.cy.ts @@ -2,6 +2,8 @@ const randomEmotion = { row: Math.floor(Math.random() * 12), col: Math.floor(Math.random() * 12), }; + +//José Carlos Sánchez Gómez - A01174050 describe("Testing different surveys", () => { beforeEach(() => { cy.visit("/"); diff --git a/cypress/e2e/signin.cy.ts b/cypress/e2e/signin.cy.ts index 9300bc2..9c4bad2 100644 --- a/cypress/e2e/signin.cy.ts +++ b/cypress/e2e/signin.cy.ts @@ -1,3 +1,4 @@ +//José Carlos Sánchez Gómez - A01174050 describe("Register", () => { beforeEach(() => { cy.visit("/register"); diff --git a/services/notifications.ts b/services/notifications.ts index a7d17ae..9d97ca2 100644 --- a/services/notifications.ts +++ b/services/notifications.ts @@ -17,6 +17,7 @@ import { Notification } from "@/types/types"; export async function getNotifications() { const session = await auth(); const userId = session?.user?.id; + console.log(userId); if (!userId) throw new Error("You must be signed in"); const notifications = []; diff --git a/types/types.ts b/types/types.ts index 5b9a244..c6f5a9c 100644 --- a/types/types.ts +++ b/types/types.ts @@ -3,6 +3,7 @@ export type Coworker = { photoUrl?: string | null; userId: string; color?: string; + id?: string; }; export interface User {