Skip to content

Commit

Permalink
Merge 9c0e8d8 into 5e445d0
Browse files Browse the repository at this point in the history
  • Loading branch information
abayo-luc committed May 7, 2019
2 parents 5e445d0 + 9c0e8d8 commit 100f1c1
Show file tree
Hide file tree
Showing 49 changed files with 2,018 additions and 406 deletions.
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ cache:
- node_modules
install:
- npm install
before_script:
- yarn
script:
- yarn test:u
- npm test -- -u
after_success:
- yarn run coveralls
- npm run coveralls
- "stable"
notifications:
email: false
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@
"isomorphic-fetch": "^2.2.1",
"jest": "^24.7.1",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.11",
"node-sass": "^4.11.0",
"prop-types": "^15.7.2",
"query-string": "^6.5.0",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-html-parser": "^2.0.2",
Expand Down
8 changes: 3 additions & 5 deletions src/__tests__/__actions__/authActions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe("Login action creators", () => {
},
{
type: LOGIN_SUCCESS,
payload: { ...payload }
payload
},
{
type: SET_CURRENT_USER,
Expand All @@ -85,15 +85,13 @@ describe("Login action creators", () => {
},
{
type: LOGIN_FAILED,
payload: { ...payload }
payload
}
];

moxios.stubRequest(`${API_URL}/users/login`, {
status: 400,
response: {
...payload
}
response: payload
});

return store.dispatch(handleSignIn({ ...data })).then(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/__actions__/createArticle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dotenv.config();
const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);

const BASE_URL = process.env.API_BASE_URL;
const BASE_URL = process.env.API_URL;
describe("article action creators", () => {
test("should return the on input change action", () => {
const data = {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/__actions__/readArticleAction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);

const BASE_URL = process.env.API_BASE_URL;
const BASE_URL = process.env.API_URL;
describe("fetching article", () => {
test("should return fetching article action", () => {
expect(fetchingArticle()).toEqual({ type: FETCHING_ARTICLE });
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/__actions__/resetPasswordActions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe("ResetPassword action creators", () => {
},
{
type: RESET_PASSWORD_LINK_SUCCESS,
payload: { ...payload }
payload
}
];

Expand All @@ -78,7 +78,7 @@ describe("ResetPassword action creators", () => {
},
{
type: RESET_PASSWORD_LINK_FAILED,
payload: { ...payload }
payload
}
];

Expand Down
179 changes: 179 additions & 0 deletions src/__tests__/__actions__/searchActions.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
import thunk from "redux-thunk";
import storeConfig from "redux-mock-store";
import moxios from "moxios";
import dotenv from "dotenv";
import axios from "../../utils/axios";
import * as actions from "../../redux/actions/searchActions";
import { articles, authors } from "../__mocks__/testData";
import {
SEARCHING_ARTICLES,
SEARCH_QUERY_CHANGE,
ARTICLE_SEARCH_FAILED,
ARTICLE_SEARCH_SUCCESS,
CLEAR_SEARCH_RESULTS,
SET_SUGGESTED_ARTICLES
} from "../../redux/actionTypes";
import { arrayToObject } from "../../utils/helperFunctions";

const keyword = "hello_world";
dotenv.config();
const mockStore = storeConfig([thunk]);
let store;
const push = jest.fn();
const history = {};
const { API_URL } = process.env;

describe("Search Action Creators", () => {
beforeEach(() => {
moxios.install(axios);
history.push = push;
});

afterEach(() => {
moxios.uninstall(axios);
history.push.mockClear();
});

test("should create SEARCH_QUERY_CHANGE", () => {
const value = "hello_search";
const expectedActions = {
type: SEARCH_QUERY_CHANGE,
payload: value
};
expect(actions.handleInputChange(value)).toEqual(expectedActions);
});

test("should dispatch ARTICLE_SEARCH_SUCCESS and clear existing one", () => {
const expectedActions = [
{
type: SEARCHING_ARTICLES
},
{
type: CLEAR_SEARCH_RESULTS
},
{
type: ARTICLE_SEARCH_SUCCESS,
payload: {
articles: arrayToObject(articles, "id"),
authors: arrayToObject(authors, "id")
}
}
];
moxios.stubRequest(`${API_URL}/articles?keyword=${keyword}&page=${1}`, {
status: 200,
response: {
articles
}
});
store = mockStore({});
return store
.dispatch(actions.fetchResults(keyword, undefined, history))
.then(() => {
expect(store.getActions()).toEqual(expectedActions);
expect(history.push).toHaveBeenCalledWith(`/search?keyword=${keyword}`);
});
});

test("should dispatch ARTICLE_SEARCH_SUCCESS to fetch more articles", () => {
const expectedActions = [
{
type: SEARCHING_ARTICLES
},
{
type: ARTICLE_SEARCH_SUCCESS,
payload: {
articles: arrayToObject(articles, "id"),
authors: arrayToObject(authors, "id")
}
}
];
moxios.stubRequest(`${API_URL}/articles?keyword=${keyword}&page=${2}`, {
status: 200,
response: {
articles
}
});
store = mockStore({});
return store.dispatch(actions.fetchResults(keyword, 2)).then(() => {
expect(store.getActions()).toEqual(expectedActions);
expect(history.push).not.toHaveBeenCalledWith(
`/search?keyword=${keyword}`
);
});
});

test("should dispatch ARTICLE_SEARCH_FAILED action creator", () => {
const pageNumber = 1;
const expectedActions = [
{
type: SEARCHING_ARTICLES
},
{
type: ARTICLE_SEARCH_FAILED,
payload: {
message: "Unauthorized"
}
}
];
moxios.stubRequest(`${API_URL}${actions.searchURL(keyword, pageNumber)}`, {
status: 401,
response: {
message: "Unauthorized"
}
});
store = mockStore({});
return store
.dispatch(actions.fetchResults(keyword, pageNumber, history))
.then(() => {
expect(store.getActions()).toEqual(expectedActions);
expect(history.push.mock.calls.length).toBe(1);
});
});

test("should dispatch SET_SUGGESTED_ARTICLES", () => {
const query = "hello world";
const expectedActions = [
{
type: SEARCH_QUERY_CHANGE,
payload: query
},
{
type: SET_SUGGESTED_ARTICLES,
payload: { articles: arrayToObject(articles, "id") }
}
];
moxios.stubRequest(`${API_URL}${actions.searchURL(query)}&limit=${4}`, {
status: 200,
response: {
articles
}
});
store = mockStore({});
return store.dispatch(actions.authSuggestArticles(query)).then(() => {
expect(store.getActions()).toEqual(expectedActions);
});
});

test("should dispatch ARTICLE_SEARCH_FAILED ", () => {
const query = "hello world";
const payload = { message: "Unknown error occurred" };
const expectedActions = [
{
type: SEARCH_QUERY_CHANGE,
payload: query
},
{
type: ARTICLE_SEARCH_FAILED,
payload
}
];
moxios.stubRequest(`${API_URL}${actions.searchURL(query)}&limit=${4}`, {
status: 500,
response: payload
});
store = mockStore({});
return store.dispatch(actions.authSuggestArticles(query)).then(() => {
expect(store.getActions()).toEqual(expectedActions);
});
});
});
4 changes: 2 additions & 2 deletions src/__tests__/__actions__/updatePasswordActions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe("update password actions ceators", () => {
},
{
type: PASSWORD_UPDATE_FAILED,
payload: { ...payload }
payload
}
];
return store
Expand Down Expand Up @@ -82,7 +82,7 @@ describe("update password actions ceators", () => {
},
{
type: PASSWORD_UPDATE_SUCCESS,
payload: { ...payload }
payload
}
];
return store
Expand Down
31 changes: 31 additions & 0 deletions src/__tests__/__components__/AppBars/CategoryBar.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from "react";
import { shallow } from "enzyme";
import toJson from "enzyme-to-json";
import CategoryBar from "../../../components/common/AppBars/CategoryBar";

const props = {
catList: ["Art"],
onClick: jest.fn(),
onMoreClick: jest.fn(),
suggestedArticles: {}
};
const wrapper = shallow(<CategoryBar {...props} />);

describe("Category Bar Component", () => {
test("should match the snapshot", () => {
expect(toJson(wrapper)).toMatchSnapshot();
});

test("should response to onClick", () => {
wrapper
.find(`[data-test="btn-more"]`)
.at(0)
.simulate("click");
expect(props.onMoreClick).toBeCalled();
wrapper
.find(`[data-test="single-category"]`)
.at(0)
.simulate("click");
expect(props.onClick).toBeCalled();
});
});
Loading

0 comments on commit 100f1c1

Please sign in to comment.