-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ft-user-can-view-and-edit-own-profile
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
Showing
29 changed files
with
2,744 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() }); | ||
}); | ||
}); |
Oops, something went wrong.