-
Notifications
You must be signed in to change notification settings - Fork 7
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
42 changed files
with
981 additions
and
223 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,4 @@ | ||
export const loginPayload = { | ||
token: 'test token', | ||
user: { email: 'test user' } | ||
} |
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,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); | ||
}); | ||
}); |
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,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"); | ||
}); | ||
}); | ||
}); |
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,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); | ||
}); | ||
}); | ||
}); |
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,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); | ||
}); | ||
}); |
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,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(); | ||
}); | ||
}); |
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,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); | ||
})); | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Oops, something went wrong.