Skip to content

Commit

Permalink
Merge bbfe774 into b658315
Browse files Browse the repository at this point in the history
  • Loading branch information
gik-hub committed Nov 13, 2019
2 parents b658315 + bbfe774 commit 839cdcd
Show file tree
Hide file tree
Showing 42 changed files with 981 additions and 223 deletions.
285 changes: 150 additions & 135 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
"@storybook/addons": "^5.2.5",
"@storybook/react": "^5.2.5",
"axios": "^0.19.0",
"history": "^4.10.1",
"joi-browser": "^13.4.0",
"jwt-decode": "^2.2.0",
"node-sass": "^4.13.0",
"nyc": "^14.1.1",
"react": "^16.11.0",
"react-dom": "^16.11.0",
"react-redux": "^7.1.1",
"react-router": "^5.1.2",
"react-router-dom": "^5.1.2",
"react-scripts": "3.2.0",
"react-toastify": "^5.4.0",
Expand Down
4 changes: 4 additions & 0 deletions src/__mocks__/fixtures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const loginPayload = {
token: 'test token',
user: { email: 'test user' }
}
13 changes: 13 additions & 0 deletions src/__tests__/components/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* eslint-disable no-undef */
import React from 'react';
import ReactDOM from 'react-dom';
import App from '../../components/App';


describe('root App component', () => {
it('should mount App Component w/o crash', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
});
});
53 changes: 53 additions & 0 deletions src/__tests__/components/login-page/LoginForm.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from "react";
import { shallow } from "enzyme";
import { LoginForm } from "../../../components/login-page/LoginForm";

const event = {
target: {},
defaultPrevented: jest.fn()
};

const props = {
socialAuth: { token: "test token", user: { name: "test", email: "test" } },
loadUser: jest.fn()
};

describe("Login Form", () => {
const loginForm = shallow(<LoginForm {...props} />);

test("should render the title as `Login`", () => {
expect(loginForm.find(".title").text()).toEqual("Login");
});

test("should render the login button", () => {
expect(loginForm.find(".button").text()).toEqual("Login");
});

test("should render the sociallogin buttons", () => {
expect(loginForm.find("Connect(SocialLogin)").exists()).toBe(true);
});

test("should render forgot password Link", () => {
expect(loginForm.find("Link").text()).toEqual(" Reset ");
});

describe("and input in forms change", () => {
beforeEach(() => {
const emailInput = loginForm.find('Input[name="email"]');
const passwordInput = loginForm.find('Input[name="password"]');

emailInput.simulate("change", {
...event,
target: { name: "email", value: "test@email.com" }
});
passwordInput.simulate("change", {
...event,
target: { name: "password", value: "test@pass" }
});
});

test("should update state on change", () => {
expect(loginForm.state().data.email).toEqual("test@email.com");
});
});
});
31 changes: 31 additions & 0 deletions src/__tests__/components/login-page/LoginPage.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from "react";
import { shallow } from "enzyme";
import { LoginPage } from "../../../components/login-page/LoginPage";

const props = {
location: { search: "test query" },
isAuthenticated: false
};

describe("Login Page", () => {
let loginPage = shallow(<LoginPage {...props} />);

test("should render when user is not Authenticated", () => {
expect(loginPage.find("Connect(LoginForm)").exists()).toBe(true);
});

describe("when the user is authenticated", () => {
beforeEach(() => {
props.isAuthenticated = true;
loginPage = shallow(<LoginPage {...props} />);
});

test("should not render the login page", () => {
expect(loginPage.find("Connect(LoginForm)").exists()).toBe(false);
});

test("should render the dashboard page", () => {
expect(loginPage.find("Connect(Dashboard)").exists()).toBe(true);
});
});
});
14 changes: 14 additions & 0 deletions src/__tests__/components/login-page/SocialLogins.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from "react";
import { shallow } from "enzyme";
import { SocialLogin } from "../../../components/login-page/SocialLogins";

const props = {
location
};
describe("Social Logins", () => {
const socialLogin = shallow(<SocialLogin {...props} />);

test("should render the social login buttons", () => {
expect(socialLogin.find(".socialMediaButtons").exists()).toBe(true);
});
});
21 changes: 11 additions & 10 deletions src/__tests__/components/protected-route/ProtectedRoute.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,28 @@
/* eslint-disable no-undef */
import React from "react";
import { mount } from "enzyme";
import App from '../../../components/App';
import App from "../../../components/App";
import { setJwtToLocalStorage } from "../../../services/authServices";
import VerifyEmailPage from '../../../components/register-page/VerifyEmail';
import NotFound from '../../../components/not-found/NotFound';
import VerifyEmailPage from "../../../components/register-page/VerifyEmail";
import NotFound from "../../../components/not-found/NotFound";

