Skip to content

Commit

Permalink
Merge branch 'staging' into ft-user-can-view-and-edit-own-profile-166…
Browse files Browse the repository at this point in the history
…840973
  • Loading branch information
Alpha1202 committed Aug 30, 2019
2 parents 9e610b2 + 2b5dd94 commit 5de8619
Show file tree
Hide file tree
Showing 69 changed files with 1,567 additions and 238 deletions.
4 changes: 3 additions & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ checks:
enabled: false
identical-code:
enabled: true

method-complexity:
config:
threshold: 10
2 changes: 1 addition & 1 deletion _test_/App.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ describe('App', () => {
expect(app.find('Switch').length).toBe(1);
});
it('renders a Route component', () => {
expect(app.find('Route').length).toBe(12);
expect(app.find('Route').length).toBe(13);
});
});
1 change: 0 additions & 1 deletion _test_/ArticleActions.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import moxios from 'moxios';
import makeMockStore from './Utils/makeMockStore';
import { fetchResponseData, mockData } from './testData/articleData';

import ArticleActions from '../src/actions/ArticleActions';
import {
SET_LOADING,
Expand Down
2 changes: 1 addition & 1 deletion _test_/ArticleCard.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('ArticleCard', () => {
});

it('renders a div component', () => {
expect(app.find('div').length).toBe(4);
expect(app.find('div').length).toBe(3);
});

it('renders an img component', () => {
Expand Down
24 changes: 24 additions & 0 deletions _test_/Comments.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import expect from 'expect';
import { shallow } from 'enzyme';
import Comments from '../src/components/Comments';

describe('Main Article', () => {
let component;

beforeEach(() => {
component = shallow(<Comments />);
});

it('renders successfully', () => {
expect(component).toBeDefined();
});

it('renders a div tag', () => {
expect(component.find('div').length).toBe(1);
});

it('renders an h1 tag', () => {
expect(component.find('h1').length).toBe(1);
});
});
25 changes: 25 additions & 0 deletions _test_/CommentsBtn.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import expect from 'expect';
import { shallow } from 'enzyme';
import CommentsBtn from '../src/components/SingleArticle/CommentsBtn';


describe('Single Article', () => {
let component;

beforeEach(() => {
component = shallow(<CommentsBtn />);
});

it('renders successfully', () => {
expect(component).toBeDefined();
});

it('renders a div component', () => {
expect(component.find('div').length).toBe(1);
});

it('renders a Link component', () => {
expect(component.find('Link').length).toBe(1);
});
});
60 changes: 60 additions & 0 deletions _test_/DraftArticles.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import React from 'react';
import expect from 'expect';
import Enzyme, { shallow } from 'enzyme';
import configureMockStore from 'redux-mock-store';
import Adapter from 'enzyme-adapter-react-16';
import { DraftArticles } from '../src/components/Dashboard/DraftArticles';

const mockStore = configureMockStore();
Enzyme.configure({ adapter: new Adapter() });

describe('Draft Articles', () => {
const props = {
getAuthUserDraftArticles: jest.fn(),
auth: { user: { id: 3 } },
userProfile: {
draft: {
articles: [
{
id: 1,
title: 'title 1',
imageUrl: 'http://img.com',
body: 'I am the body',
isDraft: true,
Category: {
name: 'Game',
},
views: '34',

},
],
},
},
};

let app;
let store;

beforeEach(() => {
store = mockStore();
app = shallow(
<DraftArticles store={store} {...props} />,
);
});

it('renders successfully', () => {
expect(app).toBeDefined();
});

it('gets all draft articles', () => {
const articleContainer = app.find('.article-title');
expect(articleContainer).toHaveLength(1);
expect(articleContainer.props().children).toEqual(props.userProfile.draft.articles[0].title);
});

it('Click on pagination', () => {
app.instance().paginate(2);
const render = jest.spyOn(app.instance(), 'paginate');
expect(render).toHaveBeenCalledTimes(0);
});
});
8 changes: 0 additions & 8 deletions _test_/FeaturedArticle.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ describe('FeaturedArticle', () => {
expect(app).toBeDefined();
});

it('renders a div component', () => {
expect(app.find('div').length).toBe(1);
});

it('renders an img component', () => {
expect(app.find('img').length).toBe(1);
});

it('renders a h3 component', () => {
expect(app.find('h3').length).toBe(1);
});
Expand Down
1 change: 0 additions & 1 deletion _test_/Homepage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ describe('Homepage', () => {
const comp = shallow(<Home allArticles={homeData} fetchArticles={getArticles} />);
const inst = comp.instance();
inst.loadItems();
// console.log(inst.debug());
});

it('componentWillUnmount should be called on unmount', () => {
Expand Down
48 changes: 48 additions & 0 deletions _test_/MainArticle.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react';
import expect from 'expect';
import { shallow } from 'enzyme';
import MainArticle from '../src/components/SingleArticle/MainArticle';
import image from '../src/assets/articleImage.png';

describe('Main Article', () => {
let component;

const props = {
views: 1,
imageUrl: '',
};

beforeEach(() => {
component = shallow(<MainArticle {...props} />);
});

it('renders successfully', () => {
expect(component).toBeDefined();
});

it('renders three div tags', () => {
expect(component.find('div').length).toBe(3);
component.setProps({ views: 2 });
component.setProps({ imageUrl: image });
});

it('renders an h1 tag', () => {
expect(component.find('h1').length).toBe(1);
});

it('renders an Link tag', () => {
expect(component.find('Link').length).toBe(1);
});

it('renders a p tag', () => {
expect(component.find('p').length).toBe(3);
});

it('renders a span tag', () => {
expect(component.find('span').length).toBe(3);
});

it('renders an image tag', () => {
expect(component.find('img').length).toBe(1);
});
});
60 changes: 60 additions & 0 deletions _test_/PublishedArticles.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import React from 'react';
import expect from 'expect';
import Enzyme, { shallow } from 'enzyme';
import configureMockStore from 'redux-mock-store';
import Adapter from 'enzyme-adapter-react-16';
import { PublishedArticles } from '../src/components/Dashboard/PublishedArticles';

const mockStore = configureMockStore();
Enzyme.configure({ adapter: new Adapter() });

describe('Published Articles', () => {
const props = {
getAuthUserPublishedArticles: jest.fn(),
auth: { user: { id: 3 } },
userProfile: {
published: {
articles: [
{
id: 1,
title: 'title 1',
imageUrl: 'http://img.com',
body: 'I am the body',
isDraft: false,
Category: {
name: 'Game',
},
views: '34',

},
],
},
},
};

let app;
let store;

beforeEach(() => {
store = mockStore();
app = shallow(
<PublishedArticles store={store} {...props} />,
);
});

it('renders successfully', () => {
expect(app).toBeDefined();
});

it('gets all published articles', () => {
const articleContainer = app.find('.article-title');
expect(articleContainer).toHaveLength(1);
expect(articleContainer.props().children).toEqual(props.userProfile.published.articles[0].title);
});

it('Click on pagination', () => {
app.instance().paginate(2);
const render = jest.spyOn(app.instance(), 'paginate');
expect(render).toHaveBeenCalledTimes(0);
});
});
64 changes: 64 additions & 0 deletions _test_/RecommendedArticles.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import React from 'react';
import expect from 'expect';
import { shallow } from 'enzyme';
import Recommended from '../src/components/SingleArticle/Recommended';
import image from '../src/assets/articleImage.png';

describe('Main Article', () => {
let component;

const props = {
allArticles: [{
title: 'Hello',
article: { slug: 'hello-1', imageUrl: '' },
},
{
title: 'Hellos',
article: { slug: 'hello-2', imageUrl: '' },
},
{
title: 'Helloey',
article: { slug: 'hello-3', imageUrl: '' },
}],
};

beforeEach(() => {
component = shallow(<Recommended {...props} />);
});

it('renders successfully', () => {
expect(component).toBeDefined();
});

it('renders a div tag', () => {
expect(component.find('div').length).toBe(2);
});

it('renders an h3 tag', () => {
expect(component.find('h3').length).toBe(1);
});

it('renders three h4 tags', () => {
expect(component.find('h4').length).toBe(3);
});

it('renders three image tags', () => {
expect(component.find('img').length).toBe(3);
component.setProps({
allArticles: {
0: { article: { slug: 'hello-1', imageUrl: image } },
1: { article: { slug: 'hello-2', imageUrl: image } },
2: { article: { slug: 'hello-3', imageUrl: image } },
},
});
});

it('renders three Link tags', () => {
expect(component.find('Link').length).toBe(3);
});

it('returns null', () => {
component.setProps({ allArticles: [] });
expect(component).toEqual({});
});
});
Loading

0 comments on commit 5de8619

Please sign in to comment.