This repository has been archived by the owner on Feb 4, 2024. It is now read-only.
generated from Arquisoft/dede_0
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #160 from Arquisoft/testing
Tests for ProductDetail, OrderDetailProduct, Footer and AboutUs
- Loading branch information
Showing
8 changed files
with
106 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import AboutUs from "./AboutUs"; | ||
import { render, screen} from "@testing-library/react"; | ||
|
||
|
||
test('Check that everything is properly rendered', async () => { | ||
render(<AboutUs/>); | ||
expect(screen.getByText("About us")).toBeInTheDocument(); | ||
expect(screen.getByText("Developer team")).toBeInTheDocument(); | ||
expect(screen.getByText("Diego Martín Fernández")).toBeInTheDocument(); | ||
expect(screen.getByText("Laura Pernía Blanco")).toBeInTheDocument(); | ||
expect(screen.getByText("Stelian Adrian Stanci")).toBeInTheDocument(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {fireEvent, render, screen} from "@testing-library/react"; | ||
import App from "../../App" | ||
|
||
test('Check that everything in the footer is rendered', async () => { | ||
render(<App/>); | ||
expect(screen.getByText("Code")).toBeInTheDocument(); | ||
expect(screen.getByText("Documentation")).toBeInTheDocument(); | ||
expect(screen.getByText("About Us")).toBeInTheDocument(); | ||
expect(screen.getByText("SOLID")).toBeInTheDocument(); | ||
}); | ||
|
||
test('Check that About Us link works at takes the user to About us page', async () => { | ||
render(<App/>); | ||
let aboutUs = screen.getByTestId("aboutUsLink"); | ||
fireEvent.click(aboutUs); | ||
expect(screen.getByText("Developer team")).toBeInTheDocument(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {ProductType} from "../shared/shareddtypes"; | ||
import ListProducts from "./ListProducts"; | ||
import {render, screen, waitForElementToBeRemoved} from "@testing-library/react"; | ||
|
||
const testProductList:ProductType[] = [{id:1, name:"Watermelon", category:"Fruit", price:3.45, | ||
image:"https://images.unsplash.com/photo-1629084092232-b7b3fa74cd4b?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=764&q=80", | ||
description: "Rica sandia" }, | ||
{id:2, name:"Salmon", category:"Fish", price:5.55, | ||
image:"https://images.unsplash.com/photo-1499125562588-29fb8a56b5d5?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1332&q=80", | ||
description: "Salmon description" } | ||
]; | ||
|
||
test("Check that products are correctly rendered", async () => { | ||
///////// We need to change the implementation of ListProduct | ||
//jest.spyOn(api, "useFetch").mockReturnValue(Promise.resolve(testProductList)); | ||
//render(<ListProducts/>) | ||
|
||
//await waitForElementToBeRemoved(() => screen.getByTestId('loadingProduct')); | ||
//expect(screen.getByText("Watermelon - 3.45€")).toBeInTheDocument(); | ||
//expect(screen.getByText("Rica sandia")).toBeInTheDocument(); | ||
}); |
21 changes: 21 additions & 0 deletions
21
webapp/src/components/PastOrders/OrderDetailProduct.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import OrderDetailProduct from "./OrderDetailProduct"; | ||
import { render, screen} from "@testing-library/react"; | ||
import {OrderProduct, ProductType} from "../../shared/shareddtypes"; | ||
|
||
const testProduct:ProductType = {id:1, name:"Watermelon", category:"Fruit", price:1.25, | ||
image:"https://images.unsplash.com/photo-1629084092232-b7b3fa74cd4b?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=764&q=80", | ||
description: "Rica sandia" }; | ||
|
||
const testOrderProduct:OrderProduct = {id:1, quantity:2, price:1.25, product:testProduct, order:undefined!}; | ||
|
||
test('Check that order product is properly rendered and total', async () => { | ||
render(<OrderDetailProduct item={testOrderProduct}/>); | ||
expect(screen.getByText(testProduct.name)).toBeInTheDocument(); | ||
expect(screen.getByText("Units: " + testOrderProduct.quantity)).toBeInTheDocument(); | ||
expect(screen.getByText(testOrderProduct.price + "€")).toBeInTheDocument(); | ||
}); | ||
|
||
test('Check that subtotal of this product is correctly calculated', async () => { | ||
render(<OrderDetailProduct item={testOrderProduct}/>); | ||
expect(screen.getByText(testOrderProduct.price * testOrderProduct.quantity + "€")).toBeInTheDocument(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import * as api from "../api/api"; | ||
import {ProductType, RatingType} from "../shared/shareddtypes"; | ||
import ProductDetail from "./ProductDetail"; | ||
import {render, screen, waitForElementToBeRemoved} from "@testing-library/react"; | ||
|
||
const testProduct:ProductType = {id:1, name:"Watermelon", category:"Fruit", price:3.45, | ||
image:"https://images.unsplash.com/photo-1629084092232-b7b3fa74cd4b?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=764&q=80", | ||
description: "Rica sandia" }; | ||
|
||
const testRating:RatingType[] = [{user:"WatermelonLover", comment:"Nice watermelon", rating:0.9, product:testProduct}, | ||
{user:"Laura", comment:"Bad watermelon", rating:0.1, product:testProduct}] | ||
|
||
test("Check that the details view of a product is renderer properly", async () => { | ||
jest.spyOn(api, "getProductById").mockReturnValue(Promise.resolve(testProduct)); | ||
render(<ProductDetail/>) | ||
|
||
await waitForElementToBeRemoved(() => screen.getByTestId('loadingProduct')); | ||
expect(screen.getByText("Watermelon - 3.45€")).toBeInTheDocument(); | ||
expect(screen.getByText("Rica sandia")).toBeInTheDocument(); | ||
}); | ||
|
||
test("Check that reviews of a product are rendered correctly", async () => { | ||
jest.spyOn(api, "getProductById").mockReturnValue(Promise.resolve(testProduct)); | ||
jest.spyOn(api, "getRatingsForProduct").mockReturnValue(Promise.resolve(testRating)); | ||
render(<ProductDetail/>) | ||
|
||
await waitForElementToBeRemoved(() => screen.getByTestId('loadingProduct')); | ||
expect(screen.getByText("Nice watermelon")).toBeInTheDocument(); | ||
expect(screen.getByText("WatermelonLover")).toBeInTheDocument(); | ||
expect(screen.getByText("Bad watermelon")).toBeInTheDocument(); | ||
expect(screen.getByText("Laura")).toBeInTheDocument(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters