From 69028b929ba797888208ceec88fde241aed967c4 Mon Sep 17 00:00:00 2001 From: Louison PARANT Date: Fri, 7 Apr 2023 09:07:49 +0200 Subject: [PATCH 1/3] Tests (Failed Test Suite) --- components/__tests__/reducers.test.ts | 121 ++++++++++++++++++++++---- 1 file changed, 104 insertions(+), 17 deletions(-) diff --git a/components/__tests__/reducers.test.ts b/components/__tests__/reducers.test.ts index 4c87609..faabeea 100644 --- a/components/__tests__/reducers.test.ts +++ b/components/__tests__/reducers.test.ts @@ -66,24 +66,111 @@ describe('test ADD_WATCHLATER', () => { }) }) }) + +describe('test LOAD_WATCHLATER', () => { + + let initialState = { + trendingIDs: [], + trendingMovies: [], + watchLaterMovies: [], + favouriteMovies: [], + } + + it('should handle LOAD_WATCHLATER', () => { + const watchLater = new Movie(1, "Test", "", 1, 5, "2023", ["Halloween"], "", "") + const MovieList = [watchLater] + expect( + appReducer(initialState, { + type: LOAD_WATCHLATER, + payload: MovieList, + }) + ).toEqual({ + trendingIDs: [], + trendingMovies: [], + watchLaterMovies: [watchLater, ...initialState.watchLaterMovies], + favouriteMovies: [], + }) + }) +}) + +describe('test LOAD_FAVOURITE', () => { + + let initialState = { + trendingIDs: [], + trendingMovies: [], + watchLaterMovies: [], + favouriteMovies: [], + } + + it('should handle LOAD_FAVOURITE', () => { + const favourite = new Movie(1, "Test", "", 1, 5, "2023", ["Halloween"], "", "") + const MovieList = [favourite] + expect( + appReducer(initialState, { + type: LOAD_FAVOURITE, + payload: MovieList, + }) + ).toEqual({ + trendingIDs: [], + trendingMovies: [], + watchLaterMovies: [], + favouriteMovies: [favourite, ...initialState.favouriteMovies], + }) + }) +}) + +describe('test FETCH_TRENDING_MOVIE', () => { + + let initialState = { + trendingIDs: [], + trendingMovies: [], + watchLaterMovies: [], + favouriteMovies: [], + } + + it('should handle FETCH_TRENDING_MOVIE', () => { + const trending = new Movie(1, "Test", "", 1, 5, "2023", ["Halloween"], "", "") + const MovieList = [trending] + expect( + appReducer(initialState, { + type: FETCH_TRENDING_MOVIE, + payload: MovieList, + }) + ).toEqual({ + trendingIDs: [], + trendingMovies: [trending, ...initialState.trendingMovies], + watchLaterMovies: [], + favouriteMovies: [], + }) + }) +}) + +describe('test POP_FIRST_TRENDING', () => { + + const trending = new Movie(1, "Test", "", 1, 5, "2023", ["Halloween"], "", "") + + let initialState = { + trendingIDs: [], + trendingMovies: [trending], + watchLaterMovies: [], + favouriteMovies: [], + } + + it('should handle POP_FIRST_TRENDING', () => { + expect( + appReducer(initialState, { + type: POP_FIRST_TRENDING, + payload: trending, + }) + ).toEqual({ + trendingIDs: [], + trendingMovies: [...initialState.trendingMovies.filter((item: Movie) => item !== trending)], + watchLaterMovies: [], + favouriteMovies: [], + }) + }) +}) /* - case LOAD_WATCHLATER: - // @ts-ignore - return {...state, watchLaterMovies: action.payload}; - case LOAD_FAVOURITE: - // @ts-ignore - return {...state, favouriteMovies: action.payload}; - case FETCH_TRENDING_ID: - // @ts-ignore - return {...state, trendingIDs: action.payload}; - case FETCH_WATCHLATER: - // @ts-ignore - return {...state, watchLaterMovies: action.payload}; - case FETCH_FAVOURITE: - // @ts-ignore - return {...state, favouriteMovies: action.payload}; - case FETCH_TRENDING_MOVIE: - return {...state, trendingMovies: action.payload}; case POP_FIRST_TRENDING: return {...state, trendingMovies: [...state.trendingMovies.filter((item: Movie) => item !== action.payload)]}; */ \ No newline at end of file From 02a421e1253e2d070c0bae4fecaa25d23fa47a91 Mon Sep 17 00:00:00 2001 From: Louison PARANT Date: Fri, 7 Apr 2023 09:14:36 +0200 Subject: [PATCH 2/3] Tests (Failed Test Suite) --- components/__tests__/reducers.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/__tests__/reducers.test.ts b/components/__tests__/reducers.test.ts index faabeea..5f451c3 100644 --- a/components/__tests__/reducers.test.ts +++ b/components/__tests__/reducers.test.ts @@ -1,5 +1,5 @@ import Movie from "../../model/Movie" -import {describe, expect, test} from '@jest/globals' +import {describe, expect} from '@jest/globals' import appReducer from "../../redux/reducers/appReducer" import {ADD_FAVOURITE, ADD_WATCHLATER, FETCH_TRENDING_MOVIE, LOAD_FAVOURITE, LOAD_WATCHLATER, POP_FIRST_TRENDING} from "../../redux/constants" From b8fda522d7da48e6a2bca9f08f5d806e4d64fbfc Mon Sep 17 00:00:00 2001 From: Lucas Delanier Date: Sat, 8 Apr 2023 15:06:47 +0200 Subject: [PATCH 3/3] last test --- components/__tests__/reducers.test.ts | 4 ---- redux/reducers/appReducer.ts | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/components/__tests__/reducers.test.ts b/components/__tests__/reducers.test.ts index 5f451c3..c2b4a49 100644 --- a/components/__tests__/reducers.test.ts +++ b/components/__tests__/reducers.test.ts @@ -170,7 +170,3 @@ describe('test POP_FIRST_TRENDING', () => { }) }) }) -/* - case POP_FIRST_TRENDING: - return {...state, trendingMovies: [...state.trendingMovies.filter((item: Movie) => item !== action.payload)]}; -*/ \ No newline at end of file diff --git a/redux/reducers/appReducer.ts b/redux/reducers/appReducer.ts index fd953ca..d3ac46f 100644 --- a/redux/reducers/appReducer.ts +++ b/redux/reducers/appReducer.ts @@ -3,7 +3,7 @@ import Movie from "../../model/Movie"; const initialState = { trendingIDs: [], - trendingMovies: [], + trendingMovies: [] as Movie[], watchLaterMovies: [] as Movie[], favouriteMovies: [] as Movie[], }