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 #157 from Arquisoft/develop
Develop - addition of testing
- Loading branch information
Showing
9 changed files
with
186 additions
and
10 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
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,14 @@ | ||
import React from 'react' | ||
import { render, screen } from '@testing-library/react'; | ||
import NavBar from './NavBar'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
|
||
test("Review view is rendered properly", async () => { | ||
|
||
render(<MemoryRouter><NavBar cart={[]}></NavBar></MemoryRouter>); | ||
expect(screen.getByAltText('DeDe logo.')).toBeInTheDocument(); | ||
expect(screen.getByPlaceholderText('Search Items...')).toBeInTheDocument(); | ||
expect(screen.getByTestId('submitButton')).toBeInTheDocument(); | ||
expect(screen.getByTestId('account-icon')).toBeInTheDocument(); | ||
expect(screen.getByTestId('cart-icon')).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,18 @@ | ||
import React from 'react' | ||
import {render, screen } from '@testing-library/react'; | ||
import DeveloperCards from './DeveloperCards'; | ||
|
||
test("DevelopersCard is rendered properly", async () =>{ | ||
|
||
render(<DeveloperCards></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(); | ||
expect(screen.getByText('Miguel Cuesta Martínez')).toBeInTheDocument(); | ||
expect(screen.getByText('Daniel Álvarez Díaz')).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
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,19 @@ | ||
import React from 'react' | ||
import { render, screen } from '@testing-library/react'; | ||
import { Review } from '../../shared/shareddtypes'; | ||
import ReviewView from './ReviewView'; | ||
const reviewTest: Review = { | ||
userId: "dummy", | ||
productId: "prod1", | ||
rating: 5, | ||
comment: "testing1", | ||
orderId: "order1" | ||
} | ||
test("Review view is rendered properly", async () => { | ||
|
||
render(<ReviewView review={reviewTest}></ReviewView>); | ||
expect(screen.getByText('dummy')).toBeInTheDocument(); | ||
expect(screen.getByText('"testing1"')).toBeInTheDocument(); | ||
|
||
|
||
}); |
93 changes: 93 additions & 0 deletions
93
webapp/src/components/products/tests/MainProducts.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,93 @@ | ||
|
||
import { fireEvent, render, screen, waitFor, waitForElementToBeRemoved } from '@testing-library/react'; | ||
import MainProducts from '../MainProducts'; | ||
import * as api from '../../../api/api'; | ||
import { Product } from '../../../shared/shareddtypes'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
|
||
|
||
const fakeProd: Product = {} as Product; | ||
const productsList = [ | ||
{ | ||
"id": "prod1", | ||
"name": "bmw", | ||
"description": "best car ever", | ||
"price": 30, | ||
"image": "", | ||
"category": "", | ||
"reviews": [], | ||
"quantity": 2, | ||
"product": fakeProd, | ||
"_id": "prod1" | ||
|
||
}, { | ||
"id": "prod2", | ||
"name": "nissan", | ||
"description": "nissan good", | ||
"price": 20, | ||
"image": "", | ||
"category": "", | ||
"reviews": [], | ||
"quantity": 2, | ||
"product": fakeProd, | ||
"_id": "prod2", | ||
"color": "yellow" | ||
}, | ||
]; | ||
|
||
test("Filter is rendered properly", async () => { | ||
jest.spyOn(api, "getProductImages").mockImplementation((_id: string): Promise<string[]> => { | ||
return Promise.resolve(["1"]); | ||
}); | ||
//The products are retrieved from the getProducts method of the API. | ||
jest.spyOn(api, "getProducts").mockReturnValue(Promise.resolve([])); | ||
render(<MemoryRouter><MainProducts refreshCartList={() => { | ||
//intentional for testing purposes | ||
}} /> </MemoryRouter>); | ||
|
||
expect(screen.getByText('Loading products!!')).toBeInTheDocument(); | ||
let filter = screen.getByTestId("openFilterBtn"); | ||
expect(filter).toBeInTheDocument(); | ||
fireEvent.click(filter); | ||
// eslint-disable-next-line testing-library/prefer-find-by | ||
await waitFor(() => expect(screen.getByTestId("drawer-filter")).toBeInTheDocument()); | ||
//wait time to load drawer | ||
await new Promise((r) => setTimeout(r, 2000)); | ||
expect(screen.getByText('Color')).toBeInTheDocument(); | ||
expect(screen.getByText('Brand')).toBeInTheDocument(); | ||
expect(screen.getByText('Min Price')).toBeInTheDocument(); | ||
expect(screen.getByText('Max Price')).toBeInTheDocument(); | ||
expect(screen.getByText('Rating')).toBeInTheDocument(); | ||
}); | ||
|
||
test("When listing products the proper function is called", 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[]> => { | ||
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)); | ||
|
||
render(<MemoryRouter><MainProducts refreshCartList={() => { | ||
//intentional for testing purposes | ||
}} /> </MemoryRouter>); | ||
//When we first render the component, it will make an API call to getProducts. | ||
expect(screen.getByText('Loading products!!')).toBeInTheDocument(); | ||
//We neeed to wait for the loader to be removed!!!! | ||
await waitForElementToBeRemoved(() => screen.getByTestId('loader')); | ||
//We make sure getProducts is called | ||
await waitFor(() => expect(mockAPI).toHaveBeenCalledTimes(1)); | ||
|
||
//We check that we can see both products info | ||
expect(screen.getByText('bmw')).toBeInTheDocument(); | ||
expect(screen.getByAltText('bmw')).toBeInTheDocument(); | ||
expect(screen.getByText('nissan')).toBeInTheDocument(); | ||
expect(screen.getByAltText('nissan')).toBeInTheDocument(); | ||
|
||
expect(api.getProductImages).toHaveBeenCalledWith(productsList[0].id); | ||
expect(api.getProductImages).toHaveBeenCalledWith(productsList[1].id); | ||
expect(mockAPI).toHaveBeenCalledWith(""); | ||
}); | ||
|
||
|
||
|
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,19 @@ | ||
import React from 'react' | ||
import { render, screen } from '@testing-library/react'; | ||
import { Review } from '../../../shared/shareddtypes'; | ||
import ReviewView from '../ReviewView'; | ||
const reviewTest: Review = { | ||
userId: "dummy", | ||
productId: "prod1", | ||
rating: 5, | ||
comment: "testing1", | ||
orderId: "order1" | ||
} | ||
test("Review view is rendered properly", async () => { | ||
|
||
render(<ReviewView review={reviewTest}></ReviewView>); | ||
expect(screen.getByText('dummy')).toBeInTheDocument(); | ||
expect(screen.getByText('"testing1"')).toBeInTheDocument(); | ||
|
||
|
||
}); |