Skip to content

Commit

Permalink
ft(user-can-rate-artilce)
Browse files Browse the repository at this point in the history
add a temporary login form
add a temporary get all articles page
add read one article page
add a dropdown button
add the star rating  modal
add the an on-success notification
[Starts #166840975]
  • Loading branch information
Alpha1202 committed Aug 29, 2019
1 parent 2b5dd94 commit 3dbf05d
Show file tree
Hide file tree
Showing 19 changed files with 707 additions and 32 deletions.
1 change: 1 addition & 0 deletions _test_/Articles.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Adapter from 'enzyme-adapter-react-16';

import { GetAllArticles } from '../src/views/Articles';


Enzyme.configure({ adapter: new Adapter() });

describe('Articles', () => {
Expand Down
17 changes: 17 additions & 0 deletions _test_/Dropdown.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import expect from 'expect';
import { shallow } from 'enzyme';

import DropLeft from '../src/components/SingleArticle/RatingsBtn/index';


describe('App', () => {
let app;
beforeEach(() => {
app = shallow(<DropLeft />);
});

it('renders successfully', () => {
expect(app).toBeDefined();
});
});
41 changes: 41 additions & 0 deletions _test_/RatingsModal.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react';
import expect from 'expect';
import { shallow } from 'enzyme';

import RatingsModal from '../src/components/SingleArticle/RatingsModal/index';


describe('App', () => {
let app;
beforeEach(() => {
app = shallow(<RatingsModal />);
});

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

it('tags have classes', () => {
expect(app.find('_class').length).toBe(9);
});

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

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

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

it('renders StarRatingComponent', () => {
expect(app.find('StarRatingComponent').length).toBe(1);
});
});



25 changes: 24 additions & 1 deletion _test_/SingleArticle.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,29 @@ import MainArticle from '../src/components/SingleArticle/MainArticle';
import Tags from '../src/components/SingleArticle/Tags';
import Recommended from '../src/components/SingleArticle/Recommended';
import CommentsBtn from '../src/components/SingleArticle/CommentsBtn';
import RatingsModal from '../src/components/SingleArticle/RatingsModal';


describe('Single Article', () => {
let component;
let prevProps;

let nextValue;

const props = {
prevProps: { match: { params: { slug: 'hello' } } },
match: { params: { slug: '' } },
article: { userId: 1 },
viewArticle: jest.fn(),
fetchArticles: jest.fn(),
articleRating: jest.fn(),
loading: false,
componentDidUpdate: jest.fn(prevProps),
onStarClick: jest.fn(nextValue),
handleRatingsSubmit: jest.fn(),
};

beforeEach(() => {
window.localStorage.setItem('jwtToken', 'token');
component = shallow(<SingleArticle {...props} />);
});

Expand Down Expand Up @@ -50,6 +57,10 @@ describe('Single Article', () => {
expect(component.find(CommentsBtn).length).toBe(1);
});

it('renders a RatingsModal component', () => {
expect(component.find(RatingsModal).length).toBe(1);
});

it('renders a Loader component', () => {
component.setProps({ loading: true });
expect(component.find(Loader).length).toBe(1);
Expand All @@ -60,4 +71,16 @@ describe('Single Article', () => {
const render = jest.spyOn(component.instance(), 'render');
expect(render).toHaveBeenCalledTimes(0);
});

it('Click on ratings modal', () => {
component.instance().onStarClick(nextValue);
const starClick = jest.spyOn(component.instance(), 'onStarClick');
expect(starClick).toHaveBeenCalledTimes(0);
});

it('submits ratings', () => {
component.instance().handleRatingsSubmit();
const starSubmit = jest.spyOn(component.instance(), 'handleRatingsSubmit');
expect(starSubmit).toHaveBeenCalledTimes(0);
});
});
67 changes: 67 additions & 0 deletions _test_/article.action.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import expect from 'expect';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import moxios from 'moxios';
import * as types from '../src/actions/types';
import * as actions from '../src/actions/article.action';
import axios from '../src/config/axiosInstance';

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

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


describe('rate Article Tests', () => {
afterEach(() => {
moxios.install(axios);
store.clearActions();
});

afterEach(() => moxios.uninstall(axios));

it('Returns success if rate article was successful', (done) => {
const dataValue = {
value: 3,
};
jest.spyOn(axios, 'post').mockResolvedValue({ data: { message: '', data: {} } });

const expectedActions = [
{
type: types.RATE_ARTICLE_START,
},
{
type: types.RATE_ARTICLE_SUCCESS,
},
];
store.dispatch(actions.articleRating(dataValue))
.then(() => {
expect(store.getActions()).toEqual(expectedActions);
done();
});

});

it('Return failure if rate article was unsuccessful', (done) => {

jest.spyOn(axios, 'post').mockRejectedValue({ response: { data: { message: '' } } });


const expectedActions = [
{
type: types.RATE_ARTICLE_START,
},
{
type: types.RATE_ARTICLE_FAILURE,
},
];

store.dispatch(actions.articleRating(3))
.then(() => {
expect(store.getActions()).toEqual(expectedActions);
done();
});

});
});
2 changes: 2 additions & 0 deletions _test_/singleArticleReducer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ describe('Login reducer', () => {
initialState = {
article: {},
loading: false,
alert: '',
rating: '',
};
});
it('should return the initial state', () => {
Expand Down
Loading

0 comments on commit 3dbf05d

Please sign in to comment.