Skip to content

Commit

Permalink
Merge 4c2b78c into 9666159
Browse files Browse the repository at this point in the history
  • Loading branch information
MBenedicte committed Jul 15, 2019
2 parents 9666159 + 4c2b78c commit ffb8dc6
Show file tree
Hide file tree
Showing 31 changed files with 870 additions and 550 deletions.
2 changes: 1 addition & 1 deletion .env.sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PORT = 5000
REACT_APP_URL_BACKEND = http://localhost:3000
REACT_APP_URL_FRONTEND = http://localhost:5000
REACT_APP_IMAGE_BASE_URL = REACT_APP_IMAGE_BASE_URL
REACT_APP_IMAGE_BASE_URL = REACT_APP_IMAGE_BASE_URL
352 changes: 157 additions & 195 deletions package-lock.json

Large diffs are not rendered by default.

17 changes: 15 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"cover": "CI=true react-scripts test \"-- --coverage\"",
"coveralls": "cat coverage/lcov.info | coveralls",
"eject": "react-scripts eject",
"lint": "./node_modules/.bin/eslint . --fix"
"lint": "eslint . --fix"
},
"dependencies": {
"@emotion/core": "^10.0.14",
Expand Down Expand Up @@ -84,5 +84,18 @@
"!<rootDir>/coverage/**/*.*",
"!<rootDir>/build/**/*.*"
]
}
},
"description": "# Badges",
"main": "index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/andela/ninjas-ah-frontend.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/andela/ninjas-ah-frontend/issues"
},
"homepage": "https://github.com/andela/ninjas-ah-frontend#readme"
}
4 changes: 3 additions & 1 deletion src/__mocks__/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ export default (Object.notification = {
on: ['publish', 'comment']
}
}
}
},
updateNotificationConfiguration: { loading: false, message: '', errors: {} },
getNotificationConfiguration: { loading: false, message: '', errors: {} }
});
17 changes: 17 additions & 0 deletions src/__mocks__/notificationUpdate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export default (Object.notification = {
configuration: {
inApp: {
articles: {
show: true,
on: ['publish', 'comment']
}
},
email: {
articles: {
show: true,
on: ['publish', 'comment']
}
}
},
updateNotificationConfiguration: { loading: false, message: '', errors: {} }
});
36 changes: 0 additions & 36 deletions src/__tests__/actions/notification/notification.test.js

This file was deleted.

30 changes: 21 additions & 9 deletions src/__tests__/components/Notification/Notification.test.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import React from 'react';
import Enzyme, { mount } from 'enzyme';
import EnzymeAdapter from 'enzyme-adapter-react-16';
import { Provider } from 'react-redux';
import { MemoryRouter } from 'react-router-dom';
import { mockStore, initialState } from '../../../__mocks__/store';
import notification from '../../../__mocks__/notification';
import thunk from 'redux-thunk';
import configureMockStore from 'redux-mock-store';
import { mount } from '../../../../config/enzymeConfig';
import config from '../../../__mocks__/notification';
import Notification from '../../../components/Profile/Settings/NotificationsComponent/Notification';
import { initialState } from '../../../__mocks__/store';

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

const mockStore = configureMockStore([thunk]);
const props = {
notification: { alias: 'email' },
createOne: jest.fn()
config: { alias: 'email' },
createNotificationConfiguration: jest.fn(),
updateNotificationConfiguration: jest.fn()
};

const store = mockStore({
...initialState,
notificationReducer: notification
config
});

