Skip to content

Commit

Permalink
feature(fix): acquire changes rom sharing article
Browse files Browse the repository at this point in the history
  • Loading branch information
YvesIraguha committed May 9, 2019
1 parent 27bed41 commit 4620eb6
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 135 deletions.
21 changes: 5 additions & 16 deletions src/__tests__/__mocks__/testData.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,19 @@ export const article3 = {
description: "Hello world"
};
export const props1 = {
<<<<<<< HEAD
deleteOneArticle: jest.fn(() => "Hello world"),
currentUser: {
firstName: "Yves",
lastName: "John",
image: "",
username: "Yves2019"
},
=======
following: {
status: true,
isFetching: false
},
followAuthor: jest.fn(),
followUser: jest.fn(),
>>>>>>> [Feature #163518655] add following functionality
history: {
push: jest.fn()
},
Expand All @@ -64,7 +61,7 @@ export const props1 = {
createdAt: "2019-04-20T09:37:50.006Z",
readTime: 1,
author: {
username: "Yves2019",
username: "Yves2018",
firstName: "Kagarama",
lastName: "Iraguha"
},
Expand All @@ -88,18 +85,16 @@ export const props1 = {
fetchOneArticle: jest.fn()
};
export const props2 = {
<<<<<<< HEAD
deleteOneArticle: jest.fn(() => "Hello world"),
currentUser: {
firstName: "Yves",
lastName: "John",
image: "",
username: "Yves2019"
=======
},
following: {
status: true,
isFetching: false
>>>>>>> [Feature #163518655] add following functionality
},
history: {
push: jest.fn()
Expand Down Expand Up @@ -143,17 +138,15 @@ export const props2 = {
fetchOneArticle: jest.fn()
};
export const props3 = {
<<<<<<< HEAD
currentUser: {
firstName: "Yves",
lastName: "John",
image: "",
username: "John203"
=======
},
following: {
status: true,
isFetching: false
>>>>>>> [Feature #163518655] add following functionality
},
history: {
push: jest.fn()
Expand All @@ -172,17 +165,15 @@ export const props3 = {
deleteOneArticle: jest.fn(() => "hello world")
};
export const props4 = {
<<<<<<< HEAD
currentUser: {
firstName: "Yves",
lastName: "John",
image: "",
username: "John203"
=======
},
following: {
status: true,
isFetching: false
>>>>>>> [Feature #163518655] add following functionality
},
history: {
push: jest.fn()
Expand All @@ -201,17 +192,15 @@ export const props4 = {
deleteOneArticle: jest.fn()
};
export const props5 = {
<<<<<<< HEAD
currentUser: {
firstName: "Yves",
lastName: "John",
image: "",
username: "John203"
=======
},
following: {
status: true,
isFetching: false
>>>>>>> [Feature #163518655] add following functionality
},
history: {
push: jest.fn()
Expand Down
223 changes: 112 additions & 111 deletions src/__tests__/__views__/ReadArticle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,140 +7,141 @@ import {
} from "../../views/ReadArticle";
import { props1, props2, props3, props4, props5 } from "../__mocks__/testData";

jest.useFakeTimers();
describe(" Read article", () => {
let inst;
const wrp = shallow(<Article {...props1} />);
beforeAll(() => {
inst = wrp.instance();
jest.spyOn(inst, "followAuthor");
jest.spyOn(inst, "handleDeleteArticle");
});

describe("Read article", () => {
test("render the full component with aside articles", () => {
const wrapper = shallow(<Article {...props1} />);
expect(wrapper.find(".article-container")).toHaveLength(1);
expect(wrapper.find(".article-other")).toHaveLength(1);
let inst;
const wrp = shallow(<Article {...props1} />);
beforeAll(() => {
inst = wrp.instance();
jest.spyOn(inst, "followAuthor");
jest.spyOn(inst, "handleDeleteArticle");
});

test("render the component without aside articles, firstName, and lastName", () => {
const wrapper = shallow(<Article {...props2} />);
expect(wrapper.find(".article-container")).toHaveLength(1);
});
describe("Read article", () => {
test("render the full component with aside articles", () => {
const wrapper = shallow(<Article {...props1} />);
expect(wrapper.find(".article-container")).toHaveLength(1);
expect(wrapper.find(".article-other")).toHaveLength(1);
});

test("render the component while it is still fetching", () => {
const wrapper = shallow(<Article {...props3} />);
expect(wrapper.find(".article-container")).not.toHaveLength(1);
});
test("render the component without aside articles, firstName, and lastName", () => {
const wrapper = shallow(<Article {...props2} />);
expect(wrapper.find(".article-container")).toHaveLength(1);
});

test("render the component without article", () => {
const wrapper = shallow(<Article {...props4} />);
expect(wrapper.find(".success-message")).toHaveLength(1);
});
test("render the component while it is still fetching", () => {
const wrapper = shallow(<Article {...props3} />);
expect(wrapper.find(".article-container")).not.toHaveLength(1);
});

test("render the component without comments and tags", () => {
const wrapper = shallow(<Article {...props5} />);
expect(wrapper.find(".article-container")).toHaveLength(1);
});
test("render the component without article", () => {
const wrapper = shallow(<Article {...props4} />);
expect(wrapper.find(".success-message")).toHaveLength(1);
});

test("should map states to props", () => {
const state = {
auth: {
test("render the component without comments and tags", () => {
const wrapper = shallow(<Article {...props5} />);
expect(wrapper.find(".article-container")).toHaveLength(1);
});

test("should map states to props", () => {
const state = {
auth: {
currentUser: {
username: "yves"
}
},
fetchedArticle: {
asideArticles: {
articles: [{ body: "hello world" }, { body: "hello world" }]
}
},
following: { isFetching: true, status: true }
};
expect(mapStateToProps(state)).toEqual({
currentUser: {
username: "yves"
}
},
fetchedArticle: {
},
asideArticles: {
articles: [{ body: "hello world" }, { body: "hello world" }]
}
},
following: { isFetching: true, status: true }
};
expect(mapStateToProps(state)).toEqual({
currentUser: {
username: "yves"
},
asideArticles: {
articles: [{ body: "hello world" }, { body: "hello world" }]
},
article: state.fetchedArticle,
following: { isFetching: true, status: true }
},
article: state.fetchedArticle,
following: { isFetching: true, status: true }
});
});
});

test("should map delete article to props", () => {
const dispatch = jest.fn();
mapDispatchToProps(dispatch).deleteOneArticle("hello world");
expect(dispatch.mock.calls[0][0]).toBeDefined();
});
test("should map delete article to props", () => {
const dispatch = jest.fn();
mapDispatchToProps(dispatch).deleteOneArticle("hello world");
expect(dispatch.mock.calls[0][0]).toBeDefined();
});

test("should map fetch article to props", () => {
const dispatch = jest.fn();
mapDispatchToProps(dispatch).fetchOneArticle("hello world");
expect(dispatch.mock.calls[0][0]).toBeDefined();
});
test("should map fetch article to props", () => {
const dispatch = jest.fn();
mapDispatchToProps(dispatch).fetchOneArticle("hello world");
expect(dispatch.mock.calls[0][0]).toBeDefined();
});

test("should redirect to another article", () => {
const wrapper = shallow(<Article {...props1} />);
wrapper.instance().componentWillReceiveProps({
match: {
params: { slug: "hello-world" }
}
test("should redirect to another article", () => {
const wrapper = shallow(<Article {...props1} />);
wrapper.instance().componentWillReceiveProps({
match: {
params: { slug: "hello-world" }
}
});
expect(props1.fetchOneArticle).toHaveBeenCalledWith("hello-world");
const secondCall = wrapper.instance().componentWillReceiveProps({
match: {
params: { slug: "juventus-vs-manu" }
}
});
expect(secondCall).toEqual(false);
});
expect(props1.fetchOneArticle).toHaveBeenCalledWith("hello-world");
const secondCall = wrapper.instance().componentWillReceiveProps({
match: {
params: { slug: "juventus-vs-manu" }
}

test("should display more reactions model", () => {
const wrapper = shallow(<Article {...props1} />);
wrapper.instance().toggleReportingModal();
expect(wrapper.state().reportingForm).toEqual(true);
wrapper.instance().toggleReportingModal();
expect(wrapper.state().reportingForm).toEqual(false);
});
expect(secondCall).toEqual(false);
});

test("should display more reactions model", () => {
const wrapper = shallow(<Article {...props1} />);
wrapper.instance().toggleReportingModal();
expect(wrapper.state().reportingForm).toEqual(true);
wrapper.instance().toggleReportingModal();
expect(wrapper.state().reportingForm).toEqual(false);
});
test("should display reporting form ", () => {
const wrapper = shallow(<Article {...props1} />);
wrapper.instance().toggleReactionsModal();
expect(wrapper.state().displayModal).toEqual(true);
wrapper.instance().toggleReactionsModal();
expect(wrapper.state().displayModal).toEqual(false);
});

test("should display reporting form ", () => {
const wrapper = shallow(<Article {...props1} />);
wrapper.instance().toggleReactionsModal();
expect(wrapper.state().displayModal).toEqual(true);
wrapper.instance().toggleReactionsModal();
expect(wrapper.state().displayModal).toEqual(false);
});
test("should redirect to edit article ", () => {
const wrapper = shallow(<Article {...props1} />);
wrapper.instance().redirectToEdit();
expect(props1.history.push).toHaveBeenCalled();
});

test("should redirect to edit article ", () => {
const wrapper = shallow(<Article {...props1} />);
wrapper.instance().redirectToEdit();
expect(props1.history.push).toHaveBeenCalled();
});
test("should test the presence of edit and deleting buttons", () => {
const wrapper = shallow(<Article {...props2} />);
expect(wrapper.find(".delete_article")).toHaveLength(1);
});

test("should test the presence of edit and deleting buttons", () => {
const wrapper = shallow(<Article {...props1} />);
expect(wrapper.find(".delete_article")).toHaveLength(1);
});
test("should test deleting an article", async () => {
const wrapper = shallow(<Article {...props2} />);
await props2.deleteOneArticle.mockResolvedValue({ status: 200 });
wrapper
.find(".delete_article")
.at(0)
.simulate("click");
expect(props2.history.push).not.toHaveBeenCalled();
});

test("should test deleting an article", async () => {
const wrapper = shallow(<Article {...props1} />);
await props1.deleteOneArticle.mockResolvedValue({ status: 200 });
wrapper
.find(".delete_article")
.at(0)
.simulate("click");
expect(props1.history.push).toHaveBeenCalled();
test("should test deleting an article", async () => {
const wrapper = shallow(<Article {...props2} />);
props2.deleteOneArticle.mockClear();
await props2.deleteOneArticle.mockResolvedValue({ status: 400 });
wrapper.find(".delete_article").simulate("click");
expect(props2.history.push).not.toHaveBeenCalled();
});
});

test("should test deleting an article", async () => {
const wrapper = shallow(<Article {...props2} />);
props2.deleteOneArticle.mockClear();
await props2.deleteOneArticle.mockResolvedValue({ status: 400 });
wrapper.find(".delete_article").simulate("click");
expect(props2.history.push).not.toHaveBeenCalled();
describe("Follow an author", () => {
test("should map followUser article to props", () => {
const dispatch = jest.fn();
Expand Down
8 changes: 1 addition & 7 deletions src/redux/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ import socialAuthReducers from "./socialAuthReducers";
import createArticleReducer from "./createArticleReducer";
import readArticleReducer from "./readArticleReducer";
import userReducer from "./userReducer";
<<<<<<< HEAD
import searchReducers from "./searchReducers";
=======
import following from "./followingReducer";
>>>>>>> [Feature #163518655] add following functionality

export default combineReducers({
auth: loginReducers,
Expand All @@ -20,9 +17,6 @@ export default combineReducers({
socialAuth: socialAuthReducers,
fetchedArticle: readArticleReducer,
user: userReducer,
<<<<<<< HEAD
search: searchReducers
=======
search: searchReducers,
following
>>>>>>> [Feature #163518655] add following functionality
});
2 changes: 1 addition & 1 deletion src/views/ReadArticle.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export class Article extends Component {
deleteOneArticle(slug).then(response => {
if (response.status === 200) {
this.setState({ response: "Article deleted successfully" });
setTimeout(() => history.push("/"), 3000);
return setTimeout(() => history.push("/"), 3000);
}
});
};
Expand Down

0 comments on commit 4620eb6

Please sign in to comment.