Skip to content

Commit

Permalink
[#164101954]: refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rajeman committed Feb 23, 2019
1 parent 89b1303 commit aa6b079
Showing 1 changed file with 99 additions and 7 deletions.
106 changes: 99 additions & 7 deletions src/app/article/article.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,104 @@ describe('ARTICLE TEST SUITE', () => {
});

it('should dispatch an action with status CREATING when article is being created', () => {
const response = {
response: {
data: {
slug: 'new article 001',
const response = { data: { secure_url: undefined } };
axios.post.mockImplementation(() => Promise.resolve(response));
const component = wrapper.find(CreateArticleComponent).first();
component.setState({
uploadCoverUrl: 'http://uploadcoverurl',
});
component.find('form').simulate('submit', {
preventDefault: () => {},
target: {
elements: {
title: { value: 'title' },
description: { value: 'description' },
category: { value: 'category' },
},
},
});
const dispatchedActions = store.getActions();
expect(dispatchedActions[1].createStatus.status).toEqual('CREATING');
});

it('should dispatch an action with type SET_CREATE_SUCCESS when article is created', () => {
const imageUploadResponse = {
data: { secure_url: 'https://secure' },
};
axios.post.mockImplementation(() => Promise.resolve(response));

const articleUploadResponse = {
data: { slug: 'created-article-001' },
};
axios.post.mockImplementation(url => {
if (!url) {
return Promise.resolve(imageUploadResponse);
}
return Promise.resolve(articleUploadResponse);
});
const component = wrapper.find(CreateArticleComponent).first();
component.setState({
uploadCoverUrl: 'http://uploadcoverurl',
});
component.find('form').simulate('submit', {
preventDefault: () => {},
target: {
elements: {
title: { value: 'title' },
description: { value: 'description' },
category: { value: 'category' },
},
},
});
const dispatchedActions = store.getActions();
expect(dispatchedActions[1].type).toEqual('SET_CREATE_STATUS');
});

it('should dispatch an action with status CREATE_ERROR if create fails', () => {
const imageUploadResponse = {
data: { secure_url: 'https://secure' },
};

const articleUploadResponse = {
response: { data: { error: 'invalid parameters' } },
};
axios.post.mockImplementation(url => {
if (!url) {
return Promise.resolve(imageUploadResponse);
}
return Promise.reject(articleUploadResponse);
});
const component = wrapper.find(CreateArticleComponent).first();
component.setState({
uploadCoverUrl: 'http://uploadcoverurl',
});
component.find('form').simulate('submit', {
preventDefault: () => {},
target: {
elements: {
title: { value: 'title' },
description: { value: 'description' },
category: { value: 'category' },
},
},
});
const dispatchedActions = store.getActions();
expect(dispatchedActions[1].createStatus.status).toEqual('CREATING');
});

it('should dispatch an action with status CREATE_ERROR if create fails', () => {
const imageUploadResponse = {
data: { secure_url: 'https://secure' },
};

const articleUploadResponse = {
response: { data: { error: 'invalid parameters' } },
};
axios.post.mockImplementation(url => {
if (!url) {
return Promise.resolve(imageUploadResponse);
}
return Promise.reject(articleUploadResponse);
});
const component = wrapper.find(CreateArticleComponent).first();
component.setState({
uploadCoverUrl: 'http://uploadcoverurl',
Expand Down Expand Up @@ -426,7 +516,9 @@ describe('ARTICLE TEST SUITE', () => {
},
comments: [
{
author: '',
author: {
username: 'rajeman',
},
comment: {
timestamp: 'comment text',
},
Expand All @@ -450,7 +542,7 @@ describe('ARTICLE TEST SUITE', () => {
);
});

it('should render the article page with default values for unavailable fields', () => {
it('should render the article page with default values for undefined fields', () => {
const component = wrapper.find('.article-header');
expect(component.exists()).toBe(true);
});
Expand Down

0 comments on commit aa6b079

Please sign in to comment.