-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature #165412889 && #165412878] add article rating && article read…
… time
- Loading branch information
Showing
40 changed files
with
859 additions
and
32 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { getPublished } from '../../../actions/articles'; | ||
import article from '../../../__mocks__/article'; | ||
|
||
const dispatch = jest.fn(action => action); | ||
|
||
describe('published article articles', () => { | ||
it('returns publish information', async () => { | ||
const result = getPublished()(dispatch); | ||
expect(result).toHaveProperty('type'); | ||
expect(result).toHaveProperty('payload'); | ||
}); | ||
}); |
3 changes: 3 additions & 0 deletions
3
src/__tests__/actions/rating/__snapshots__/createRate.test.js.snap
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,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<RatingComponent /> should render a <CreateRatingComponent /> component 1`] = `ShallowWrapper {}`; |
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,35 @@ | ||
import React from 'react'; | ||
import configureMockStore from 'redux-mock-store'; | ||
import thunk from 'react-thunk'; | ||
import { Provider } from 'react-redux'; | ||
// import article from '../../../__mocks__/article'; | ||
import { createRate } from '../../../actions/rating'; | ||
import { Rating as RatingComponent } from '../../../components/Articles/Article/Rating'; | ||
import { shallow, mount } from '../../../../config/enzymeConfig'; | ||
|
||
describe('<RatingComponent />', () => { | ||
const props = { | ||
slug: 'slug-slug', | ||
rating: 1, | ||
errors: { error: ['12'] }, | ||
createRate: jest.fn(), | ||
fetchOneArticle: jest.fn() | ||
}; | ||
const rating = { | ||
slug: 'slug-slug', | ||
rating: 1 | ||
}; | ||
const component = shallow(<RatingComponent {...props} />); | ||
it('should render a <CreateRatingComponent /> component ', () => { | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
const dispatch = jest.fn(action => action); | ||
|
||
describe('Create rating', () => { | ||
test('returns rating information', async () => { | ||
const result = createRate(rating)(dispatch); | ||
expect(result).toHaveProperty('type'); | ||
expect(result).toHaveProperty('payload'); | ||
}); | ||
}); | ||
}); |
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,87 @@ | ||
import React from 'react'; | ||
import configureMockStore from 'redux-mock-store'; | ||
import thunk from 'react-thunk'; | ||
import { Provider } from 'react-redux'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import { mockStore, initialState } from '../../../__mocks__/store'; | ||
import { | ||
Rating as RatingComponent, | ||
mapStateToProps | ||
} from '../../../components/Articles/Article/Rating'; | ||
import { shallow, mount } from '../../../../config/enzymeConfig'; | ||
|
||
describe('<Article />', () => { | ||
const props = { | ||
message: 'Thank you for rating this article', | ||
errors: { token: 'Failed to authenticate token' }, | ||
submitRate: jest.fn(), | ||
createRate: jest.fn(), | ||
closeMessage: jest.fn(), | ||
ratingStars: jest.fn(), | ||
fetchOneArticle: jest.fn(), | ||
getSpecificArticle: jest.fn(), | ||
isAuth: true, | ||
slug: 'slug-article-12fg51x', | ||
article: { | ||
title: 'yes man', | ||
rating: 1, | ||
description: 'yes' | ||
}, | ||
loading: false | ||
}; | ||
const component = shallow(<RatingComponent {...props} />); | ||
it('should create <RatingComponent /> snapshot ', () => { | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
it('should trigger submit rate ', () => { | ||
component.setProps({ message: props.message, slug: props.slug, isAuth: true }); | ||
component.instance().submitRate(4); | ||
}); | ||
it('should trigger close message ', () => { | ||
component.setState({ message: { rating: 'updated' } }); | ||
component | ||
.find('.rating-errors i') | ||
.at(1) | ||
.simulate('click'); | ||
component.instance().closeMessage(); | ||
}); | ||
it('should trigger close message ', () => { | ||
component.setState({ message: { rating: 'updated' } }); | ||
component | ||
.find('.rating-errors i') | ||
.at(0) | ||
.simulate('click'); | ||
component.instance().closeMessage(); | ||
}); | ||
it('should trigger submit rate ', () => { | ||
component.setProps({ message: props.message, slug: props.slug, isAuth: false }); | ||
component.setState({ errors: { token: 'some' } }); | ||
component.instance().submitRate(4); | ||
}); | ||
it('should trigger submit rate ', () => { | ||
component.setProps({ message: props.message, slug: props.slug, isAuth: false }); | ||
component.setState({ errors: { token: 'token' } }); | ||
component.instance().submitRate(4); | ||
}); | ||
it('should trigger submit rate ', () => { | ||
component | ||
.find('.one-star') | ||
.at(1) | ||
.simulate('click', 5); | ||
}); | ||
|
||
it('should test map state', () => { | ||
mapStateToProps({ | ||
user: { isAuth: true }, | ||
articles: { article: props.article }, | ||
rating: { | ||
createRate: { | ||
loading: false, | ||
message: 'yes', | ||
errors: { token: 'token' } | ||
} | ||
} | ||
}); | ||
expect(mapStateToProps).toBeDefined(); | ||
}); | ||
}); |
5 changes: 5 additions & 0 deletions
5
src/__tests__/components/Articles/__snapshots__/Rating.test.js.snap
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,5 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<Article /> should create <RatingComponent /> snapshot 1`] = `ShallowWrapper {}`; | ||
|
||
exports[`<Article /> should render a <RatingComponent /> component 1`] = `ShallowWrapper {}`; |
100 changes: 100 additions & 0 deletions
100
src/__tests__/components/Profile/MyArticles/Published.test.js
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,100 @@ | ||
import React from 'react'; | ||
import configureMockStore from 'redux-mock-store'; | ||
import thunk from 'react-thunk'; | ||
import { Provider } from 'react-redux'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import URL from '../../../../__mocks__/URL'; | ||
import articles from '../../../../__mocks__/articles'; | ||
import { mockStore, initialState } from '../../../../__mocks__/store'; | ||
import { PublishedArticles as PublishedArticlesComponent } from '../../../../components/Profile/Articles/MyArticles/Published'; | ||
import { mount, shallow } from '../../../../../config/enzymeConfig'; | ||
|
||
const props = { | ||
errors: {}, | ||
article: { | ||
title: 'Hello John Doe', | ||
description: 'John Doe, Mocker', | ||
body: 'body of the article', | ||
slug: 'slug-slug-slug' | ||
}, | ||
message: { message: 'Published' }, | ||
fetchOneArticle: jest.fn(), | ||
history: {}, | ||
match: { params: { slug: 'slug-slug-slug' } }, | ||
publishArticle: jest.fn(), | ||
unpublishArticle: jest.fn(), | ||
deleteArticle: jest.fn(), | ||
fileSelectedHandler: jest.fn(), | ||
createObjectURL: jest.fn(), | ||
getPublished: jest.fn() | ||
}; | ||
const store = mockStore({ | ||
...initialState, | ||
articles: { articles }, | ||
getPublished: jest.fn(true) | ||
}); | ||
const state = { | ||
article: { | ||
title: 'Hello John Doe', | ||
description: 'John Doe, Mocker', | ||
body: JSON.stringify({ | ||
blocks: [ | ||
{ | ||
key: 'cnu26', | ||
text: 'test componentWillReceiveProps failedtest componentWillReceiveProps failed', | ||
type: 'unstyled', | ||
depth: 0, | ||
inlineStyleRanges: [ | ||
{ offset: 0, length: 74, style: 'color-rgb(36,41,46)' }, | ||
{ offset: 0, length: 74, style: 'bgcolor-rgb(255,255,255)' }, | ||
{ offset: 0, length: 74, style: 'fontsize-32' }, | ||
{ | ||
offset: 0, | ||
length: 74, | ||
style: | ||
'fontfamily--apple-system, system-ui, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol' | ||
} | ||
], | ||
entityRanges: [], | ||
data: { 'text-align': 'start' } | ||
}, | ||
{ | ||
key: 'emuik', | ||
text: 'Okey', | ||
type: 'unstyled', | ||
depth: 0, | ||
inlineStyleRanges: [ | ||
{ offset: 0, length: 4, style: 'color-rgb(36,41,46)' }, | ||
{ offset: 0, length: 4, style: 'bgcolor-rgb(255,255,255)' }, | ||
{ offset: 0, length: 4, style: 'fontsize-32' }, | ||
{ | ||
offset: 0, | ||
length: 4, | ||
style: | ||
'fontfamily--apple-system, system-ui, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol' | ||
} | ||
], | ||
entityRanges: [], | ||
data: {} | ||
} | ||
], | ||
entityMap: {} | ||
}), | ||
slug: 'slug-slug-slug' | ||
}, | ||
message: { message: 'Published' }, | ||
getPublished: jest.fn() | ||
}; | ||
describe('<PublishedArticlesComponent />', () => { | ||
const component = shallow(<PublishedArticlesComponent {...props} />); | ||
it('should render a <PublishedArticlesComponent /> component ', () => { | ||
const component = mount(<Provider store={store}> | ||
<MemoryRouter> | ||
<PublishedArticlesComponent {...props} /> | ||
</MemoryRouter> | ||
</Provider>); | ||
}); | ||
it('should trigger publish ', () => { | ||
component.setProps({ articles }); | ||
}); | ||
}); |
3 changes: 3 additions & 0 deletions
3
src/__tests__/components/Profile/MyArticles/__snapshots__/Published.test.js.snap
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,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<PublishedArticlesComponent /> should render a <PublishedArticlesComponent /> component 1`] = `ShallowWrapper {}`; |
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
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,42 @@ | ||
import createRatingReducer from '../../../reducers/rating/createRatingReducer'; | ||
import initialState from '../../../store/initialStates/ratingInitialState'; | ||
import { ratingActionsTypes } from '../../../actions-types'; | ||
// import articles from '../../__mocks__/articles'; | ||
// import article from '../../__mocks__/article'; | ||
// import message from '../../__mocks__/articleMessage'; | ||
// import errors from '../../__mocks__/errors'; | ||
|
||
const rating = { | ||
slug: 'slug-slug', | ||
rating: 1 | ||
}; | ||
|
||
describe('Rating reducers', () => { | ||
it('CREATE_RATING_START', () => { | ||
const reducer = createRatingReducer(initialState, { | ||
type: ratingActionsTypes.CREATE_RATING_START, | ||
payload: {} | ||
}); | ||
expect(reducer.createRate).toBeInstanceOf(Object); | ||
}); | ||
it('CREATE_RATING_SUCCESS', () => { | ||
const reducer = createRatingReducer(initialState, { | ||
type: ratingActionsTypes.CREATE_RATING_SUCCESS, | ||
payload: { rating } | ||
}); | ||
expect(reducer.createRate).toHaveProperty('errors'); | ||
}); | ||
it('CREATE_RATING_FAILURE', () => { | ||
const reducer = createRatingReducer(initialState, { | ||
type: ratingActionsTypes.CREATE_RATING_FAILURE, | ||
payload: {} | ||
}); | ||
expect(reducer.createRate).toHaveProperty('errors'); | ||
}); | ||
it('DEFAULT', () => { | ||
createRatingReducer(initialState, { | ||
type: null, | ||
payload: null | ||
}); | ||
}); | ||
}); |
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
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,4 @@ | ||
export const CREATE_RATING_START = 'CREATE_RATING_START'; | ||
export const CREATE_RATING_END = 'CREATE_RATING_END'; | ||
export const CREATE_RATING_SUCCESS = 'CREATE_RATING_SUCCESS'; | ||
export const CREATE_RATING_FAILURE = 'CREATE_RATING_FAILURE'; |
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,11 @@ | ||
import { articlesType } from '../../actions-types'; | ||
import { apiAction } from '../../helpers'; | ||
|
||
export const getPublished = () => dispatch => dispatch(apiAction({ | ||
method: 'get', | ||
url: '/articles/published', | ||
onStart: articlesType.FETCH_MY_PUBLISHED_ARTICLES_START, | ||
onEnd: articlesType.FETCH_MY_PUBLISHED_ARTICLES_END, | ||
onSuccess: articlesType.FETCH_MY_PUBLISHED_ARTICLES_SUCCESS, | ||
onFailure: articlesType.FETCH_MY_PUBLISHED_ARTICLES_FAILURE | ||
})); |
Oops, something went wrong.