Skip to content

Commit

Permalink
ft-user-can-view-and-edit-own-profile
Browse files Browse the repository at this point in the history
create view authenticated user profile
fetch user profile api
fetch user followers api
fetch user followee api
fetch user article api
fetch user published article api
fetch user draft article api
fetch user update profile api
create edit profile form
[Finishes #166840973]
  • Loading branch information
Alpha1202 committed Sep 3, 2019
1 parent f45793c commit 3b30826
Show file tree
Hide file tree
Showing 29 changed files with 2,744 additions and 74 deletions.
48 changes: 30 additions & 18 deletions _test_/Dashboard.spec.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,49 @@
import React from 'react';
import expect from 'expect';
import { shallow } from 'enzyme';
import configureMockStore from 'redux-mock-store';

import Dashboard from '../src/views/Dashboard';
import { UserDashboard } from '../src/components/Dashboard/index';

const mockStore = configureMockStore();

describe('Dashboard', () => {
let component;
const props = {
authUserProfile: jest.fn(),
getAuthUserFollowers: jest.fn(),
getAuthUserFollowee: jest.fn(),
getAuthUserArticles: jest.fn(),
auth: {
user: {
userName: '',
id: '',
},
},
};

let app;
let store;

beforeEach(() => {
component = shallow(<Dashboard />);
store = mockStore();
app = shallow(<UserDashboard store={store} {...props} />);
});

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

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

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

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

it('renders a li tag', () => {
expect(component.find('li').length).toBe(2);
it('renders dashboard index', () => {
expect(app).toMatchSnapshot();
});

it('renders a Link tag', () => {
expect(component.find('Link').length).toBe(2);
it('renders without auth', () => {
props.auth = null;
app = shallow(<UserDashboard store={store} {...props} />);
expect(app).toMatchSnapshot();
});
});
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);
});
});
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);
});
});
16 changes: 16 additions & 0 deletions _test_/authReducer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ describe('Login reducer', () => {
loading: false,
});
});
it('should set loading to true', () => {
expect(reducer(initialState, {
type: actionTypes.AUTH_LOADING,
})).toEqual({
...initialState,
loading: true,
});
});
it('should remove current user', () => {
expect(reducer(initialState, {
type: actionTypes.REMOVE_CURRENT_USER,
})).toEqual({
...initialState,
loading: false,
});
});

it('should successfully store the token upon login', () => {
expect(reducer(initialState, {
Expand Down
15 changes: 15 additions & 0 deletions _test_/dashboardView.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import expect from 'expect';
import { shallow } from 'enzyme';

import App from '../src/views/Dashboard';

describe('App', () => {
let app;
beforeEach(() => {
app = shallow(<App />);
});
it('renders successfully', () => {
expect(app).toBeDefined();
});
});
50 changes: 50 additions & 0 deletions _test_/editProfileForm.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from 'react';
import expect from 'expect';
import { shallow } from 'enzyme';
import configureMockStore from 'redux-mock-store';

import { EditProfileForm } from '../src/components/Dashboard/EditProfileForm';

const mockStore = configureMockStore();

describe('App', () => {
const props = {
editAuthUserProfile: jest.fn(),
auth: { user: { id: '' } },
userProfile: { isLoading: '' },
};
let app;
let store;

beforeEach(() => {
const initialState = {
firstName: '',
lastName: '',
userName: '',
bio: '',
avatar: '',
};

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

it('renders successfully', () => {
expect(app).toBeDefined();
});
it('Simulates an onchange event', () => {
const event = {
target: {
id: 'firstName',
value: 'This is to test for email change',
name: 'firstName',
},
};
app.find('input').at(0).simulate('change', event);
});
it('Simulates a form submit event', () => {
app.find('form').simulate('submit', { preventDefault: jest.fn() });
});
});
Loading

0 comments on commit 3b30826

Please sign in to comment.