Skip to content

Commit a93c38e

Browse files
committed
chore: Move showLoading to saga and test it
1 parent 3537eba commit a93c38e

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/amo/components/Categories.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, { PropTypes } from 'react';
22
import { connect } from 'react-redux';
33
import { compose } from 'redux';
4-
import { showLoading } from 'react-redux-loading-bar';
54

65
import Link from 'amo/components/Link';
76
import { categoriesFetch } from 'core/actions/categories';
@@ -26,7 +25,6 @@ export class CategoriesBase extends React.Component {
2625
componentWillMount() {
2726
const { addonType, categories, clientApp, dispatch } = this.props;
2827
if (!Object.values(categories).length) {
29-
dispatch(showLoading());
3028
dispatch(categoriesFetch({ addonType, clientApp }));
3129
}
3230
}

src/amo/sagas/categories.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { hideLoading } from 'react-redux-loading-bar';
1+
import { hideLoading, showLoading } from 'react-redux-loading-bar';
22
import { call, put, select, takeEvery } from 'redux-saga/effects';
33

44
import {
@@ -14,12 +14,14 @@ import { getApi } from './utils';
1414
// worker Saga: will be fired on every CATEGORIES_FETCH action.
1515
export function* fetchCategories() {
1616
try {
17+
yield put(showLoading());
1718
const api = yield select(getApi);
1819
const response = yield call(categoriesApi, { api });
1920
yield put(categoriesLoad(response));
20-
yield put(hideLoading());
21+
// yield put(hideLoading());
2122
} catch (err) {
2223
yield put(categoriesFail(err));
24+
} finally {
2325
yield put(hideLoading());
2426
}
2527
}

tests/client/amo/sagas/testCategories.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { hideLoading } from 'react-redux-loading-bar';
1+
import { hideLoading, showLoading } from 'react-redux-loading-bar';
22
import { call, put, select, takeEvery } from 'redux-saga/effects';
33

44
import categoriesSaga, { fetchCategories } from 'amo/sagas/categories';
@@ -15,6 +15,10 @@ describe('categoriesSaga', () => {
1515
const fetchCategoriesGenerator = fetchCategories();
1616

1717
let next = fetchCategoriesGenerator.next();
18+
assert.deepEqual(
19+
next.value, put(showLoading()), 'should dispatch show loading bar');
20+
21+
next = fetchCategoriesGenerator.next();
1822
const api = next.value;
1923
assert.deepEqual(api, select(getApi), 'must yield getApi');
2024

@@ -35,6 +39,10 @@ describe('categoriesSaga', () => {
3539
const fetchCategoriesGenerator = fetchCategories();
3640

3741
let next = fetchCategoriesGenerator.next();
42+
assert.deepEqual(
43+
next.value, put(showLoading()), 'should dispatch show loading bar');
44+
45+
next = fetchCategoriesGenerator.next();
3846
const api = next.value;
3947
assert.deepEqual(api, select(getApi), 'must yield getApi');
4048

0 commit comments

Comments
 (0)