describe('Notification test', () => {
Expand All @@ -37,4 +39,14 @@ describe('Notification test', () => {
wrapper.find('button[id="save"]').simulate('click');
expect(wrapper.find('button[id="save"]').length).toBe(1);
});
it('should create default configurations', () => {
window.localStorage.setItem('token', 'token');
const wrapper = mount(<Provider store={store}>
<MemoryRouter>
<Notification store={store} {...props} />
</MemoryRouter>
</Provider>);
wrapper.find('button[id="save"]').simulate('click');
expect(wrapper.find('button[id="save"]').length).toBe(1);
});
});
26 changes: 17 additions & 9 deletions src/__tests__/components/Notification/NotificationHeader.test.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
import React from 'react';
import Enzyme, { mount } from 'enzyme';
import EnzymeAdapter from 'enzyme-adapter-react-16';
import { Provider } from 'react-redux';
import { MemoryRouter } from 'react-router-dom';
import thunk from 'redux-thunk';
import configureMockStore from 'redux-mock-store';
import notification from '../../../__mocks__/notification';
import { mount } from '../../../../config/enzymeConfig';
import config from '../../../__mocks__/notification';
import NotificationHeader from '../../../components/Profile/Settings/NotificationsComponent/NotificationHeader';
import { initialState } from '../../../__mocks__/store';

