Skip to content

Commit

Permalink
Merge pull request #241 from wizelineacademy/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
pedroalonsoms authored Jun 14, 2024
2 parents 56cd70f + 638251c commit 56e4f70
Show file tree
Hide file tree
Showing 10 changed files with 247 additions and 27 deletions.
9 changes: 8 additions & 1 deletion components/GrowthCircle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const GrowthCircle = ({

return (
<svg
data-testid="growth-circle-svg"
width={size}
height={size}
viewBox={`0 0 ${size} ${size}`}
Expand All @@ -41,7 +42,13 @@ const GrowthCircle = ({
<stop offset="100%" stopColor={gradient.end} />
</linearGradient>
</defs>
<circle cx={radius} cy={radius} r={radius} fill={`url(#${gradientId})`} />
<circle
data-testid="growth-circle"
cx={radius}
cy={radius}
r={radius}
fill={`url(#${gradientId})`}
/>
<text
x="50%"
y="50%"
Expand Down
24 changes: 16 additions & 8 deletions components/Loader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@ import "@/public/Loader.css";

const Loader = () => {
return (
<section className="m-auto flex h-full w-full flex-col items-center justify-center">
<div className="container">
<div className="box" />
<div className="box" />
<div className="box" />
<div className="box" />
<div className="box" />
<section
data-testid="loader-section"
className="m-auto flex h-full w-full flex-col items-center justify-center"
>
<div className="container" data-testid="loader-container">
<div className="box" data-testid="loader-box" />
<div className="box" data-testid="loader-box" />
<div className="box" data-testid="loader-box" />
<div className="box" data-testid="loader-box" />
<div className="box" data-testid="loader-box" />
</div>
<p className="mt-4 text-xl font-medium text-primary">Cargando...</p>
<p
data-testid="loader-text"
className="mt-4 text-xl font-medium text-primary"
>
Cargando...
</p>
</section>
);
};
Expand Down
2 changes: 2 additions & 0 deletions components/UserProfileButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ const UserProfileButton = ({
strokeWidth={1.4}
stroke="currentColor"
className={`${color} ${sizes[size]}`}
role="img"
data-testid="user-profile-icon"
>
<path
strokeLinecap="round"
Expand Down
21 changes: 17 additions & 4 deletions db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,15 @@ export const pipTask = pgTable("pip_task", {
id: serial("id").primaryKey(),
rulerSurveyId: integer("ruler_survey_id").references(
() => rulerSurveyAnswers.id,
{ onDelete: "cascade" },
),
sprintSurveyId: integer("sprint_survey_id").references(() => sprintSurvey.id),
finalSurveyId: integer("final_survey_id").references(() => finalSurvey.id),
sprintSurveyId: integer("sprint_survey_id").references(
() => sprintSurvey.id,
{ onDelete: "cascade" },
),
finalSurveyId: integer("final_survey_id").references(() => finalSurvey.id, {
onDelete: "cascade",
}),
userId: uuid("user_id").references(() => user.id, { onDelete: "cascade" }),
title: varchar("title", { length: 64 }),
description: varchar("description", { length: 256 }),
Expand Down Expand Up @@ -124,11 +130,15 @@ export const userResource = pgTable(
}),
rulerSurveyId: integer("ruler_survey_id").references(
() => rulerSurveyAnswers.id,
{ onDelete: "cascade" },
),
sprintSurveyId: integer("sprint_survey_id").references(
() => sprintSurvey.id,
{ onDelete: "cascade" },
),
finalSurveyId: integer("final_survey_id").references(() => finalSurvey.id),
finalSurveyId: integer("final_survey_id").references(() => finalSurvey.id, {
onDelete: "cascade",
}),
},
// composite primary key on (userId, resourceId)
);
Expand Down Expand Up @@ -189,7 +199,10 @@ export const pipResourceSkill = pgTable("pip_resource_skill", {
});

export const sprintSurveyQuestion = pgTable("sprint_survey_question", {
sprintSurveyId: integer("sprint_survey_id").references(() => sprintSurvey.id),
sprintSurveyId: integer("sprint_survey_id").references(
() => sprintSurvey.id,
{ onDelete: "cascade" },
),
questionId: integer("question_id").references(() => question.id),
});

Expand Down
17 changes: 15 additions & 2 deletions services/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
sprintSurveyAnswerProject,
rulerSurveyAnswers,
rulerEmotion,
sprintSurveyQuestion,
} from "@/db/schema";
import { and, asc, eq, inArray, ne, or } from "drizzle-orm";
import { SQSClient, SendMessageBatchCommand } from "@aws-sdk/client-sqs";
Expand Down Expand Up @@ -97,11 +98,23 @@ export async function createProject({
);
};

const sprintSurveyQuestionsIds: number[] = [30, 31, 32, 33, 34, 41];

jumpToNextSprint();
while (currentDate <= newProject.endDate) {
await db
const [insertedSurvey] = await db
.insert(sprintSurvey)
.values({ projectId, scheduledAt: currentDate });
.values({ projectId, scheduledAt: currentDate })
.returning({ id: sprintSurvey.id });

// insertedSurvey.id

await db.insert(sprintSurveyQuestion).values(
sprintSurveyQuestionsIds.map((questionId) => ({
sprintSurveyId: insertedSurvey.id,
questionId: questionId,
})),
);

jumpToNextSprint();
}
Expand Down
8 changes: 4 additions & 4 deletions services/rag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,8 @@ async function orderCoworkersFeedback(

const coworkersOpenFeedback = await db
.select({
userId: sprintSurveyAnswerCoworkers.userId,
coworkerId: sprintSurveyAnswerCoworkers.coworkerId,
userId: sprintSurveyAnswerCoworkers.coworkerId,
coworkerId: sprintSurveyAnswerCoworkers.userId,
questionId: sprintSurveyAnswerCoworkers.questionId,
comment: sprintSurveyAnswerCoworkers.comment,
})
Expand All @@ -451,8 +451,8 @@ async function orderCoworkersFeedback(

const coworkersClosedFeedback = await db
.select({
userId: sprintSurveyAnswerCoworkers.userId,
coworkerId: sprintSurveyAnswerCoworkers.coworkerId,
userId: sprintSurveyAnswerCoworkers.coworkerId,
coworkerId: sprintSurveyAnswerCoworkers.userId,
questionId: sprintSurveyAnswerCoworkers.questionId,
answer: sprintSurveyAnswerCoworkers.answer,
})
Expand Down
27 changes: 19 additions & 8 deletions services/sprintSurvey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,9 @@ export async function getDetailedProjectStatistics(projectId: number) {
),
);

const listeningFeeling = Math.round(
Number(listeningFeelingResult[0]?.listeningFeeling ?? 0),
const listeningFeeling = Math.min(
100,
Math.round(Number(listeningFeelingResult[0]?.listeningFeeling ?? 0)),
);

// Obtener el promedio de respuestas para "Recognition Feeling"
Expand All @@ -267,8 +268,9 @@ export async function getDetailedProjectStatistics(projectId: number) {
),
);

const recognitionFeeling = Math.round(
Number(recognitionFeelingResult[0]?.recognitionFeeling ?? 0),
const recognitionFeeling = Math.min(
100,
Math.round(Number(recognitionFeelingResult[0]?.recognitionFeeling ?? 0)),
);

// Obtener el promedio de respuestas para "Respect and Trust Environment"
Expand All @@ -286,9 +288,14 @@ export async function getDetailedProjectStatistics(projectId: number) {
eq(finalSurveyAnswer.questionId, 39),
),
);
const respectTrustEnvironment = Math.round(
Number(respectTrustEnvironmentResult[0]?.respectTrustEnvironment ?? 0),

const respectTrustEnvironment = Math.min(
100,
Math.round(
Number(respectTrustEnvironmentResult[0]?.respectTrustEnvironment ?? 0),
),
);

const resourcesSatisfactionResult = await db
.select({
resourcesSatisfaction:
Expand All @@ -307,8 +314,12 @@ export async function getDetailedProjectStatistics(projectId: number) {
eq(sprintSurveyAnswerProject.questionId, 26),
),
);
const resourcesSatisfaction = Math.round(
Number(resourcesSatisfactionResult[0]?.resourcesSatisfaction ?? 0),

const resourcesSatisfaction = Math.min(
100,
Math.round(
Number(resourcesSatisfactionResult[0]?.resourcesSatisfaction ?? 0),
),
);

return {
Expand Down
70 changes: 70 additions & 0 deletions test/GrowthCircle.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import React from "react";
import { render, screen } from "@testing-library/react";
import { describe, it, expect } from "vitest";
import GrowthCircle from "@/components/GrowthCircle";

describe("GrowthCircle Component", () => {
/*
Adrian Alejandro Ramirez Cruz A00830640 - Test #6/12
Test #1: Verifica que el componente se renderiza correctamente con los valores mínimos.
*/
it("renders correctly with minimum values", () => {
render(
<GrowthCircle
percentage={0}
gradient={{ start: "#000000", end: "#ffffff" }}
/>,
);
const svgElement = screen.getByTestId("growth-circle-svg");
expect(svgElement).toBeInTheDocument();
});

/*
Adrian Alejandro Ramirez Cruz A00830640 - Test #7/12
Test #2: Verifica que el componente se renderiza correctamente con los valores máximos.
*/
it("renders correctly with maximum values", () => {
render(
<GrowthCircle
percentage={100}
gradient={{ start: "#000000", end: "#ffffff" }}
/>,
);
const svgElement = screen.getByTestId("growth-circle-svg");
expect(svgElement).toBeInTheDocument();
});

/*
Adrian Alejandro Ramirez Cruz A00830640 - Test #8/12
Test #3: Verifica que el tamaño del círculo y el radio se calculan correctamente.
*/
it("calculates the circle size and radius correctly", () => {
render(
<GrowthCircle
percentage={50}
gradient={{ start: "#000000", end: "#ffffff" }}
/>,
);
const svgElement = screen.getByTestId("growth-circle-svg");
const circleElement = screen.getByTestId("growth-circle");
const expectedRadius = 50; // 50% of the maxSize (150)
expect(svgElement).toHaveAttribute("width", String(expectedRadius * 2));
expect(svgElement).toHaveAttribute("height", String(expectedRadius * 2));
expect(circleElement).toHaveAttribute("r", String(expectedRadius));
});

/*
Adrian Alejandro Ramirez Cruz A00830640 - Test #9/10
Test #4: Verifica que el texto se renderiza correctamente dentro del círculo.
*/
it("renders text correctly inside the circle", () => {
render(
<GrowthCircle
percentage={75}
gradient={{ start: "#000000", end: "#ffffff" }}
/>,
);
const textElement = screen.getByText("75%");
expect(textElement).toBeInTheDocument();
});
});
39 changes: 39 additions & 0 deletions test/Loader.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from "react";
import { render, screen } from "@testing-library/react";
import { describe, it, expect } from "vitest";
import Loader from "@/components/Loader";

describe("Loader Component", () => {
/*
Adrian Alejandro Ramirez Cruz A00830640 - Test #10/12
Test #1: Verifica que el componente se renderiza correctamente.
*/
it("renders correctly", () => {
render(<Loader />);
const loaderSection = screen.getByTestId("loader-section");
expect(loaderSection).toBeInTheDocument();
});

/*
Adrian Alejandro Ramirez Cruz A00830640 - Test #11/12
Test #2: Verifica que el contenedor y las cajas se renderizan correctamente.
*/
it("renders the loader container and boxes correctly", () => {
render(<Loader />);
const loaderContainer = screen.getByTestId("loader-container");
const loaderBoxes = screen.getAllByTestId("loader-box");
expect(loaderContainer).toBeInTheDocument();
expect(loaderBoxes.length).toBe(5); // Verifica que haya 5 elementos con el data-testid "loader-box"
});

/*
Adrian Alejandro Ramirez Cruz A00830640 - Test #12/12
Test #3: Verifica que el texto de carga se renderiza correctamente.
*/
it("renders the loading text correctly", () => {
render(<Loader />);
const loadingText = screen.getByTestId("loader-text");
expect(loadingText).toBeInTheDocument();
expect(loadingText).toHaveTextContent("Cargando...");
});
});
57 changes: 57 additions & 0 deletions test/UserProfileButton.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React from "react";
import { render, screen } from "@testing-library/react";
import { describe, it, expect } from "vitest";
import UserProfileButton from "@/components/UserProfileButton";

describe("UserProfileButton Component", () => {
/*
Adrian Alejandro Ramirez Cruz A00830640 - Test #1/12
Test #1: Verifica que el componente se renderiza correctamente sin una foto de perfil.
*/
it("renders correctly without a profile photo", () => {
render(<UserProfileButton />);
expect(screen.getByTestId("user-profile-icon")).toBeInTheDocument();
});

/*
Adrian Alejandro Ramirez Cruz A00830640 - Test #2/12
Test #2: Verifica que el componente se renderiza correctamente con una foto de perfil.
*/
it("renders correctly with a profile photo", () => {
const photoUrl = "https://example.com/photo.jpg";
render(<UserProfileButton photoUrl={photoUrl} />);
const imgElement = screen.getByAltText("User");
expect(imgElement).toBeInTheDocument();
expect(imgElement).toHaveAttribute("src", photoUrl);
});

/*
Adrian Alejandro Ramirez Cruz A00830640 - Test #3/12
Test #3: Verifica que el componente se renderiza con el tamaño especificado.
*/
it("renders with the specified size", () => {
render(<UserProfileButton size="lg" />);
const svgElement = screen.getByTestId("user-profile-icon");
expect(svgElement).toHaveClass("h-32 w-32");
});

/*
Adrian Alejandro Ramirez Cruz A00830640 - Test #4/12
Test #4: Verifica que el componente se renderiza con el color por defecto.
*/
it("renders with default color", () => {
render(<UserProfileButton />);
const svgElement = screen.getByTestId("user-profile-icon");
expect(svgElement).toHaveClass("text-primary");
});

/*
Adrian Alejandro Ramirez Cruz A00830640 - Test #5/12
Test #5: Verifica que el componente se renderiza con el color personalizado.
*/
it("renders with custom color", () => {
render(<UserProfileButton color="text-secondary" />);
const svgElement = screen.getByTestId("user-profile-icon");
expect(svgElement).toHaveClass("text-secondary");
});
});

0 comments on commit 56e4f70

Please sign in to comment.