11import moxios from "moxios" ;
22
3- import {
4- FETCH_POPULAR_SUCCESS ,
5- FETCH_STORY_SUCCESS ,
6- FETCH_NEWS_ERROR ,
7- CHANGE_HEADER ,
8- CLEAR_ERROR ,
9- SET_WIDTH ,
10- OPEN_RESPONSIVE_MENU ,
11- CLOSE_RESPONSIVE_MENU ,
12- fetchPopularSuccess ,
13- fetchStorySuccess ,
14- changeHeader ,
15- fetchNewsError ,
16- clearError ,
17- setWidth ,
18- openResponsiveMenu ,
19- closeResponsiveMenu ,
20- fetchTopStories ,
21- fetchMostPopular ,
22- } from "../../../redux/actions/news" ;
3+ import * as NewsActions from "redux/actions/news" ;
234
245import { story , popular , errorNews , width } from "../../fixtures/news" ;
256
267import { store } from "../../store" ;
278
289test ( "Should get the top stories correctly" , ( ) => {
29- const action = fetchStorySuccess ( story ) ;
10+ const action = NewsActions . fetchStorySuccess ( story ) ;
3011
3112 expect ( action ) . toEqual ( {
32- type : FETCH_STORY_SUCCESS ,
13+ type : NewsActions . FETCH_STORY_SUCCESS ,
3314 payload : story ,
3415 } ) ;
3516} ) ;
3617
3718test ( "Should get the most popular stories correctly" , ( ) => {
38- const action = fetchPopularSuccess ( popular ) ;
19+ const action = NewsActions . fetchPopularSuccess ( popular ) ;
3920
4021 expect ( action ) . toEqual ( {
41- type : FETCH_POPULAR_SUCCESS ,
22+ type : NewsActions . FETCH_POPULAR_SUCCESS ,
4223 payload : popular ,
4324 } ) ;
4425} ) ;
4526
4627test ( "Should show error if there is any" , ( ) => {
47- const action = fetchNewsError ( errorNews ) ;
28+ const action = NewsActions . fetchNewsError ( errorNews ) ;
4829
4930 expect ( action ) . toEqual ( {
50- type : FETCH_NEWS_ERROR ,
31+ type : NewsActions . FETCH_NEWS_ERROR ,
5132 payload : errorNews ,
5233 } ) ;
5334} ) ;
5435
5536test ( "Should change the header" , ( ) => {
56- const action = changeHeader ( "arts" ) ;
37+ const action = NewsActions . changeHeader ( "arts" ) ;
5738
5839 expect ( action ) . toEqual ( {
59- type : CHANGE_HEADER ,
40+ type : NewsActions . CHANGE_HEADER ,
6041 payload : "arts" ,
6142 } ) ;
6243} ) ;
6344
6445test ( "Should clear the error" , ( ) => {
65- const action = clearError ( ) ;
46+ const action = NewsActions . clearError ( ) ;
6647
6748 expect ( action ) . toEqual ( {
68- type : CLEAR_ERROR ,
49+ type : NewsActions . CLEAR_ERROR ,
6950 } ) ;
7051} ) ;
7152
7253test ( "Should set the width of the window" , ( ) => {
73- const action = setWidth ( width ) ;
54+ const action = NewsActions . setWidth ( width ) ;
7455
7556 expect ( action ) . toEqual ( {
76- type : SET_WIDTH ,
57+ type : NewsActions . SET_WIDTH ,
7758 payload : width ,
7859 } ) ;
7960} ) ;
8061
8162test ( "Should open the responsive menu" , ( ) => {
82- const action = openResponsiveMenu ( ) ;
63+ const action = NewsActions . openResponsiveMenu ( ) ;
8364
8465 expect ( action ) . toEqual ( {
85- type : OPEN_RESPONSIVE_MENU ,
66+ type : NewsActions . OPEN_RESPONSIVE_MENU ,
8667 } ) ;
8768} ) ;
8869
8970test ( "Should close the responsive menu" , ( ) => {
90- const action = closeResponsiveMenu ( ) ;
71+ const action = NewsActions . closeResponsiveMenu ( ) ;
9172
9273 expect ( action ) . toEqual ( {
93- type : CLOSE_RESPONSIVE_MENU ,
74+ type : NewsActions . CLOSE_RESPONSIVE_MENU ,
9475 } ) ;
9576} ) ;
9677
@@ -115,11 +96,11 @@ describe("Testing redux-thunk, fetching news", () => {
11596 } ) ;
11697
11798 const expectedActions = {
118- type : FETCH_STORY_SUCCESS ,
99+ type : NewsActions . FETCH_STORY_SUCCESS ,
119100 payload : story . results ,
120101 } ;
121102
122- return store . dispatch ( fetchTopStories ( "home" ) ) . then ( ( ) => {
103+ return store . dispatch ( NewsActions . fetchTopStories ( "home" ) ) . then ( ( ) => {
123104 const actionsGetCalled = store . getActions ( ) ;
124105
125106 expect ( actionsGetCalled [ 0 ] ) . toEqual ( expectedActions ) ;
@@ -133,11 +114,11 @@ describe("Testing redux-thunk, fetching news", () => {
133114 } ) ;
134115
135116 const expectedActions = {
136- type : FETCH_NEWS_ERROR ,
117+ type : NewsActions . FETCH_NEWS_ERROR ,
137118 payload : errorNews ,
138119 } ;
139120
140- return store . dispatch ( fetchTopStories ( "home" ) ) . then ( ( ) => {
121+ return store . dispatch ( NewsActions . fetchTopStories ( "home" ) ) . then ( ( ) => {
141122 const actionsGetCalled = store . getActions ( ) ;
142123
143124 expect ( actionsGetCalled [ 0 ] ) . toEqual ( expectedActions ) ;
@@ -156,11 +137,11 @@ describe("Testing redux-thunk, fetching news", () => {
156137 } ) ;
157138
158139 const expectedActions = {
159- type : FETCH_POPULAR_SUCCESS ,
140+ type : NewsActions . FETCH_POPULAR_SUCCESS ,
160141 payload : popular . results ,
161142 } ;
162143
163- return store . dispatch ( fetchMostPopular ( ) ) . then ( ( ) => {
144+ return store . dispatch ( NewsActions . fetchMostPopular ( ) ) . then ( ( ) => {
164145 const actionsGetCalled = store . getActions ( ) ;
165146
166147 expect ( actionsGetCalled [ 0 ] ) . toEqual ( expectedActions ) ;
@@ -174,11 +155,11 @@ describe("Testing redux-thunk, fetching news", () => {
174155 } ) ;
175156
176157 const expectedActions = {
177- type : FETCH_NEWS_ERROR ,
158+ type : NewsActions . FETCH_NEWS_ERROR ,
178159 payload : errorNews ,
179160 } ;
180161
181- return store . dispatch ( fetchMostPopular ( ) ) . then ( ( ) => {
162+ return store . dispatch ( NewsActions . fetchMostPopular ( ) ) . then ( ( ) => {
182163 const actionsGetCalled = store . getActions ( ) ;
183164
184165 expect ( actionsGetCalled [ 0 ] ) . toEqual ( expectedActions ) ;
0 commit comments