Skip to content

Commit

Permalink
Merge 5af8fc9 into 45e75a3
Browse files Browse the repository at this point in the history
  • Loading branch information
YvesIraguha committed Apr 30, 2019
2 parents 45e75a3 + 5af8fc9 commit 52c540f
Show file tree
Hide file tree
Showing 29 changed files with 1,348 additions and 125 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"sourceType": "module"
},
"eol-last": ["error", "always"],
" global-require": "off",
"import/prefer-default-export": "on",
"import/resolver": {
"node": {
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ yarn.*
yarn-*
.DS_Store
.env
.coveralls.yml
.coveralls.yml

yarn.lock
2 changes: 2 additions & 0 deletions enzyme.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* eslint-disable import/no-extraneous-dependencies */
import { configure } from "enzyme";
import Adapter from "enzyme-adapter-react-16";
import dotenv from "dotenv";

dotenv.config();
configure({ adapter: new Adapter() });
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"prop-types": "^15.7.2",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-html-parser": "^2.0.2",
"react-redux": "^6.0.1",
"react-router-dom": "^5.0.0",
"react-rte": "^0.16.1",
Expand All @@ -60,6 +61,7 @@
"babel-eslint": "^10.0.1",
"babel-jest": "^24.6.0",
"babel-loader": "^8.0.5",
"babel-polyfill": "^6.26.0",
"coveralls": "^3.0.3",
"css-loader": "^2.1.1",
"dotenv-webpack": "^1.7.0",
Expand All @@ -76,6 +78,7 @@
"eslint-plugin-react": "^7.12.4",
"file-loader": "^3.0.1",
"html-webpack-plugin": "^3.2.0",
"jest-cli": "^24.7.1",
"mini-css-extract-plugin": "^0.5.0",
"moxios": "^0.4.0",
"prettier": "^1.16.4",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import moxios from "moxios";
import configureMockStore from "redux-mock-store";
import thunk from "redux-thunk";
import dotenv from "dotenv";
import axios from "../../utils/axios";
import { article } from "../__mocks__/testData";
import {
Expand All @@ -24,10 +25,11 @@ import {
fetchOneArticle
} from "../../redux/actions/newArticle";

dotenv.config();
const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);

const BASE_URL = "http://localhost:3000/api/v1";
const BASE_URL = process.env.API_BASE_URL;
describe("article action creators", () => {
test("should return the on input change action", () => {
const data = {
Expand Down
131 changes: 131 additions & 0 deletions src/__tests__/__actions__/readArticleAction.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import moxios from "moxios";
import configureMockStore from "redux-mock-store";
import thunk from "redux-thunk";
import axios from "../../utils/axios";
import {
fetchingArticle,
fetchArticle,
deleteArticle
} from "../../redux/actions/readArticleActionCreator";
import {
FETCHING_ARTICLE,
FETCHING_ASIDE_ARTICLES,
ARTICLE_FETCHED,
ARTICLE_ERROR,
DELETE_ARTICLE
} from "../../redux/actionTypes";

const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);

const BASE_URL = process.env.API_BASE_URL;
describe("fetching article", () => {
test("should return fetching article action", () => {
expect(fetchingArticle()).toEqual({ type: FETCHING_ARTICLE });
});
});

describe("Fetching and deleting an article ", () => {
beforeEach(() => {
moxios.install(axios);
});
afterEach(() => {
moxios.uninstall(axios);
});

test("should dispatch the create article action", async () => {
const store = mockStore({});
const actions = [
{
type: ARTICLE_FETCHED,
payload: {
message: "Article fetched"
}
},
{
type: FETCHING_ASIDE_ARTICLES,
payload: {
articles: [""]
}
}
];
await moxios.stubRequest(`${BASE_URL}/articles/helloWorld`, {
status: 200,
response: {
message: "Article fetched"
}
});
await moxios.stubRequest(`${BASE_URL}/articles?limit=7`, {
status: 200,
response: {
articles: [""]
}
});
store.dispatch(fetchArticle("helloWorld")).then(() => {
expect(store.getActions()).toEqual(actions);
});
});

test("should dispatch the fetch article error", async () => {
const store = mockStore({});
const actions = [
{
type: ARTICLE_ERROR,
payload: {
message: "Error is thrown"
}
}
];
await moxios.stubRequest(`${BASE_URL}/articles/helloWorld`, {
status: 404,
response: {
message: "Error is thrown"
}
});
store.dispatch(fetchArticle("helloWorld")).then(() => {
expect(store.getActions()).toEqual(actions);
});
});

test("should dispatch the delete article method", async () => {
const store = mockStore({});
const actions = [
{
type: DELETE_ARTICLE,
payload: {
message: "Article deleted successfully"
}
}
];
await moxios.stubRequest(`${BASE_URL}/articles/helloWorld`, {
status: 200,
response: {
message: "Article deleted successfully"
}
});
store.dispatch(deleteArticle("helloWorld")).then(() => {
expect(store.getActions()).toEqual(actions);
});
});

test("should dispatch the delete article error", async () => {
const store = mockStore({});
const actions = [
{
type: DELETE_ARTICLE,
payload: {
message: "Error is thrown"
}
}
];
await moxios.stubRequest(`${BASE_URL}/articles/helloWorld`, {
status: 404,
response: {
message: "Error is thrown"
}
});
store.dispatch(deleteArticle("helloWorld")).then(() => {
expect(store.getActions()).toEqual(actions);
});
});
});
22 changes: 22 additions & 0 deletions src/__tests__/__components__/Cards/mainCard.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from "react";
import { shallow } from "enzyme";
import { MainCard } from "../../../components/common/Cards/main";

import { mainCardProps1, mainCardProps2 } from "../../__mocks__/testData";

describe("main card ", () => {
test("should render one main card with firstName lastName", () => {
const wrapper = shallow(<MainCard {...mainCardProps1} />);
expect(wrapper.find(".article-card")).toHaveLength(1);
});
test("should render one main card without firstName, and lastNamve", () => {
const wrapper = shallow(<MainCard {...mainCardProps2} />);
expect(wrapper.find(".article-card")).toHaveLength(1);
});
test("should render one main card without firstName, and lastNamve", () => {
const wrapper = shallow(<MainCard {...mainCardProps1} />);
wrapper.find(".left").simulate("click");
expect(mainCardProps1.history.push).toHaveBeenCalled();
expect(wrapper.find(".left")).toHaveLength(1);
});
});
Loading

0 comments on commit 52c540f

Please sign in to comment.