Skip to content

Commit 6edb270

Browse files
committed
Changed import methods in tests, for shorter test files. Deleted actions for loading favorite, it was more than needed.
1 parent c42d853 commit 6edb270

File tree

10 files changed

+239
-319
lines changed

10 files changed

+239
-319
lines changed

.eslintcache

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/components/market-details/MarketDetails.jsx

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717

1818
import AddSrc from "assets/bookmarkEmpty.svg";
1919
import AddedSrc from "assets/bookmark.svg";
20-
import SpinnerSrc from "assets/spinner.svg";
2120

2221
import ErrorFallback from "components/error-fallback/ErrorFallback";
2322
import DetailsTable from "components/details-table/DetailsTable";
@@ -32,7 +31,7 @@ import { MarketDetailsContainer } from "./MarketDetails.styles";
3231

3332
const MarketDetails = () => {
3433
const { marketDetail, chartTimeFrame } = useSelector((state) => state.chart);
35-
const { favorites, loadingFavorite } = useSelector((state) => state.favorite);
34+
const { favorites } = useSelector((state) => state.favorite);
3635
const { user } = useSelector((state) => state.user);
3736

3837
const timeFrames = ["5min", "15min", "30min", "1hour"];
@@ -50,13 +49,7 @@ const MarketDetails = () => {
5049
}, [user.name, dispatch, favorites.length]);
5150

5251
const add = <img src={AddSrc} alt="empty bookmark" />;
53-
const added = (
54-
<img
55-
src={loadingFavorite ? SpinnerSrc : AddedSrc}
56-
alt="added favorite, filled bookmark"
57-
/>
58-
);
59-
// const spinner = <img src={SpinnerSrc} alt="spinner for loading favorite" />;
52+
const added = <img src={AddedSrc} alt="added favorite, filled bookmark" />;
6053

6154
const handleClick = () => {
6255
// First, checking the length
@@ -91,10 +84,7 @@ const MarketDetails = () => {
9184
{add}
9285
</Link>
9386
) : (
94-
<FavoriteButton
95-
onClick={() => handleClick()}
96-
favorite={loadingFavorite}
97-
>
87+
<FavoriteButton onClick={() => handleClick()}>
9888
{favorites.some(
9989
(favorite) => favorite.symbol[0].symbol === marketDetail.symbol
10090
)

src/redux/actions/favorite.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ export const ADD_FAVORITE = "ADD_FAVORITE";
1111
export const DELETE_FAVORITE = "DELETE_FAVORITE";
1212
export const FETCH_FAVORITE_ERROR = "FETCH_FAVORITE_ERROR";
1313
export const CLEAN_FAVORITE_STATE = "CLEAN_FAVORITE_STATE";
14-
export const LOADING_FAVORITE = "LOADING_FAVORITE";
15-
export const LOADING_FAVORITE_END = "LOADING_FAVORITE_END";
1614

1715
export const getFavorite = (stock) => ({
1816
type: GET_FAVORITE,
@@ -38,14 +36,6 @@ export const cleanFavoriteState = () => ({
3836
type: CLEAN_FAVORITE_STATE,
3937
});
4038

41-
export const setLoadingFavorite = () => ({
42-
type: LOADING_FAVORITE,
43-
});
44-
45-
export const setLoadingFavoriteEnd = () => ({
46-
type: LOADING_FAVORITE_END,
47-
});
48-
4939
export const fetchGetFavorites = () => async (dispatch) => {
5040
const token = JSON.parse(localStorage.getItem("token"));
5141

@@ -72,14 +62,11 @@ export const fetchAddFavorites = (stock) => async (dispatch) => {
7262
headers: { Authorization: `Bearer ${token}` },
7363
};
7464

75-
dispatch(setLoadingFavorite());
76-
7765
try {
7866
const response = await axios.post(`${url}/`, favoriteStock, config);
7967
const data = await response.data;
8068
return [
8169
dispatch(addFavorite(data.symbol[0])),
82-
// dispatch(setLoadingFavoriteEnd()),
8370
toaster.notify(
8471
() => (
8572
<NotificationComponent

src/redux/reducers/favorite.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import * as FavoriteActions from "redux/actions/favorite";
33
const initialState = {
44
errorFavorite: null,
55
favorites: [],
6-
loadingFavorite: false,
76
};
87

98
const favoriteReducer = (state = initialState, action) => {
@@ -35,16 +34,6 @@ const favoriteReducer = (state = initialState, action) => {
3534
...state,
3635
favorites: [],
3736
};
38-
case FavoriteActions.LOADING_FAVORITE:
39-
return {
40-
...state,
41-
loadingFavorite: true,
42-
};
43-
case FavoriteActions.LOADING_FAVORITE_END:
44-
return {
45-
...state,
46-
loadingFavorite: false,
47-
};
4837
default:
4938
return state;
5039
}

src/tests/redux/actions/news.test.js

Lines changed: 25 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,77 @@
11
import 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

245
import { story, popular, errorNews, width } from "../../fixtures/news";
256

267
import { store } from "../../store";
278

289
test("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

3718
test("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

4627
test("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

5536
test("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

6445
test("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

7253
test("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

8162
test("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

8970
test("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

Comments
 (0)