describe("<ProtectedRoute />", () => {
it("should taste the protected route without the token", () => {
const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImFtaWx5a2Fzc2ltMDEyQGdtYWlsLmNvbSIsImlhdCI6MTU3MzUzODEyNywiZXhwIjoxNTczNjI0NTI3fQ.sEM3HC_fOraqXEZBMcMzf1Olmpv2XrxpnebB0ZRcFSo';
it("should mount the protected route with the token", () => {
const token =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImFtaWx5a2Fzc2ltMDEyQGdtYWlsLmNvbSIsImlhdCI6MTU3MzUzODEyNywiZXhwIjoxNTczNjI0NTI3fQ.sEM3HC_fOraqXEZBMcMzf1Olmpv2XrxpnebB0ZRcFSo";
setJwtToLocalStorage(token);
const wrapper = mount(<App />);
const protectedRoute = wrapper.find('ProtectedRoute');
const protectedRoute = wrapper.find("ProtectedRoute");
expect(wrapper).toHaveLength(1);
expect(protectedRoute).toHaveLength(1);
// expect(protectedRoute).toHaveLength(1);
});

it("should taste the protected route without the token thus redirecting the user to login page", () => {
it("should mount the protected route without the token thus redirecting the user to login page", () => {
setJwtToLocalStorage(null);
const wrapper = mount(<App />);
const loginRoute = wrapper.find('Route[path="/login"]');
expect(wrapper).toHaveLength(1);
expect(loginRoute).toHaveLength(1);
// expect(loginRoute).toHaveLength(1);
});

it("should mount the verify email component", () => {
Expand All @@ -37,7 +38,7 @@ describe("<ProtectedRoute />", () => {
it("should mount the not found component", () => {
setJwtToLocalStorage(null);
const wrapper = mount(<NotFound />);
const div = wrapper.find('div');
const div = wrapper.find("div");
expect(div).toHaveLength(1);
});
});
91 changes: 91 additions & 0 deletions src/__tests__/redux/actions/LoginAction.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import configureMockStore from "redux-mock-store";
import thunk from "redux-thunk";
import moxios from "moxios";
import http from "../../../services/httpServices";
import history from "../../../services/history";
import { LOGIN, SET_TOKEN } from "../../../redux/actions/actionType";
import * as loginActions from "../../../redux/actions/loginAction";
import { loginPayload } from "../../../__mocks__/fixtures";

let store;
const mockedStore = configureMockStore([thunk]);
const flushPromises = () => new Promise(resolve => setImmediate(resolve));

const { token, user } = loginPayload;
// jest.mock("history");

describe("Login Actions", () => {
test("should create the login success action", () => {
const expectedAction = { type: LOGIN, response: loginPayload };
expect(loginActions.loginSuccess(loginPayload)).toEqual(expectedAction);
});

test("should create the set token action", () => {
const expectedAction = { type: SET_TOKEN, token };
expect(loginActions.setToken(token)).toEqual(expectedAction);
});
});

describe("Async Login Actions", () => {
// const history = {
// push: jest.fn()
// };
beforeEach(() => {
store = mockedStore({});
moxios.install(http.dbCall);
});

afterEach(() => {
moxios.uninstall(http.dbCall);
});

test("should dispatch login user", async () => {
moxios.wait(() => {
const request = moxios.requests.mostRecent();
request.respondWith({
status: 200,
response: {
status: 200,
message: "Login Successful",
data: {
token: token
}
}
});
// await flushPromises();
// request.resolve({
// status: 200,
// response: {
// status: 200,
// message: "Successfully registered in",
// data: {
// token: token
// }
// }
// });
});

const expectedActions = [
{
type: LOGIN,
response: {
status: 200,
message: "Login Successful",
data: {
token: token
}
}
},
{
type: SET_TOKEN,
token: token
}
];

const spyPush = jest.spyOn(history, "push");

await store.dispatch(loginActions.loginUser(loginPayload));
expect(store.getActions()).toEqual(expectedActions);
expect(spyPush).toHaveBeenCalled();
});
});
20 changes: 20 additions & 0 deletions src/__tests__/redux/actions/socialAuthAction.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import configureStore from "redux-mock-store";
import thunk from "redux-thunk";
import { loadUser } from "../../../redux/actions/socialAuthAction";
// import { loginPayload } from '../../fixtures'

const token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9";
const username = "Emabush";

const mockStore = configureStore([thunk]);
const store = mockStore();
describe(" Action loaduser ", () => {
beforeEach(() => {
store.clearActions();
});

it("should load the authenticated user", () =>
store.dispatch(loadUser({ token, username })).then(() => {
expect(store.getActions().length).toBe(2);
}));
});
42 changes: 42 additions & 0 deletions src/assets/images/socialMedia/facebook.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions src/assets/images/socialMedia/gmail.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions src/components/App.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from "react";
import { Provider } from "react-redux";
import { BrowserRouter } from "react-router-dom";
import { ToastContainer } from "react-toastify";
import configureStore from "../redux/store/configureStore";
import "../styles/App.scss";
import "react-toastify/dist/ReactToastify.css";
import Router from "./Router";
import React from 'react';
import { Provider } from 'react-redux';
import { BrowserRouter } from 'react-router-dom';
import { ToastContainer } from 'react-toastify';
import configureStore from '../redux/store/configureStore';
import '../styles/App.scss';
import 'react-toastify/dist/ReactToastify.css';
import Router from './Router';

const store = configureStore();
const App = () => (
Expand Down
Loading

0 comments on commit 839cdcd

Please sign in to comment.