-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
1,348 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,6 @@ yarn.* | |
yarn-* | ||
.DS_Store | ||
.env | ||
.coveralls.yml | ||
.coveralls.yml | ||
|
||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
Oops, something went wrong.