Skip to content

Commit

Permalink
ft-user-can-edit-profile
Browse files Browse the repository at this point in the history
add an edit profile modal form
[#166840973]
  • Loading branch information
Alpha1202 committed Aug 27, 2019
2 parents f448e8d + 32509ca commit 19d5dea
Show file tree
Hide file tree
Showing 23 changed files with 2,262 additions and 136 deletions.
49 changes: 28 additions & 21 deletions _test_/Dashboard.spec.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,44 @@
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);
});

it('renders a ul tag', () => {
expect(component.find('ul').length).toBe(1);
expect(app).toBeDefined();
console.log(app.debug())
});

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

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

});
});
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() });
});
});
220 changes: 220 additions & 0 deletions _test_/userAction.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
import expect from 'expect';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import moxios from 'moxios';
import { toast } from 'react-toastify';
import * as types from '../src/actions/types';
import * as actions from '../src/actions/userActions';
import axios from '../src/config/axiosInstance';

const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);

const initialState = {};
let store = mockStore(initialState);

const userId = 2;
const userToken = 'nhfjdjskkkaa';

describe('User Action Tests', () => {
afterEach(() => {
moxios.install(axios);
store.clearActions();
});
afterEach(() => moxios.uninstall(axios));

it('should dispatch GET_AUTH_USER_PROFILE action', () => {
store.dispatch(actions.getAuthUserProfileStart());
expect(store.getActions()).toContainEqual({ type: types.GET_AUTH_USER_PROFILE_START });
});
it('Returns success if user profile was successfully fetched', (done) => {
moxios.stubRequest(`https://ah-nyati-backend-staging.herokuapp.com/api/v1/user/profiles/${userId}`, {
status: 200,
data: [],
});
const expectedActions = [
{
type: types.GET_AUTH_USER_PROFILE_START,
},
{
type: types.GET_AUTH_USER_PROFILE_SUCCESS,
},
{
type: types.GET_AUTH_USER_PROFILE_FAILURE,
},
];
store = mockStore({});
store.dispatch(actions.authUserProfile(userToken));
store.dispatch(actions.getAuthUserProfileSuccess());
store.dispatch(actions.getAuthUserProfileFailure());
expect(store.getActions()).toEqual(expectedActions);
done();
});

it('Returns success if get user profile was successful', (done) => {
jest.spyOn(axios, 'get').mockResolvedValue({ data: { data: {} } });

const expectedActions = [
{
type: types.GET_AUTH_USER_PROFILE_START,
},
{
type: types.GET_AUTH_USER_PROFILE_SUCCESS,
},
];
store.dispatch(actions.authUserProfile(userId))
.then(() => {
expect(store.getActions()).toEqual(expectedActions);
done();
});
});

it('Returns success if get user followers was successful', (done) => {
jest.spyOn(axios, 'get').mockResolvedValue({ data: { data: {} } });

const expectedActions = [
{
type: types.GET_AUTH_USER_PROFILE_START,
},
{
type: types.GET_AUTH_USER_PROFILE_SUCCESS,
},
];
store.dispatch(actions.getAuthUserFollowers(userId))
.then(() => {
expect(store.getActions()).toEqual(expectedActions);
done();
});
});

it('Return failure if get user profile was unsuccessful', (done) => {
jest.spyOn(axios, 'get').mockRejectedValue({ response: { data: { message: '' } } } );

const expectedActions = [
{
type: types.GET_AUTH_USER_PROFILE_START,
},
{
type: types.GET_AUTH_USER_PROFILE_FAILURE,
},
];
store.dispatch(actions.authUserProfile(userId))
.then(() => {
expect(store.getActions()).toEqual(expectedActions);
done();
});
});

it('Return failure if get user followers was unsuccessful', (done) => {
jest.spyOn(axios, 'get').mockRejectedValue({ response: { data: { message: '' } } } );

const expectedActions = [
{
type: types.GET_AUTH_USER_FOLLOWERS_START,
},
{
type: types.GET_AUTH_USER_FOLLOWERS_FAILURE,
},
];
store.dispatch(actions.getAuthUserFollowers(userToken))
.then(() => {
expect(store.getActions()).toEqual(expectedActions);
done();
});
});

it('Return failure if get user followees was unsuccessful', (done) => {
jest.spyOn(axios, 'get').mockRejectedValue({ response: { data: { message: '' } } } );

const expectedActions = [
{
type: types.GET_AUTH_USER_FOLLOWEE_START,
},
{
type: types.GET_AUTH_USER_FOLLOWEE_FAILURE,
},
];
store.dispatch(actions.getAuthUserFollowee(userToken))
.then(() => {
expect(store.getActions()).toEqual(expectedActions);
done();
});
});

it('Returns success if get user followees was successful', (done) => {
jest.spyOn(axios, 'get').mockResolvedValue({ data: { data: {} } });

const expectedActions = [
{
type: types.GET_AUTH_USER_FOLLOWEE_START,
},
{
type: types.GET_AUTH_USER_FOLLOWEE_SUCCESS,
},
];
store.dispatch(actions.getAuthUserFollowee(userId))
.then(() => {
expect(store.getActions()).toEqual(expectedActions);
done();
});
});

it('Returns success if get user articles was successful', (done) => {
jest.spyOn(axios, 'get').mockResolvedValue({ data: { data: {} } });
const userName = '';
const expectedActions = [
{
type: types.GET_AUTH_USER_ARTICLES_START,
},
{
type: types.GET_AUTH_USER_ARTICLES_SUCCESS,
},
];
store.dispatch(actions.getAuthUserArticles(userName))
.then(() => {
expect(store.getActions()).toEqual(expectedActions);
done();
});
});

it('Return failure if get user articles was unsuccessful', (done) => {
jest.spyOn(axios, 'get').mockRejectedValue({ response: { data: { message: '' } } } );
const userName = '';
const expectedActions = [
{
type: types.GET_AUTH_USER_ARTICLES_START,
},
{
type: types.GET_AUTH_USER_ARTICLES_FAILURE,
},
];
store.dispatch(actions.getAuthUserArticles(userName))
.then(() => {
expect(store.getActions()).toEqual(expectedActions);
done();
});
});

it('Returns success if edit user profile was successful', (done) => {
jest.spyOn(axios, 'get').mockResolvedValue({ data: { data: {} } });
const newProfileDetails = {
firstName: '',
lastName: '',
userName: '',
};
const userid = '';
const expectedActions = [
{
type: types.EDIT_AUTH_USER_PROFILE_START,
},
{
type: types.EDIT_AUTH_USER_PROFILE_SUCCESS,
},
];
store.dispatch(actions.editAuthUserProfile(newProfileDetails, userid))
.then(() => {
expect(store.getActions()).toEqual(expectedActions);
done();
});
});
});
37 changes: 37 additions & 0 deletions _test_/userArticles.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react';
import expect from 'expect';
import { shallow } from 'enzyme';
import configureMockStore from 'redux-mock-store';

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

const mockStore = configureMockStore();

describe('Dashboard', () => {
const props = {
userProfile: {
profile: {
firstName: '',
lastName: '',
userName: '',
imageUrl: '',
},
followers: [],
followees: [],
articles: [],
},
};
let app;
let store;

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

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

0 comments on commit 19d5dea

Please sign in to comment.