Skip to content
This repository has been archived by the owner on Feb 4, 2024. It is now read-only.

Commit

Permalink
Tests for Footer and AboutUs (+ skeleton ListProduct)
Browse files Browse the repository at this point in the history
  • Loading branch information
laura-pb committed May 2, 2022
1 parent 5432437 commit 3411885
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 3 deletions.
12 changes: 12 additions & 0 deletions webapp/src/components/About/AboutUs.test.tsx
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();
});
17 changes: 17 additions & 0 deletions webapp/src/components/Footer/Footer.test.tsx
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();
});
2 changes: 1 addition & 1 deletion webapp/src/components/Footer/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const Footer = () => {
</Column>
<Column>
<Link to="/about">
<FooterLink>About Us</FooterLink>
<FooterLink data-testid="aboutUsLink">About Us</FooterLink>
</Link>
</Column>
<Column>
Expand Down
21 changes: 21 additions & 0 deletions webapp/src/components/ListProducts.test.tsx
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();
});
3 changes: 1 addition & 2 deletions webapp/src/shared/shareddtypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ export type OrderProduct = {
}

export type RatingType = {

user: string
comment: string
rating: number
profileImage: string
profileImage?: string
product: ProductType
}

Expand Down

0 comments on commit 3411885

Please sign in to comment.