Skip to content

Commit

Permalink
Merge pull request #75 from wizelineacademy/tests-caro
Browse files Browse the repository at this point in the history
Added Tests Caro
  • Loading branch information
Diegogtz03 authored Jun 15, 2024
2 parents f558306 + 4718a64 commit ebc8b71
Show file tree
Hide file tree
Showing 10 changed files with 372 additions and 1 deletion.
27 changes: 27 additions & 0 deletions knowx/cypress/e2e/compare/compareCard.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//E2E test for the compare one card functionality - Carolina González A01284948

describe("Load one card", () => {
it("passes", () => {
// Prepare the database
cy.request("http://localhost:3000/api/testing")
cy.login()
cy.wait(8000)
cy.visit("http://localhost:3000/")

cy.setCookie(
"compareData",
"%7B%22categories%22%3A%5B%22Description%22%2C%22Price%22%2C%22Sound%20quality%22%2C%22Brand%20reputation%22%2C%22Design%22%2C%22Key%20action%22%5D%2C%22results%22%3A%5B%7B%22Name%22%3A%22Steinway%20%26%20Sons%22%2C%22Description%22%3A%22Handcrafted%20pianos%20with%20a%20focus%20on%20quality%20and%20tradition.%22%2C%22Categories%22%3A%5B%7B%22Name%22%3A%22Price%22%2C%22Value%22%3A%22High%22%7D%2C%7B%22Name%22%3A%22Sound%20quality%22%2C%22Value%22%3A%22Excellent%22%7D%2C%7B%22Name%22%3A%22Brand%20reputation%22%2C%22Value%22%3A%22Iconic%20and%20renowned%22%7D%2C%7B%22Name%22%3A%22Design%22%2C%22Value%22%3A%22Elegant%20and%20timeless%22%7D%2C%7B%22Name%22%3A%22Key%20action%22%2C%22Value%22%3A%22Superb%22%7D%5D%7D%2C%7B%22Name%22%3A%22Yamaha%22%2C%22Description%22%3A%22Japanese%20manufacturer%20known%20for%20innovation%2C%20reliability%2C%20and%20versatility.%22%2C%22Categories%22%3A%5B%7B%22Name%22%3A%22Price%22%2C%22Value%22%3A%22Moderate%20to%20high%22%7D%2C%7B%22Name%22%3A%22Sound%20quality%22%2C%22Value%22%3A%22Very%20good%22%7D%2C%7B%22Name%22%3A%22Brand%20reputation%22%2C%22Value%22%3A%22Renowned%22%7D%2C%7B%22Name%22%3A%22Design%22%2C%22Value%22%3A%22Modern%20and%20sleek%22%7D%2C%7B%22Name%22%3A%22Key%20action%22%2C%22Value%22%3A%22Excellent%22%7D%5D%7D%2C%7B%22Name%22%3A%22Bechstein%22%2C%22Description%22%3A%22German%20manufacturer%20known%20for%20craftsmanship%20and%20rich%2C%20powerful%20sound.%22%2C%22Categories%22%3A%5B%7B%22Name%22%3A%22Price%22%2C%22Value%22%3A%22High%22%7D%2C%7B%22Name%22%3A%22Sound%20quality%22%2C%22Value%22%3A%22Excellent%22%7D%2C%7B%22Name%22%3A%22Brand%20reputation%22%2C%22Value%22%3A%22Renowned%22%7D%2C%7B%22Name%22%3A%22Design%22%2C%22Value%22%3A%22Elegant%20and%20luxurious%22%7D%2C%7B%22Name%22%3A%22Key%20action%22%2C%22Value%22%3A%22Superb%22%7D%5D%7D%2C%7B%22Name%22%3A%22Kawai%22%2C%22Description%22%3A%22Japanese%20manufacturer%20known%20for%20quality%2C%20innovation%2C%20and%20value.%22%2C%22Categories%22%3A%5B%7B%22Name%22%3A%22Price%22%2C%22Value%22%3A%22Moderate%22%7D%2C%7B%22Name%22%3A%22Sound%20quality%22%2C%22Value%22%3A%22Very%20good%22%7D%2C%7B%22Name%22%3A%22Brand%20reputation%22%2C%22Value%22%3A%22Distinguished%22%7D%2C%7B%22Name%22%3A%22Design%22%2C%22Value%22%3A%22Modern%20and%20stylish%22%7D%2C%7B%22Name%22%3A%22Key%20action%22%2C%22Value%22%3A%22Excellent%22%7D%5D%7D%2C%7B%22Name%22%3A%22Grotrian-Steinweg%22%2C%22Description%22%3A%22German%20manufacturer%20known%20for%20craftsmanship%2C%20sound%20quality%2C%20and%20tradition.%22%2C%22Categories%22%3A%5B%7B%22Name%22%3A%22Price%22%2C%22Value%22%3A%22High%22%7D%2C%7B%22Name%22%3A%22Sound%20quality%22%2C%22Value%22%3A%22Excellent%22%7D%2C%7B%22Name%22%3A%22Brand%20reputation%22%2C%22Value%22%3A%22Renowned%22%7D%2C%7B%22Name%22%3A%22Design%22%2C%22Value%22%3A%22Elegant%20and%20luxurious%22%7D%2C%7B%22Name%22%3A%22Key%20action%22%2C%22Value%22%3A%22Superb%22%7D%5D%7D%2C%7B%22Name%22%3A%22Baldwin%22%2C%22Description%22%3A%22American%20manufacturer%20known%20for%20quality%20and%20affordability.%22%2C%22Categories%22%3A%5B%7B%22Name%22%3A%22Price%22%2C%22Value%22%3A%22Moderate%22%7D%2C%7B%22Name%22%3A%22Sound%20quality%22%2C%22Value%22%3A%22Good%22%7D%2C%7B%22Name%22%3A%22Brand%20reputation%22%2C%22Value%22%3A%22Distinguished%22%7D%2C%7B%22Name%22%3A%22Design%22%2C%22Value%22%3A%22Traditional%20and%20classic%22%7D%2C%7B%22Name%22%3A%22Key%20action%22%2C%22Value%22%3A%22Very%20good%22%7D%5D%7D%5D%7D",
)
cy.visit("http://localhost:3000/dashboard/phase3")
cy.wait(8000)

cy.get("table").should("exist")
cy.contains(
"Handcrafted pianos with a focus on quality and tradition.",
).click()

cy.get("button").contains("Compare").click()

cy.get("h2").contains("Steinway & Sons")
})
})
35 changes: 35 additions & 0 deletions knowx/cypress/e2e/compare/compareCards.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//E2E test for the compare two cards functionality - Carolina González A01284948

