Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(client-test): setup client side testing
- Loading branch information
Showing
104 changed files
with
5,230 additions
and
1,004 deletions.
There are no files selected for viewing
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,6 @@ | ||
#!/bin/bash | ||
while read FILENAME; do | ||
LCOV_INPUT_FILES="$LCOV_INPUT_FILES -a \"$FILENAME\"" | ||
done < <( find $1 -name lcov.info ) | ||
|
||
eval lcov "${LCOV_INPUT_FILES}" -o $1/$2 |
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 |
---|---|---|
|
@@ -8,4 +8,7 @@ coverage/ | |
.nyc_output/ | ||
.DS_STORE | ||
client/build | ||
.vscode | ||
.vscode | ||
e2e-tests | ||
e2e-test-output | ||
nightwatch.** |
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
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 |
---|---|---|
|
@@ -18,4 +18,6 @@ DISQUS_SHORT_NAME= | |
ROOT_URL= | ||
|
||
TIMEZONE= | ||
SOCKET_URL= | ||
SOCKET_URL= | ||
|
||
API_VERSION= |
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
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,41 @@ | ||
export const bookData = { | ||
title: 'A new title', | ||
coverPhotoPath: '', | ||
documentPath: '' | ||
}; | ||
|
||
export const response = { | ||
message: ['Book added successfully'], | ||
book: { | ||
title: 'A new book title', | ||
id: 1 | ||
}, | ||
id: 1 | ||
}; | ||
|
||
export const searchResponse = { | ||
data: { | ||
...response.book | ||
} | ||
}; | ||
|
||
export const getBookResponse = { | ||
books: { ...response.book }, | ||
pagination: { | ||
pageSize: 1, | ||
totalCount: 10, | ||
page: 0, | ||
pageCount: 1, | ||
limit: 10 | ||
}, | ||
message: ['There was an unexpected error'] | ||
}; | ||
|
||
export const responseFailure = { | ||
message: ['The title field is required'] | ||
}; | ||
|
||
export const signinResponseFailure = { | ||
message: ['Sorry, we can\'t find this account'] | ||
}; | ||
|
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 @@ | ||
export default {}; |
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,46 @@ | ||
|
||
/** | ||
* @class localStorage | ||
*/ | ||
class localStorage { | ||
/** | ||
* @static | ||
* @param {any} key | ||
* @param {any} value | ||
* @returns {object} setItem | ||
* @memberOf localStorage | ||
*/ | ||
static setItem(key, value) { | ||
return Object.assign(localStorage, { [key]: value }); | ||
} | ||
|
||
/** | ||
* @static | ||
* @param {any} key | ||
* @returns {object} item | ||
* @memberOf localStorage | ||
*/ | ||
static getItem(key) { | ||
return localStorage[key]; | ||
} | ||
|
||
/** | ||
* @static | ||
* @param {any} key | ||
* @returns {undefined} | ||
* @memberOf localStorage | ||
*/ | ||
static removeItem(key) { | ||
delete localStorage[key]; | ||
} | ||
|
||
/** | ||
* @static | ||
* @returns {undefined} | ||
* @memberOf localStorage | ||
*/ | ||
static clear() { | ||
localStorage = {}; | ||
} | ||
} | ||
export default localStorage; |
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 @@ | ||
export default {}; |
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,17 @@ | ||
|
||
export const response = { | ||
message: ['Your account has been created successfully'], | ||
payload: { | ||
group: 'user', | ||
userId: 1, | ||
} | ||
}; | ||
|
||
export const signupResponseFailure = { | ||
message: ['The name field is required'] | ||
}; | ||
|
||
export const signinResponseFailure = { | ||
message: ['Sorry, we can\'t find this account'] | ||
}; | ||
|
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 @@ | ||
export default Object.create(null); |
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,145 @@ | ||
import moxios from 'moxios'; | ||
import thunk from 'redux-thunk'; | ||
import configureMockStore from 'redux-mock-store'; | ||
import expect from 'expect'; | ||
|
||
import { | ||
login, | ||
logout | ||
} from 'actions/auth'; | ||
import { userSignupRequestAction } from 'actions/signupActions'; | ||
import { response, signupResponseFailure, signinResponseFailure } from '../__mocks__/user'; | ||
|
||
/* eslint-disable max-nested-callbacks */ | ||
|
||
const mockStore = configureMockStore([ | ||
thunk | ||
]); | ||
|
||
describe('# Auth', () => { | ||
beforeEach(() => moxios.install()); | ||
afterEach(() => moxios.uninstall()); | ||
|
||
describe('# Signup', () => { | ||
it('creates SET_CURRENT_USER when signup action is successful', () => { | ||
moxios.wait(() => { | ||
const request = moxios.requests.mostRecent(); | ||
request.respondWith({ | ||
status: 200, | ||
response: response, | ||
}); | ||
}); | ||
|
||
const expectedActions = [ | ||
{ | ||
type: 'ADD_FLASH_MESSAGE', | ||
message: { | ||
text: ['Your account has been created successfully'], | ||
type: 'success' | ||
} | ||
}, | ||
{ type: 'SET_CURRENT_USER', user: response.payload } | ||
]; | ||
|
||
const store = mockStore({ }); | ||
return store.dispatch(userSignupRequestAction({})) | ||
.then(() => { | ||
expect(store.getActions()).toEqual(expectedActions); | ||
}); | ||
}); | ||
|
||
it('should not create a user when signup action fails', () => { | ||
moxios.wait(() => { | ||
const request = moxios.requests.mostRecent(); | ||
request.respondWith({ | ||
status: 400, | ||
response: signupResponseFailure, | ||
}); | ||
}); | ||
|
||
const expectedActions = [ | ||
{ | ||
type: 'ADD_FLASH_MESSAGE', | ||
message: { | ||
text: ['The name field is required'], | ||
type: 'error' | ||
} | ||
} | ||
]; | ||
|
||
const store = mockStore({}); | ||
return store.dispatch(userSignupRequestAction({})).then(() => { | ||
expect(store.getActions()).toEqual(expectedActions); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('# Signin', () => { | ||
it('should create SET_CURRENT_USER when signin action is successful', () => { | ||
moxios.wait(() => { | ||
const request = moxios.requests.mostRecent(); | ||
request.respondWith({ | ||
status: 200, | ||
response: response, | ||
}); | ||
}); | ||
|
||
const expectedActions = [ | ||
{ type: 'SET_CURRENT_USER', user: response.payload } | ||
]; | ||
|
||
const store = mockStore({ }); | ||
return store.dispatch(login({})) | ||
.then(() => { | ||
expect(store.getActions()).toEqual(expectedActions); | ||
}); | ||
}); | ||
|
||
it('should not log a user in when signin action fails', () => { | ||
moxios.wait(() => { | ||
const request = moxios.requests.mostRecent(); | ||
request.respondWith({ | ||
status: 400, | ||
response: signinResponseFailure, | ||
}); | ||
}); | ||
|
||
const expectedActions = [ | ||
{ | ||
type: 'ADD_FLASH_MESSAGE', | ||
message: { | ||
text: ['Sorry, we can\'t find this account'], | ||
type: 'error' | ||
}, | ||
} | ||
]; | ||
|
||
const store = mockStore({ }); | ||
return store.dispatch(login({})) | ||
.then(() => { | ||
expect(store.getActions()).toEqual(expectedActions); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('# Logout', () => { | ||
it('should log a user out when the logout action is dispatched', (done) => { | ||
moxios.wait(() => { | ||
const request = moxios.requests.mostRecent(); | ||
request.respondWith({ | ||
status: 200, | ||
response: response, | ||
}); | ||
}); | ||
|
||
const expectedActions = [ | ||
{ type: 'SET_CURRENT_USER', user: {} } | ||
]; | ||
|
||
const store = mockStore({ }); | ||
store.dispatch(logout()); | ||
expect(store.getActions()).toEqual(expectedActions); | ||
done(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.