From e8dba82800e2e4ba449b42714725cfaeecfc7dec Mon Sep 17 00:00:00 2001 From: "Santiago.Martinez" <41674380j@institutmontilivi.cat> Date: Sun, 9 May 2021 17:04:44 +0200 Subject: [PATCH] Add some tests --- .../pages/movie-details/MovieDetails.test.js | 33 +++++++++++++++++ .../src/pages/show-detail/showdetails.test.js | 23 ++++++++++++ .../src/pages/tv-shows/Tv_shows.test.js | 37 ------------------- 3 files changed, 56 insertions(+), 37 deletions(-) create mode 100644 00-TEAMS/06-TEAM/src/pages/movie-details/MovieDetails.test.js create mode 100644 00-TEAMS/06-TEAM/src/pages/show-detail/showdetails.test.js delete mode 100644 00-TEAMS/06-TEAM/src/pages/tv-shows/Tv_shows.test.js diff --git a/00-TEAMS/06-TEAM/src/pages/movie-details/MovieDetails.test.js b/00-TEAMS/06-TEAM/src/pages/movie-details/MovieDetails.test.js new file mode 100644 index 0000000000..09b7c02996 --- /dev/null +++ b/00-TEAMS/06-TEAM/src/pages/movie-details/MovieDetails.test.js @@ -0,0 +1,33 @@ +// import React from 'react'; +// import { render, screen } from '../../common/test/index'; +import { getMovieById, getCastMovie, loadRecomended } from '../../application/store/actions/actionsCreator'; + +describe('Given a function getMovieById', () => { + describe('When invoked', () => { + test('Should dispatch LOAD_MOVIE', async () => { + const dispatch = jest.fn(); + await getMovieById('460465')(dispatch); + expect(dispatch).toHaveBeenCalled(); + }); + }); +}); + +describe('Given a function getCastMovie', () => { + describe('When invoked', () => { + test('Should dispatch LOAD_CAST', async () => { + const dispatch = jest.fn(); + await getCastMovie('460465')(dispatch); + expect(dispatch).toHaveBeenCalled(); + }); + }); +}); + +describe('Given a function loadRecomended', () => { + describe('When invoked', () => { + test('Should dispatch LOAD_RECOMENDED', async () => { + const dispatch = jest.fn(); + await loadRecomended('460465')(dispatch); + expect(dispatch).toHaveBeenCalled(); + }); + }); +}); diff --git a/00-TEAMS/06-TEAM/src/pages/show-detail/showdetails.test.js b/00-TEAMS/06-TEAM/src/pages/show-detail/showdetails.test.js new file mode 100644 index 0000000000..f854f39f50 --- /dev/null +++ b/00-TEAMS/06-TEAM/src/pages/show-detail/showdetails.test.js @@ -0,0 +1,23 @@ +// import React from 'react'; +// import { render, screen } from '../../common/test/index'; +import { getShowById, loadRecommendedShows } from '../../application/store/actions/actionsCreator'; + +describe('Given a function getShowById', () => { + describe('When invoked', () => { + test('Should dispatch LOAD_SHOW', async () => { + const dispatch = jest.fn(); + await getShowById('79460')(dispatch); + expect(dispatch).toHaveBeenCalled(); + }); + }); +}); + +describe('Given a function loadRecommendedShows', () => { + describe('When invoked', () => { + test('Should dispatch LOAD_SHOWS_RECOMMENDED', async () => { + const dispatch = jest.fn(); + await loadRecommendedShows('79460')(dispatch); + expect(dispatch).toHaveBeenCalled(); + }); + }); +}); diff --git a/00-TEAMS/06-TEAM/src/pages/tv-shows/Tv_shows.test.js b/00-TEAMS/06-TEAM/src/pages/tv-shows/Tv_shows.test.js deleted file mode 100644 index afc5bbfa2c..0000000000 --- a/00-TEAMS/06-TEAM/src/pages/tv-shows/Tv_shows.test.js +++ /dev/null @@ -1,37 +0,0 @@ -import React from 'react'; -import { render, screen } from '../../common/test'; -import { createStore } from '../../application/store'; -import TvShows from './Tv_shows'; - -const results = [ - { id: 1, poster_path: 'www.google.es', originalTitle: 'SuperFilm 1' }, - { id: 2, poster_path: 'www.google.es', originalTitle: 'SuperFilm 2' }, - { id: 3, poster_path: 'www.google.es', originalTitle: 'SuperFilm 3' } -]; - -export const promisify = (value) => new Promise((resolve) => resolve(value)); - -jest.mock('../../common/services/films', () => ({ - TYPE_PARAMS: { - on_the_air: 'on_the_air' - }, - getShows: () => promisify({ data: { results } }) -})); - -const store = createStore({ - shows: [{ id: 3, poster_path: 'www.google.es', originalTitle: 'SuperFilm' }] -}); - -describe('Footer Component', () => { - test('should contain text Tv_shows', async () => { - render(, { store }); - - const initialFilm = screen.getByAltText('SuperFilm'); - const firstLoadedFilm = await screen.findByAltText('SuperFilm 1'); - const total = await screen.findByText('Total: 4'); - - expect(initialFilm).toBeInTheDocument(); - expect(firstLoadedFilm).toBeInTheDocument(); - expect(total).toBeInTheDocument(); - }); -});