-
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.
- Loading branch information
Showing
24 changed files
with
799 additions
and
5 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 @@ | ||
APP_URL=https://ah-backend-thanos-staging.herokuapp.com/api |
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
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
62 changes: 62 additions & 0 deletions
62
src/actions/createArticleActions/createArticleActions.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,62 @@ | ||
import moxios from 'moxios'; | ||
import configureMockStore from 'redux-mock-store'; | ||
import thunk from 'redux-thunk'; | ||
import { | ||
createArticleSuccess, createArticleThunk, | ||
} from './index'; | ||
import ACTION_TYPE from '../actionTypes'; | ||
import APP_URL from '../../utils/constants'; | ||
|
||
|
||
describe('Create article Actions tests', () => { | ||
let store; | ||
let actionTypesData; | ||
let response; | ||
beforeEach(() => { | ||
response = { title: 'going to school' }; | ||
const mockStore = configureMockStore([thunk]); | ||
store = mockStore({}); | ||
actionTypesData = actionType => ({ | ||
type: actionType, | ||
payload: response, | ||
}); | ||
// import and pass your custom axios instance to this method | ||
moxios.install(); | ||
}); | ||
afterEach(() => { | ||
// import and pass your custom axios instance to this method | ||
moxios.uninstall(); | ||
}); | ||
test('Successful get and post rating action', () => { | ||
expect(createArticleSuccess(response)).toEqual(expect.objectContaining( | ||
actionTypesData(ACTION_TYPE.CREATE_ARTICLE_SUCCESS), | ||
)); | ||
}); | ||
test('Post article successfull', () => { | ||
moxios.stubRequest(`${APP_URL}/articles`, { | ||
status: 200, | ||
response: { message: 'ok' }, | ||
}); | ||
store.dispatch(createArticleThunk()).then(() => { | ||
expect(store.getActions()).toEqual(expect.objectContaining( | ||
{ | ||
type: ACTION_TYPE.CREATE_ARTICLE_SUCCESS, | ||
payload: { message: 'ok' }, | ||
}, | ||
)); | ||
}); | ||
}); | ||
test('Post article successfull', () => { | ||
moxios.stubRequest(`${APP_URL}/articles`, { | ||
status: 400, | ||
responseText: { error: 'ok' }, | ||
}); | ||
store.dispatch(createArticleThunk()).then(() => { | ||
expect(store.getActions()).toEqual(expect.objectContaining( | ||
[{ | ||
type: ACTION_TYPE.CREATE_ARTICLE_FAILED, | ||
}], | ||
)); | ||
}); | ||
}); | ||
}); |
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,44 @@ | ||
import axios from 'axios'; | ||
import ACTION_TYPE from '../actionTypes'; | ||
import APP_URL from '../../utils/constants'; | ||
|
||
export const postArticleData = response => ({ | ||
type: ACTION_TYPE.POST_ARTICLE_DATA, | ||
payload: response, | ||
}); | ||
|
||
export const createArticleSuccess = response => ({ | ||
type: ACTION_TYPE.CREATE_ARTICLE_SUCCESS, | ||
payload: response, | ||
}); | ||
|
||
export const createArticleFailure = errorMessage => ({ | ||
type: ACTION_TYPE.CREATE_ARTICLE_FAILED, | ||
errorMessage, | ||
}); | ||
|
||
export const updateImageUrl = imageUrl => ({ | ||
type: ACTION_TYPE.UPDATE_IMAGE_URL, | ||
payload: imageUrl, | ||
}); | ||
|
||
const tok = localStorage.getItem('token'); | ||
export const createArticleThunk = data => (dispatch) => { | ||
const userdata = { | ||
...data, | ||
}; | ||
const url = `${APP_URL}/articles`; | ||
const token = `Token ${tok}`; | ||
const headers = { | ||
headers: { Authorization: token }, | ||
}; | ||
return axios.post(url, userdata, headers) | ||
.then((res) => { | ||
const resData = res.data.results; | ||
dispatch(createArticleSuccess(resData)); | ||
}).catch((error) => { | ||
const errorData = error.response.data; | ||
dispatch(createArticleFailure(errorData)); | ||
}); | ||
}; | ||
export default createArticleThunk; |
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
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 url('https://fonts.googleapis.com/css?family=Roboto+Condensed'); | ||
|
||
#titleInput, | ||
#descriptionInput, | ||
#image_urlInput, | ||
#tag_listInput { | ||
height: 40px; | ||
border-top: none; | ||
border-left: none; | ||
border-right: none; | ||
} | ||
|
||
#createArticleBt { | ||
padding: 15px; | ||
width: 30%; | ||
background-color: #47d79f; | ||
border: none; | ||
font-family: "Roboto Condensed", sans-serif; | ||
&:hover { | ||
background-color: #3db184; | ||
} | ||
|
||
} | ||
.artcileCreate{ | ||
font-family: "Roboto Condensed", sans-serif; | ||
} | ||
.createArticleTitle { | ||
font-family: "Roboto Condensed", sans-serif; | ||
} | ||
|
||
.artcileCreate { | ||
padding-bottom: 30px; | ||
} | ||
#bodyInput { | ||
height: 500px; | ||
} | ||
.create-article-form { | ||
width: 80%; | ||
} | ||
|
||
.image-upload{ | ||
color: turquoise !important; | ||
border-color: turquoise !important; } | ||
|
||
.image { | ||
color: white; | ||
} | ||
input[type="file"] { | ||
border-color: turquoise !important; | ||
} |
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,16 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import CreateArticle from './index'; | ||
|
||
describe('<CreateArticle /> ', () => { | ||
const CreateArticleComponent = shallow( | ||
<CreateArticle | ||
onChange={jest.fn()} | ||
onSubmit={jest.fn()} | ||
onClick={jest.fn()} | ||
/>, | ||
); | ||
test('renders the component', () => { | ||
expect(CreateArticleComponent).toMatchSnapshot(); | ||
}); | ||
}); |
122 changes: 122 additions & 0 deletions
122
src/components/CreateArticle/__snapshots__/CreateArticle.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,122 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<CreateArticle /> renders the component 1`] = ` | ||
<div> | ||
<br /> | ||
<h3 | ||
className="text-center createArticleTitle" | ||
> | ||
Create Your Article | ||
</h3> | ||
<hr | ||
className="col-sm-8 " | ||
/> | ||
<br /> | ||
<div | ||
className="col-sm-10 offset-2 artcileCreate" | ||
> | ||
<form | ||
className="create-article-form" | ||
onSubmit={[MockFunction]} | ||
> | ||
<h5> | ||
Title: | ||
</h5> | ||
<small> | ||
Title must be 130 characters maximum and 5 characters minimum | ||
</small> | ||
<div | ||
className="form-group" | ||
> | ||
<textarea | ||
className="form-control" | ||
id="titleInput" | ||
maxLength="130" | ||
minLength="5" | ||
name="title" | ||
onChange={[MockFunction]} | ||
required={true} | ||
rows="3" | ||
/> | ||
</div> | ||
<h5> | ||
Description | ||
</h5> | ||
<small> | ||
Title must be 150 characters maximum and 100 characters minimum | ||
</small> | ||
<div | ||
className="form-group" | ||
> | ||
<textarea | ||
className="form-control" | ||
id="descriptionInput" | ||
maxLength="120" | ||
minLength="100" | ||
name="description" | ||
onChange={[MockFunction]} | ||
required={true} | ||
rows="3" | ||
/> | ||
</div> | ||
<h5> | ||
Tag list | ||
</h5> | ||
<div | ||
className="form-group" | ||
> | ||
<textarea | ||
className="form-control" | ||
id="tag_listInput" | ||
name="tag_list" | ||
onChange={[MockFunction]} | ||
required={true} | ||
rows="3" | ||
/> | ||
</div> | ||
<br /> | ||
<h5> | ||
Upload Image | ||
</h5> | ||
<div | ||
className="col-lg-8 mt-2" | ||
> | ||
<input | ||
className="image" | ||
name="image_url" | ||
onClick={[MockFunction]} | ||
type="file" | ||
/> | ||
</div> | ||
<br /> | ||
<h5> | ||
Body | ||
</h5> | ||
<div | ||
className="form-group" | ||
> | ||
<textarea | ||
className="form-control" | ||
id="bodyInput" | ||
name="body" | ||
onChange={[MockFunction]} | ||
required={true} | ||
rows="3" | ||
/> | ||
</div> | ||
<div | ||
className="signin-createArticleBt" | ||
> | ||
<button | ||
className="btn btn-primary" | ||
id="createArticleBt" | ||
name="createArticleBt" | ||
type="submit" | ||
> | ||
Publish Article | ||
</button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
`; |
Oops, something went wrong.