Skip to content

Commit

Permalink
Merge pull request #164 from Arquisoft/develop
Browse files Browse the repository at this point in the history
Develop - adding refactoring of tests done by Miguel and removal of code smells
  • Loading branch information
sebaslh01 authored May 2, 2022
2 parents d31ed27 + a48aeae commit cb0ff4b
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react'
import { render, screen } from '@testing-library/react';
import NavBar from './NavBar';
import NavBar from '../NavBar';
import { MemoryRouter } from 'react-router-dom';

test("Review view is rendered properly", async () => {
Expand Down
10 changes: 10 additions & 0 deletions webapp/src/components/fragments/tests/PageNotFound.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { render, screen } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import PageNotFound from '../PageNotFound';

test("Review view is rendered properly", async () => {

render(<MemoryRouter><PageNotFound/></MemoryRouter>);
expect(screen.getByText("SORRY")).toBeInTheDocument();
expect(screen.getByText("We couldn't find the page you're looking for!!")).toBeInTheDocument();
});
3 changes: 1 addition & 2 deletions webapp/src/components/other/DeveloperCards.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as React from 'react';
import Card from '@mui/material/Card';
import CardContent from '@mui/material/CardContent';
import CardMedia from '@mui/material/CardMedia';
import Typography from '@mui/material/Typography';
import { Button, CardActionArea, CardActions, Grid } from '@mui/material';
import { CardActionArea, Grid } from '@mui/material';
import { Box } from '@mui/system';

export default function MultiActionAreaCard() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React from 'react'
import {render, screen } from '@testing-library/react';
import DeveloperCards from './DeveloperCards';
import DeveloperCards from '../DeveloperCards';

test("DevelopersCard is rendered properly", async () =>{

render(<DeveloperCards></DeveloperCards>);
render(<DeveloperCards/>);
expect(screen.getByText('Luis Miguel Alonso Ferreiro')).toBeInTheDocument();
expect(screen.getByText('Sebastián López Hernández')).toBeInTheDocument();
expect(screen.getByText('Jesús González Méndez')).toBeInTheDocument();
Expand Down
21 changes: 21 additions & 0 deletions webapp/src/components/other/tests/about_us.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { render } from "@testing-library/react";
import { BrowserRouter as Router } from "react-router-dom";

import AboutUs from "../about_us";

/**
* Test that the about us page renders correctly
*/
test("Cart empty is rendered correctly", async () => {

const { getByText } = render(
<Router>
<AboutUs/>
</Router>
)

// The expected content of the page (cards aside)
expect(getByText("Decentralized Delivery")).toBeInTheDocument();
expect(getByText("DeDe is an online retail system that preserves the privacy of the customers following the SOLID principles. This means that our Decentralized Delivery app will not store user data per se, but will acess, when permission is granted, the information located inside the user's SOLID pod. This information will be used by our app to know the user's address for delivery purposes.")).toBeInTheDocument();

});
6 changes: 4 additions & 2 deletions webapp/src/components/products/tests/MainProducts.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ test("When listing products the proper function is called", async () => {

test("When listing products, use filter by color works as expected", async () => {
//We need to mock this function as the ProductCard calls it in order to render the img of each product.
jest.spyOn(api, "getProductImages").mockImplementation((id: string): Promise<string[]> => {
jest.spyOn(api, "getProductImages").mockImplementation((_id: string): Promise<string[]> => {
return Promise.resolve(["1"]);
});
//The products are retrieved from the getProducts method of the API.
const mockAPI = jest.spyOn(api, "getProducts").mockReturnValue(Promise.resolve(productsList));

const {container}=render(<MemoryRouter><MainProducts refreshCartList={() => { }} /> </MemoryRouter>);
render(<MemoryRouter><MainProducts refreshCartList={() => {
//intentional testing purpose
}} /> </MemoryRouter>);

//We neeed to wait for the loader to be removed!!!!
await waitForElementToBeRemoved(() => screen.getByTestId('loader'));
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/user/AddressForm.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { screen, render, queryByText, waitForElementToBeRemoved } from "@testing-library/react";
import { screen, render } from "@testing-library/react";

import AddressForm from './AddressForm';

Expand Down

0 comments on commit cb0ff4b

Please sign in to comment.