Skip to content

Commit

Permalink
Feature(Create and Get all Articles): Enable user to create and view …
Browse files Browse the repository at this point in the history
…articles [Starts: #167484551]
  • Loading branch information
Musinda Kadhuwa committed Oct 11, 2019
1 parent c383a00 commit 79129af
Show file tree
Hide file tree
Showing 26 changed files with 608 additions and 141 deletions.
52 changes: 43 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
},
"dependencies": {
"@ckeditor/ckeditor5-build-classic": "^12.4.0",
"@ckeditor/ckeditor5-build-inline": "^12.4.0",
"@ckeditor/ckeditor5-editor-classic": "^12.1.4",
"@ckeditor/ckeditor5-react": "^1.1.3",
"axios": "^0.19.0",
Expand All @@ -31,17 +30,19 @@
"querystring": "^0.2.0",
"react": "^16.9.0",
"react-dom": "^16.9.0",
"react-html-parser": "^2.0.2",
"react-quill": "^1.3.3",
"react-redux": "^7.1.1",
"react-router": "^5.1.2",
"react-router-dom": "^5.0.1",
"react-scripts": "3.1.2",
"react-toastify": "^5.4.0",
"redux": "^4.0.4",
"redux-devtools-extension": "^2.13.8",
"redux-mock-store": "^1.5.3",
"redux-promise-middleware": "^6.1.1",
"redux-thunk": "^2.3.0",
"sass-loader": "^8.0.0",
"redux-mock-store": "^1.5.3"
"sass-loader": "^8.0.0"
},
"devDependencies": {
"coveralls": "^3.0.6",
Expand Down
29 changes: 29 additions & 0 deletions src/__mocks__/mockData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export default {
payload: {
title: 'Growth mindset',
description: 'How to demonstrate growth mindsewt',
tags: 'education',
category: 'Eductaion',
body:
'is simply dummy text of the printing and typesetting industry Lorem Ipsum has'
},

returnedArticle: {
author: {
bio: null,
firstName: 'Carlos',
image: null,
lastName: 'Gringo',
userName: 'carlosG'
},
authorId: 3,
blocked: false,
slug: 'tech-world-becoming-a-village-2lk1kg3x3y',
body:
"<h2>Where can I get some?</h2><p>There are many variations of injected humour, or non-characteristic</p><figure class='image'><img src='http://res.cloudinary.com/jkadhuwa/image/upload/v1570696434/buxtk2bswoki2jhiwtr5.png'></figure>",
category: 'Education',
createdAt: '2019-10-10T08:34:04.511Z',
description:
'I like creating a fontawesome.js in the src folder and then importing that into index.js. Feel free to add this file wherever as long as the components you want to use the icons in have access (are child components).'
}
};
3 changes: 0 additions & 3 deletions src/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { ToastContainer, toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
import './App.scss';
import GetAllArticles from '../feature/articles/getArticles/GetAllArticlesComponent';
import About from '../feature/About';
import CreateArticle from '../feature/articles/createArticle/CreateArticleComponent';
import ProtectedRoutes from '../feature/protectedRoutes/ProtectedRoutesComponent';
import Nav from './routes/Nav';
Expand All @@ -27,9 +26,7 @@ function App() {
<Route path="/login" component={Login} />
<Route path="/Signup" component={SignUp} />
<Route exact path="/" component={GetAllArticles} />
<Route path="/About" component={About} />
<Route path="/login" component={Login} />
<ProtectedRoutes path="/Create" component={CreateArticle} />
</Switch>
</BrowserRouter>
</div>
Expand Down
60 changes: 60 additions & 0 deletions src/app/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,63 @@ body {
text-align: center;
}
}
@media (min-width: 320px) and (max-width: 480px) {
body {
background: #fff;
font-family: ‘Open Sans’, sans-serif;
letter-spacing: 1px;
.App {
.App-header {
background-color: #282c34;
height: 6.2rem;
font-size: 25px;
color: white;
}
}
.nav-wrapper {
.App-logo {
height: 5rem;
margin: 10px 10px 10px 50px;
float: left;
}
.right {
float: right;
}
.last {
margin-right: 50px;
}
ul {
display: flex;
li {
list-style-type: none;
text-transform: uppercase;
line-height: 45px;
a {
color: #fff;
text-decoration: none;
padding: 15px 20px 15px 20px;
font-size: 1.2rem;
font-weight: bolder;
}
a:hover {
background: #fff;
color: #282c34;
cursor: pointer;
}
}
}
}
.intro {
margin-top: 20%;
font-size: 1.5rem;
font-weight: bold;
text-align: center;
}
.App-logo {
display: none;
}
.last {
margin-right: 15px !important;
}
}
}
Binary file added src/app/common/images/avatar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/app/common/images/backgroundImage.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/app/common/images/defaultImage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/app/config/ckeditorConfig.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-param-reassign */
/* istanbul ignore file */
import axios from 'axios';

async function getCloudinaryImageUrl(file) {
Expand Down
20 changes: 20 additions & 0 deletions src/app/helpers/getImage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* istanbul ignore file */
import ReactHtmlParser from 'react-html-parser';
import defaultImage from '../common/images/defaultImage.png';

const getImage = body => {
const image = ReactHtmlParser(body);
let imgUrl;

image.forEach(img => {
if (img.type === 'figure') {
imgUrl = img.props.children[0].props.src;
}
});
if (imgUrl) {
return imgUrl;
}
return defaultImage;
};

export default getImage;
8 changes: 1 addition & 7 deletions src/app/routes/Nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@ export class Navbar extends Component {
<li>
<Link to="/">Home</Link>
</li>
<li>
<Link to="/About">About</Link>
</li>
<li>
<Link to="/Create">Create</Link>
</li>
<li>
<Link to="/login" className="last">
<Link to="/login">
Login
</Link>
</li>
Expand All @@ -42,9 +39,6 @@ export class Navbar extends Component {
<li>
<Link to="/">Home</Link>
</li>
<li>
<Link to="/About">About</Link>
</li>
<li>
<Link to="/Create">Create</Link>
</li>
Expand Down
28 changes: 3 additions & 25 deletions src/feature/articles/__tests__/CreateArticleAction.test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import axios from 'axios';
import moxios from 'moxios';
import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import appMockStore from '../../../__mocks__/mockStoreConfig';
import createArticle from '../createArticle/createArticleAction';
import {
CREATE_ARTICLE_SUCCESS,
CREATE_ARTICLE_FAIL
} from '../constants';
import { CREATE_ARTICLE_SUCCESS, CREATE_ARTICLE_FAIL } from '../constants';
import LocalStorage from '../../../__mocks__/localStorage';

const middleware = [thunk];
const mockStore = configureStore(middleware);
const store = mockStore({});
const store = appMockStore({});

let storage;
const token = 'Invalid token';
Expand Down Expand Up @@ -48,22 +42,6 @@ describe('Create Article success', () => {
expect(dispatchedTypes).toEqual(expectedAction);
});
});
test('login testing error', () => {
const expected = {
status: 400,
error: 'SERVER ERROR! Please contact the administartor'
};
moxios.stubRequest(/.*/, {
response: expected
});
const mockArticles = {
description: 'I knew that would happen soon but i kept it inside',
body: 'I knew that would happen soon but i kept it inside'
};
return store.dispatch(createArticle(mockArticles)).then(() => {
expect(store.getActions().length).toEqual(1);
});
});
});

describe('Create article fail', () => {
Expand Down
9 changes: 0 additions & 9 deletions src/feature/articles/__tests__/CreateArticleComponent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,6 @@ describe('Iputs on change tests', () => {
});
expect(wrapper.state('tags')).toEqual('Tourism Beaches Scuba-diving');
});
// it('Should insert into body field', () => {
// const CKEditor = wrapper.find('.input__body');
// // CKEditor.simulate('change', {
// // ckeeditor: {
// // data: 'Tourism Beaches Scuba-diving in watamu beaches'
// // }
// // });
// // expect(wrapper.state('body')).toEqual('Tourism Beaches Scuba-diving');
// });
});

describe('On submit tests', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ describe('Create Article reducer', () => {

it('Should test No_ACTION/DEFAULT', () => {
const reducer = createArticleReducer(initialState, {
payload: {
}
payload: {}
});
expect(reducer.article).toEqual({});
});
Expand Down
Loading

0 comments on commit 79129af

Please sign in to comment.