Enzyme.configure({ adapter: new EnzymeAdapter() });
const mockStore = configureMockStore([thunk]);
const props = {
notification: { alias: 'email' },
createOne: jest.fn()
config: { alias: 'email' },
createNotificationConfiguration: jest.fn(),
updateNotificationConfiguration: jest.fn()
};
describe('Notification test', () => {
let store;
beforeEach(() => {
store = mockStore({ notificationReducer: notification });
store = mockStore({
...initialState,
config
});
});
test('renders without an error', () => {
const wrapper = mount(<Provider store={store}>
<NotificationHeader store={store} {...props} />
<MemoryRouter>
<NotificationHeader store={store} {...props} />
</MemoryRouter>
</Provider>);
expect(wrapper.find('input').length).toBe(2);
});

it('should call toggleNotificationType', () => {
const wrapper = mount(<Provider store={store}>
<NotificationHeader store={store} {...props} />
<MemoryRouter>
<NotificationHeader store={store} {...props} />
</MemoryRouter>
</Provider>);

wrapper.find('input[data-test="inApp"]').simulate('change');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import React from 'react';
import Enzyme, { mount } from 'enzyme';
import EnzymeAdapter from 'enzyme-adapter-react-16';
import { Provider } from 'react-redux';
import thunk from 'redux-thunk';
import configureMockStore from 'redux-mock-store';
import { mount } from '../../../../config/enzymeConfig';
import notification from '../../../__mocks__/notification';
import NotificationOptions from '../../../components/Profile/Settings/NotificationsComponent/NotificationOptions';

Enzyme.configure({ adapter: new EnzymeAdapter() });
const mockStore = configureMockStore([thunk]);
const props = {
notification: { alias: 'email' },
Expand All @@ -16,7 +14,7 @@ const props = {
describe('Notification test', () => {
let store;
beforeEach(() => {
store = mockStore({ notificationReducer: notification });
store = mockStore({ notification });
});
test('renders without an error', () => {
const wrapper = mount(<Provider store={store}>
Expand All @@ -41,4 +39,20 @@ describe('Notification test', () => {
inputs.map(input => input.simulate('change', { target: { value: 'comment', checked: true } }));
expect(wrapper.find('input').length).toBe(4);
});
it('should call onChange, and addOption', () => {
const wrapper = mount(<Provider store={store}>
<NotificationOptions store={store} {...props} />
</Provider>);
const inputs = wrapper.find('input');
inputs.map(input => input.simulate('change', { target: { value: 'comment', checked: true } }));
expect(wrapper.find('input').length).toBe(4);
});
it('should call onChange, and remove', () => {
const wrapper = mount(<Provider store={store}>
<NotificationOptions store={store} {...props} />
</Provider>);
const inputs = wrapper.find('input');
inputs.map(input => input.simulate('change', { target: { value: 'comment', checked: false } }));
expect(wrapper.find('input').length).toBe(4);
});
});
8 changes: 8 additions & 0 deletions src/__tests__/components/Routes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ describe('<Routes />', () => {
</Provider>);
expect(component.find(Home)).toHaveLength(1);
});
test('renders <Home /> without crashing', () => {
const component = mount(<Provider store={store}>
<MemoryRouter initialEntries={['/']}>
<Routes isAuth={true} />
</MemoryRouter>
</Provider>);
expect(component.find(Home)).toHaveLength(1);
});

test('renders <SocialMediaAuth /> without crashing', () => {
const component = mount(<Provider store={store}>
Expand Down
16 changes: 16 additions & 0 deletions src/__tests__/reducers/notification/createConfiguration.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import notification from '../../../__mocks__/notification';
import reducers from '../../../reducers';
import initialState from '../../../store/initialStates/notification';
import { notificationActionTypes } from '../../../actions-types';

describe('Notification reducer', () => {
test('CREATE_NOTIFICATION_CONFIGURATION_SUCCESS', () => {
const reducer = reducers.notification(initialState, {
type: notificationActionTypes.CREATE_NOTIFICATION_CONFIGURATION_SUCCESS,
payload: { ...notification }
});

expect(reducer).toHaveProperty('config');
expect.objectContaining('config');
});
});
40 changes: 40 additions & 0 deletions src/__tests__/reducers/notification/getConfiguration.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import notification from '../../../__mocks__/notification';
import reducers from '../../../reducers';
import initialState from '../../../store/initialStates/notification';
import { notificationActionTypes } from '../../../actions-types';

describe('Notification reducers', () => {
test('GET_NOTIFICATION_CONFIGURATION_START', () => {
const reducer = reducers.notification(initialState, {
type: notificationActionTypes.GET_NOTIFICATION_CONFIGURATION_START,
payload: { loading: true }
});
expect(reducer.getNotificationConfiguration).toHaveProperty('loading');
expect(reducer.getNotificationConfiguration.loading).toBeTruthy();
});

test('GET_NOTIFICATION_CONFIGURATION_SUCCESS', () => {
const reducer = reducers.notification(initialState, {
type: notificationActionTypes.GET_NOTIFICATION_CONFIGURATION_SUCCESS,
payload: { ...notification }
});
expect(reducer).toHaveProperty('config');
expect.objectContaining('config');
});
test('GET_NOTIFICATION_CONFIGURATION_FAILURE', () => {
const reducer = reducers.notification(initialState, {
type: notificationActionTypes.GET_NOTIFICATION_CONFIGURATION_FAILURE,
payload: { errors: false }
});
expect(reducer.getNotificationConfiguration).toHaveProperty('errors');
});

test('GET_NOTIFICATION_CONFIGURATION_END', () => {
const reducer = reducers.notification(initialState, {
type: notificationActionTypes.GET_NOTIFICATION_CONFIGURATION_END,
payload: { loading: false }
});
expect(reducer.getNotificationConfiguration).toHaveProperty('loading');
expect(reducer.getNotificationConfiguration.loading).toBeFalsy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import notification from '../../../__mocks__/notification';
import reducers from '../../../reducers';
import initialState from '../../../store/initialStates/notification';
import { notificationActionTypes } from '../../../actions-types';

describe('Notification reducer', () => {
test('TOGGLE_NOTIFICATION_TYPE', () => {
Object.keys(notification.config).map((key) => {
const reducer = reducers.notification(initialState, {
type: notificationActionTypes.TOGGLE_NOTIFICATION_CONFIGURATION_TYPE,
payload: key
});
expect(reducer).toHaveProperty('config');
expect.objectContaining('config');
});
});

test('ADD_OPTION', () => {
Object.keys(notification.config).map((type, option) => {
const reducer = reducers.notification(initialState, {
type: notificationActionTypes.ADD_OPTION,
payload: { option, type }
});
expect(reducer).toHaveProperty('config');
expect.objectContaining('config');
});
});

test('REMOVE_OPTION', () => {
initialState.config.inApp.articles.on = ['publish', 'comment'];
Object.keys(notification.config).map((type, option) => {
const reducer = reducers.notification(initialState, {
type: notificationActionTypes.REMOVE_OPTION,
payload: { option: 'publish', type }
});
expect(reducer).toHaveProperty('config');
expect.objectContaining('config');
});
});
test('Default', () => {
const reducer = reducers.notification(initialState, {
type: null,
payload: null
});

expect(reducer).toHaveProperty('config');
expect.objectContaining([]);
});
});
Loading

0 comments on commit ffb8dc6

Please sign in to comment.