describe("Load three cards", () => {
it("passes", () => {
// Prepare the database
cy.request("http://localhost:3000/api/testing")
cy.login()
cy.wait(8000)
cy.visit("http://localhost:3000/")

cy.setCookie(
"compareData",
"%7B%22categories%22%3A%5B%22Description%22%2C%22Price%22%2C%22Sound%20quality%22%2C%22Brand%20reputation%22%2C%22Design%22%2C%22Key%20action%22%5D%2C%22results%22%3A%5B%7B%22Name%22%3A%22Steinway%20%26%20Sons%22%2C%22Description%22%3A%22Handcrafted%20pianos%20with%20a%20focus%20on%20quality%20and%20tradition.%22%2C%22Categories%22%3A%5B%7B%22Name%22%3A%22Price%22%2C%22Value%22%3A%22High%22%7D%2C%7B%22Name%22%3A%22Sound%20quality%22%2C%22Value%22%3A%22Excellent%22%7D%2C%7B%22Name%22%3A%22Brand%20reputation%22%2C%22Value%22%3A%22Iconic%20and%20renowned%22%7D%2C%7B%22Name%22%3A%22Design%22%2C%22Value%22%3A%22Elegant%20and%20timeless%22%7D%2C%7B%22Name%22%3A%22Key%20action%22%2C%22Value%22%3A%22Superb%22%7D%5D%7D%2C%7B%22Name%22%3A%22Yamaha%22%2C%22Description%22%3A%22Japanese%20manufacturer%20known%20for%20innovation%2C%20reliability%2C%20and%20versatility.%22%2C%22Categories%22%3A%5B%7B%22Name%22%3A%22Price%22%2C%22Value%22%3A%22Moderate%20to%20high%22%7D%2C%7B%22Name%22%3A%22Sound%20quality%22%2C%22Value%22%3A%22Very%20good%22%7D%2C%7B%22Name%22%3A%22Brand%20reputation%22%2C%22Value%22%3A%22Renowned%22%7D%2C%7B%22Name%22%3A%22Design%22%2C%22Value%22%3A%22Modern%20and%20sleek%22%7D%2C%7B%22Name%22%3A%22Key%20action%22%2C%22Value%22%3A%22Excellent%22%7D%5D%7D%2C%7B%22Name%22%3A%22Bechstein%22%2C%22Description%22%3A%22German%20manufacturer%20known%20for%20craftsmanship%20and%20rich%2C%20powerful%20sound.%22%2C%22Categories%22%3A%5B%7B%22Name%22%3A%22Price%22%2C%22Value%22%3A%22High%22%7D%2C%7B%22Name%22%3A%22Sound%20quality%22%2C%22Value%22%3A%22Excellent%22%7D%2C%7B%22Name%22%3A%22Brand%20reputation%22%2C%22Value%22%3A%22Renowned%22%7D%2C%7B%22Name%22%3A%22Design%22%2C%22Value%22%3A%22Elegant%20and%20luxurious%22%7D%2C%7B%22Name%22%3A%22Key%20action%22%2C%22Value%22%3A%22Superb%22%7D%5D%7D%2C%7B%22Name%22%3A%22Kawai%22%2C%22Description%22%3A%22Japanese%20manufacturer%20known%20for%20quality%2C%20innovation%2C%20and%20value.%22%2C%22Categories%22%3A%5B%7B%22Name%22%3A%22Price%22%2C%22Value%22%3A%22Moderate%22%7D%2C%7B%22Name%22%3A%22Sound%20quality%22%2C%22Value%22%3A%22Very%20good%22%7D%2C%7B%22Name%22%3A%22Brand%20reputation%22%2C%22Value%22%3A%22Distinguished%22%7D%2C%7B%22Name%22%3A%22Design%22%2C%22Value%22%3A%22Modern%20and%20stylish%22%7D%2C%7B%22Name%22%3A%22Key%20action%22%2C%22Value%22%3A%22Excellent%22%7D%5D%7D%2C%7B%22Name%22%3A%22Grotrian-Steinweg%22%2C%22Description%22%3A%22German%20manufacturer%20known%20for%20craftsmanship%2C%20sound%20quality%2C%20and%20tradition.%22%2C%22Categories%22%3A%5B%7B%22Name%22%3A%22Price%22%2C%22Value%22%3A%22High%22%7D%2C%7B%22Name%22%3A%22Sound%20quality%22%2C%22Value%22%3A%22Excellent%22%7D%2C%7B%22Name%22%3A%22Brand%20reputation%22%2C%22Value%22%3A%22Renowned%22%7D%2C%7B%22Name%22%3A%22Design%22%2C%22Value%22%3A%22Elegant%20and%20luxurious%22%7D%2C%7B%22Name%22%3A%22Key%20action%22%2C%22Value%22%3A%22Superb%22%7D%5D%7D%2C%7B%22Name%22%3A%22Baldwin%22%2C%22Description%22%3A%22American%20manufacturer%20known%20for%20quality%20and%20affordability.%22%2C%22Categories%22%3A%5B%7B%22Name%22%3A%22Price%22%2C%22Value%22%3A%22Moderate%22%7D%2C%7B%22Name%22%3A%22Sound%20quality%22%2C%22Value%22%3A%22Good%22%7D%2C%7B%22Name%22%3A%22Brand%20reputation%22%2C%22Value%22%3A%22Distinguished%22%7D%2C%7B%22Name%22%3A%22Design%22%2C%22Value%22%3A%22Traditional%20and%20classic%22%7D%2C%7B%22Name%22%3A%22Key%20action%22%2C%22Value%22%3A%22Very%20good%22%7D%5D%7D%5D%7D",
)
cy.visit("http://localhost:3000/dashboard/phase3")
cy.wait(8000)

cy.get("table").should("exist")
cy.contains(
"Handcrafted pianos with a focus on quality and tradition.",
).click()
cy.contains(
"Japanese manufacturer known for innovation, reliability, and versatility.",
).click()
cy.contains(
"German manufacturer known for craftsmanship and rich, powerful sound.",
).click()

cy.get("button").contains("Compare").click()

cy.get("h2").contains("Steinway & Sons")
cy.get("h2").contains("Yamaha")
cy.get("h2").contains("Bechstein")
})
})
21 changes: 21 additions & 0 deletions knowx/cypress/e2e/logout/logout.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//E2E test for the Log out functionality - Carolina González A01284948
describe("Sign out", () => {
it("passes", () => {
// Prepare the database
cy.request("http://localhost:3000/api/testing")
cy.login()
cy.wait(8000)
cy.visit("http://localhost:3000/")
cy.get("#dropdown-btn-icon").click()
cy.get("button").contains("Sign out").click()
cy.wait(8000)

// Check that the user is logged out
cy.get("button").should("contain", "Sign in with Email")
cy.wait(8000)

cy.visit("http://localhost:3000/")
cy.wait(8000)
cy.get("button").should("contain", "Sign in with Email")
})
})
2 changes: 1 addition & 1 deletion knowx/src/components/Compare/Compare_Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useState } from "react"
import { Results, ServiceCategories } from "@/interfaces/Phase3"
import { Chip } from "@nextui-org/react"

