@@ -7,16 +7,13 @@ import VideoPlayerContainer from './VideoPlayerContainer';
77import { fireEvent , getByTestId } from '@testing-library/dom' ;
88import AppContext from '../../providers/AppContext' ;
99
10+
1011global . YT = YTMockedObject ;
12+ const FAVORITES_KEY = "favorites" ;
1113const EXPECTED_LENGHT = 3
1214const contextValueVideosList = youtubeMockedData . items . slice ( 0 , EXPECTED_LENGHT ) ;
1315
1416const build = async ( Component = < VideoPlayerContainer videosList = { contextValueVideosList } /> , video ) => {
15-
16- beforeEach ( ( ) => {
17- window . localStorage . clear ( ) ;
18- } ) ;
19-
2017 const contextValue = { search : jest . fn , theme : lightTheme } ;
2118 let container ;
2219 let routeWrap ;
@@ -54,7 +51,6 @@ describe('VideoPlayerContainer', () => {
5451 } ) ;
5552
5653 it ( 'adds/removes to favorites and "Add favorite" / "Remove favorite" in button ' , async ( ) => {
57- const FAVORITES_KEY = "favorites" ;
5854 const savedVideo = contextValueVideosList [ 0 ] ;
5955 const built = ( await build ( < VideoPlayerContainer videosList = { contextValueVideosList } /> , savedVideo ) ) ;
6056 const { addFavoriteButton } = built ;
@@ -78,7 +74,6 @@ describe('VideoPlayerContainer', () => {
7874 } ) ;
7975
8076 it ( 'adds/removes video to existing in localStorage' , async ( ) => {
81- const FAVORITES_KEY = "favorites" ;
8277 const firstVideo = contextValueVideosList [ 1 ] ;
8378 const savedVideo = contextValueVideosList [ 0 ] ;
8479 window . localStorage . setItem ( FAVORITES_KEY , JSON . stringify ( { [ firstVideo . id . videoId ] : firstVideo } ) ) ;
@@ -95,7 +90,7 @@ describe('VideoPlayerContainer', () => {
9590 } ) ;
9691
9792 it ( 'adds/removes favorite clicking related video favorite button ' , async ( ) => {
98- const FAVORITES_KEY = "favorites" ;
93+ window . localStorage . clear ( ) ;
9994 const savedVideo = contextValueVideosList [ 0 ] ;
10095 const built = ( await build ( < VideoPlayerContainer videosList = { contextValueVideosList } /> , savedVideo ) ) ;
10196 const { container } = built ;
@@ -105,20 +100,11 @@ describe('VideoPlayerContainer', () => {
105100
106101 let favorites = window . localStorage . getItem ( FAVORITES_KEY ) ;
107102 const parsedSavedVideo = JSON . parse ( favorites ) [ savedVideo . id . videoId ] ;
108-
109103 expect ( Object . keys ( JSON . parse ( favorites ) ) ) . toHaveLength ( 1 ) ;
110104 expect ( JSON . stringify ( parsedSavedVideo ) ) . toEqual ( JSON . stringify ( savedVideo ) ) ;
111- expect ( captionAddFavorite . textContent ) . toBe ( "Remove favorite" ) ;
112-
113- fireEvent . click ( captionAddFavorite ) ;
114-
115- favorites = window . localStorage . getItem ( FAVORITES_KEY ) ;
116- expect ( Object . keys ( JSON . parse ( favorites ) ) ) . toHaveLength ( 0 ) ;
117- expect ( captionAddFavorite . textContent ) . toBe ( "Add favorite" ) ;
118105 } ) ;
119106
120107 it ( 'adds/removes video to existing clicking related video favorite button' , async ( ) => {
121- const FAVORITES_KEY = "favorites" ;
122108 const firstVideo = contextValueVideosList [ 1 ] ;
123109 const secondVideo = contextValueVideosList [ 0 ] ;
124110 window . localStorage . setItem ( FAVORITES_KEY , JSON . stringify ( { [ firstVideo . id . videoId ] : firstVideo } ) ) ;
0 commit comments