interface CardProps {
export interface CardProps {
initialTitle: string
initialDescription: string
initialData: ServiceCategories[]
Expand Down
1 change: 1 addition & 0 deletions knowx/src/components/Dashboard/InputBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const InputBar = ({ history }: { history: SimpleHistoryType[] | [] }) => {
<div className="w-full px-1 py-2">
<div className="mt-2 flex w-full flex-col gap-2">
<Button
name="historial"
type="button"
onClick={() => router.push(`/history/${suggestion.id}`)}
aria-hidden="true"
Expand Down
63 changes: 63 additions & 0 deletions knowx/src/tests/compare/compareCardTitles.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//Test for the render of the list of titles - Carolina González A01284948
import { test, expect } from "vitest"
import { screen, render } from "@testing-library/react"
import { mockCardProps } from "../mocks/mock"
import { act } from "react"
import { Compare_Card } from "@/components/Compare/Compare_Card"

test("Compare Card Titles Render Test", async () => {
render(
<Compare_Card
initialTitle={mockCardProps.initialTitle}
initialDescription={mockCardProps.initialDescription}
initialData={mockCardProps.initialData}
titles={mockCardProps.titles}
allData={mockCardProps.allData}
/>,
)

expect(screen.getByText("test")).toBeVisible()

act(() => {
screen
.getByRole("button", {
name: /test/i,
})
.click()
})

expect(screen.getByText("titles2")).toBeVisible()
})

/*test("Compare Card Information Change", async () => {
render(
<Compare_Card
initialTitle={mockCardProps.initialTitle}
initialDescription={mockCardProps.initialDescription}
initialData={mockCardProps.initialData}
titles={mockCardProps.titles}
allData={mockCardProps.allData}
/>,
)
expect(screen.getByText("InitialDescription")).toBeVisible()
act(() => {
screen
.getByRole("button", {
name: /test/i,
})
.click()
})
act(() => {
screen
.getByRole("menuitem", {
name: /titles2/i,
})
.click()
})
expect(screen.getByText("Description2")).toBeVisible()
})
*/
77 changes: 77 additions & 0 deletions knowx/src/tests/dashboard/historyResults.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//Test for the render and functionality of the history component - Carolina González A01284948
import { test, expect, vi } from "vitest"
import { screen, render } from "@testing-library/react"
import { mockHistoryTest } from "../mocks/mock"
import { act } from "react"
import InputBar from "@/components/Dashboard/InputBar"
import { fireEvent } from "@testing-library/react"

const mockLink = vi.fn()

const mockRouter = {
push: vi.fn(),
}
vi.mock("next/navigation", () => ({
useRouter: () => mockRouter,
}))

vi.mock("@/actions/redirect", () => ({
navigate: (url: string) => mockLink(url),
}))

vi.mock("@/actions/search", () => ({
initialSearchAction: async (query: string) => {
return query
},
clearSearches: () => {},
}))

test("Render History and Search PopUp Test", async () => {
render(<InputBar history={mockHistoryTest} />)

fireEvent.change(screen.getByPlaceholderText("Search for a topic..."), {
target: { value: "test" },
})

act(() => {
screen.getByRole("listitem", { name: "" }).click()
})

expect(screen.getByText("Historial")).toBeInTheDocument()
expect(screen.getByText("Nueva busqueda")).toBeInTheDocument()
})

test("Search History Click Test", async () => {
render(<InputBar history={mockHistoryTest} />)

fireEvent.change(screen.getByPlaceholderText("Search for a topic..."), {
target: { value: "test" },
})

act(() => {
screen.getByRole("listitem", { name: "" }).click()
})

act(() => {
screen.getByText("Historial").click()
})

expect(mockRouter.push).toHaveBeenCalledWith("/history/1")
})
test("New Search Click Test", async () => {
render(<InputBar history={mockHistoryTest} />)

fireEvent.change(screen.getByPlaceholderText("Search for a topic..."), {
target: { value: "test" },
})

act(() => {
screen.getByRole("listitem", { name: "" }).click()
})

act(() => {
screen.getByText("Nueva busqueda").click()
})

expect(mockLink).toHaveBeenCalledWith("test")
})
50 changes: 50 additions & 0 deletions knowx/src/tests/history/checkUserMenu.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//Test for the render and redirect correct options on the UserMenu - Carolina González A01284948
import { test, expect } from "vitest"
import { screen, render } from "@testing-library/react"
import Header from "@/components/Header"
import { act } from "react"
import { SessionProvider } from "next-auth/react"

test("Check User Menu on Dashboard", async () => {
render(
<SessionProvider
session={{
user: {
email: "[email protected]",
name: "Test User",
},
expires: "",
}}
>
<Header isDashboard={true} />
</SessionProvider>,
)

act(() => {
screen.getByRole("button", { name: "" }).click()
})

expect(screen.getByText("History")).toBeVisible()
})

test("Check User Menu on History", async () => {
render(
<SessionProvider
session={{
user: {
email: "[email protected]",
name: "Test User",
},
expires: "",
}}
>
<Header isDashboard={false} />
</SessionProvider>,
)

act(() => {
screen.getByRole("button", { name: "" }).click()
})

expect(screen.getByText("Dashboard")).toBeVisible()
})
65 changes: 65 additions & 0 deletions knowx/src/tests/mocks/mock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,69 @@
import { SimpleHistoryType } from "@/interfaces"
import { CardProps } from "@/components/Compare/Compare_Card"
import { ResultsTableProps } from "@/interfaces/Phase3"

export const mockResultsTable: ResultsTableProps = {
results: {
results: [
{
Name: "TestColumn",
Description: "DescriptionTest",
Categories: [
{ Name: "Name", Value: "TestColumn" },
{ Name: "Price", Value: "100" },
{ Name: "NewColumn", Value: "NewValue" },
],
},
],
categories: ["Name", "Price", "NewColumn"],
},
}

export const mockCardProps: CardProps = {
initialTitle: "test",
initialDescription: "InitialDescription",
initialData: [
{
Name: "initialDataName",
Value: "initialDataValue",
},
],
titles: ["test", "titles2"],
allData: {
categories: ["Name", "Price"],
results: [
{
Name: "titles2",
Description: "Description2",
Categories: [
{ Name: "Name", Value: "titles2" },
{ Name: "Price", Value: "Price2" },
],
},
],
},
}

export const mockHistoryTest: SimpleHistoryType[] = [
{
id: 1,
search: "test",
timestamp: new Date("2021-01-01"),
feedback: -1,
},
{
id: 352,
search: "top",
timestamp: new Date("2021-01-02"),
feedback: 0,
},
{
id: 3,
search: "new",
timestamp: new Date("2021-01-03"),
feedback: 1,
},
]

export const mockHistory: SimpleHistoryType[] = [
{
Expand Down
32 changes: 32 additions & 0 deletions knowx/src/tests/resultsTable/resultsTable.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//Test for the render of a new column in the results table - Carolina González A01284948
import { test, expect } from "vitest"
import { screen, render } from "@testing-library/react"
import { mockResultsTable } from "../mocks/mock"
import P3_ResultsTable from "@/components/Phase3/P3_ResultsTable"
import { act } from "react"

vi.mock("@/actions/compare", () => ({
toggleCompares: () => {
return
},
}))

test("Show new column render test ", async () => {
render(<P3_ResultsTable incoming_results={mockResultsTable.results} />)

expect(screen.getByText("Columns")).toBeVisible()

act(() => {
screen.getByRole("button", { name: /columns/i }).click()
})

act(() => {
screen
.getByRole("menuitemcheckbox", {
name: /NewColumn/i,
})
.click()
})

expect(screen.getByText("NewColumn")).toBeInTheDocument()
})

0 comments on commit ebc8b71

Please sign in to comment.