-
-
Notifications
You must be signed in to change notification settings - Fork 179
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
1 parent
1b3aa60
commit 3e1cbfa
Showing
17 changed files
with
612 additions
and
3 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 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<LastActiveSolutionConfig>Debug|Any CPU</LastActiveSolutionConfig> | ||
</PropertyGroup> | ||
</Project> |
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,2 @@ | ||
import mockAxios from 'jest-mock-axios'; | ||
export default mockAxios; |
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,24 @@ | ||
|
||
import configureMockStore from 'redux-mock-store'; | ||
import thunk from 'redux-thunk'; | ||
const middlewares = [thunk]; | ||
const mockStore = configureMockStore(middlewares); | ||
|
||
let initialState; | ||
initialState = { | ||
app: { | ||
userData: { | ||
authToken: "eyJhbGciOiJIUtI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFybCI6ImFueXRoaW5nQGNib2FyZC5pbyIsImlkIjoiNWJjZmE0ZWQ0OTRiMjAwMDBmOGFiOThiIiwiaXNzdWVyIjoiY2JvYXJkLmlvIiwiaWF0IjoxNTU5NzU1NTU3fQ.2ENI4GyaHwV1B-Pifi0ZUKqyGcjTSLDV0UoPKUY99bo", | ||
email: "[email protected]", | ||
id: "5bcfa4ed494b20000f8ab98b", | ||
lastlogin: "2018-10-23T22:47:09.367Z", | ||
locale: "en-US", | ||
name: "martin bedouret", | ||
provider: "", | ||
role: "user" | ||
} | ||
} | ||
}; | ||
const store = mockStore(initialState); | ||
|
||
export const getStore = () => store; |
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 * as helpers from '../helpers'; | ||
describe('helpers', () => { | ||
|
||
it('should create a file from data', () => { | ||
const dataUrl = "data:text/plain;charset=utf-8;base64,dGVzdGluZw=="; | ||
const file = helpers.dataURLtoFile(dataUrl, 'myfile'); | ||
expect(file.name).toBe("myfile"); | ||
}); | ||
it('should create a file with ext from data', () => { | ||
const dataUrl = "data:text/plain;charset=utf-8;base64,dGVzdGluZw=="; | ||
const file = helpers.dataURLtoFile(dataUrl, 'myfile.txt', true); | ||
expect(file.name).toBe('myfile.txt.plain'); | ||
}); | ||
}); |
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,21 @@ | ||
import * as i18n from '../i18n'; | ||
describe('i18n', () => { | ||
|
||
it('should import translation data', () => { | ||
i18n.importTranslation('es-ES') | ||
.then((lang) => { | ||
expect(lang.cboard.components.WelcomeScreen.login).toBe("Iniciar sesión"); | ||
}); | ||
}); | ||
it('should strip Region Code', () => { | ||
expect(i18n.stripRegionCode('es-ES')).toBe("es"); | ||
}); | ||
it('should normalize Language Code', () => { | ||
expect(i18n.normalizeLanguageCode('ES-ES')).toBe("es-ES"); | ||
expect(i18n.normalizeLanguageCode('es-es')).toBe("es-ES"); | ||
}); | ||
it('should normalize Language Code for two', () => { | ||
expect(i18n.normalizeLanguageCode('ES')).toBe("es"); | ||
expect(i18n.normalizeLanguageCode('es')).toBe("es"); | ||
}); | ||
}); |
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,9 @@ | ||
|
||
import createReducer from '../reducers'; | ||
describe('reducers', () => { | ||
|
||
it('should create Reducer', () => { | ||
const red = createReducer(); | ||
expect(red).toBeDefined; | ||
}); | ||
}); |
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,42 @@ | ||
|
||
import register from '../registerServiceWorker'; | ||
import unregister from '../registerServiceWorker'; | ||
describe('registerServiceWorker', () => { | ||
|
||
global.navigator = Object.create(navigator); | ||
Object.defineProperty(navigator, 'serviceWorker', { | ||
value: { ready: false } | ||
}); | ||
global.process.env = Object.create(process.env); | ||
Object.defineProperty(process.env, 'NODE_ENV', { | ||
value: 'production' | ||
}); | ||
global.process.env = Object.create(process.env); | ||
Object.defineProperty(process.env, 'PUBLIC_URL', { | ||
value: 'https://app.cboard.io' | ||
}); | ||
global.window = Object.create(window); | ||
Object.defineProperty(window, 'location', { | ||
value: { | ||
href: 'https://app.cboard.io', | ||
origin: 'https://app.cboard.io' | ||
}, | ||
writable: true | ||
}); | ||
|
||
it('should register Service Worker', () => { | ||
const serviceWorker = register(jest.fn(), jest.fn()); | ||
expect(serviceWorker).toBeDefined; | ||
}); | ||
it('should register Service Worker localhost', () => { | ||
Object.defineProperty(window.location, 'hostname', { | ||
value: 'localhost' | ||
}); | ||
const serviceWorker = register(jest.fn(), jest.fn()); | ||
expect(serviceWorker).toBeDefined; | ||
}); | ||
it('should unregister Service Worker', () => { | ||
const serviceWorker = unregister(); | ||
expect(serviceWorker).toBeDefined; | ||
}); | ||
}); |
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,9 @@ | ||
|
||
import configureStore from '../store'; | ||
describe('store', () => { | ||
|
||
it('should configure Store', () => { | ||
const store = configureStore(); | ||
expect(store).toBeDefined; | ||
}); | ||
}); |
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,148 @@ | ||
|
||
import API from './api'; | ||
import mockAxios from 'jest-mock-axios'; | ||
|
||
let store; | ||
// allows us to easily return reponses and/or success/fail for a thunk that calls a service | ||
const mockServiceCreator = (body, succeeds = true) => () => | ||
new Promise((resolve, reject) => { | ||
setTimeout(() => (succeeds ? resolve(body) : reject(body)), 10); | ||
}); | ||
|
||
describe('Cboard API calls', () => { | ||
let initialState; | ||
// set up a fake store for all our tests | ||
beforeEach(() => { | ||
}); | ||
afterEach(() => { | ||
// cleaning up the mess left behind the previous test | ||
mockAxios.reset(); | ||
}); | ||
|
||
it("fetches results from get language api", () => { | ||
let catchFn = jest.fn(), thenFn = jest.fn(); | ||
|
||
//call method | ||
API.getLanguage('es-ES') | ||
.then(thenFn) | ||
.catch(catchFn); | ||
// simulating a server response | ||
let responseObj = { data: 'fake!' }; | ||
mockAxios.mockResponse(responseObj); | ||
}); | ||
it("fetches results from get my boards api", () => { | ||
let catchFn = jest.fn(), thenFn = jest.fn(); | ||
|
||
//call method | ||
API.getMyBoards(1, 10) | ||
.then(thenFn) | ||
.catch(catchFn); | ||
}); | ||
it("fetches results from get boards api", () => { | ||
let catchFn = jest.fn(), thenFn = jest.fn(); | ||
|
||
//call method | ||
API.getBoards(1) | ||
.then(thenFn) | ||
.catch(catchFn); | ||
}); | ||
it("fetches results from get board api", () => { | ||
let catchFn = jest.fn(), thenFn = jest.fn(); | ||
|
||
//call method | ||
API.getBoard('aaaa') | ||
.then(thenFn) | ||
.catch(catchFn); | ||
}); | ||
it("fetches results from get communicators api", () => { | ||
let catchFn = jest.fn(), thenFn = jest.fn(); | ||
|
||
//call method | ||
API.getCommunicators(1,10) | ||
.then(thenFn) | ||
.catch(catchFn); | ||
}); | ||
it("fetches results from createBoard api", () => { | ||
let catchFn = jest.fn(), thenFn = jest.fn(); | ||
const board = { | ||
"name": "board_name", | ||
"author": "Postman Test", | ||
"email": "[email protected]", | ||
"format": "obf", | ||
"tiles": [ | ||
{} | ||
], | ||
"caption": "string", | ||
"isPublic": true, | ||
"locale": "ar-SA" | ||
} | ||
//call method | ||
API.createBoard(board) | ||
.then(thenFn) | ||
.catch(catchFn); | ||
}); | ||
it("fetches results from createCommunicator api", () => { | ||
let catchFn = jest.fn(), thenFn = jest.fn(); | ||
const comm = { | ||
"name": "comm_name", | ||
"author": "Postman Test", | ||
"email": "[email protected]", | ||
"rootBoard": "obf", | ||
"boards": [ | ||
{} | ||
] | ||
}; | ||
//call method | ||
API.createCommunicator(comm) | ||
.then(thenFn) | ||
.catch(catchFn); | ||
}); | ||
it("fetches results from arasaacPictogramsSearch api", () => { | ||
let catchFn = jest.fn(), thenFn = jest.fn(); | ||
//call method | ||
API.arasaacPictogramsSearch('es','perro') | ||
.then(thenFn) | ||
.catch(catchFn); | ||
// simulating a server response | ||
let responseObj = { data: 'fake!' }; | ||
mockAxios.mockResponse(responseObj); | ||
}); | ||
it("fetches results from deleteBoard api", () => { | ||
let catchFn = jest.fn(), thenFn = jest.fn(); | ||
//call method | ||
API.deleteBoard('esnm') | ||
.then(thenFn) | ||
.catch(catchFn); | ||
}); | ||
it("fetches results from login api", () => { | ||
let catchFn = jest.fn(), thenFn = jest.fn(); | ||
const user = { | ||
"email": "[email protected]", | ||
"password": "123456" | ||
} | ||
//call method | ||
API.login(user) | ||
.then(thenFn) | ||
.catch(catchFn); | ||
// simulating a server response | ||
let responseObj = { data: 'fake!' }; | ||
mockAxios.mockResponse(responseObj); | ||
}); | ||
it("fetches results from tawasolPictogramsSearch api", () => { | ||
let catchFn = jest.fn(), thenFn = jest.fn(); | ||
//call method | ||
API.tawasolPictogramsSearch('es', 'perro') | ||
.then(thenFn) | ||
.catch(catchFn); | ||
// simulating a server response | ||
let responseObj = { data: 'fake!' }; | ||
mockAxios.mockResponse(responseObj); | ||
}); | ||
it("fetches results from uploadFromDataURL api", () => { | ||
let catchFn = jest.fn(), thenFn = jest.fn(); | ||
//call method | ||
API.uploadFromDataURL('es', 'perro') | ||
.then(thenFn) | ||
.catch(catchFn); | ||
}); | ||
}); |
38 changes: 38 additions & 0 deletions
38
src/components/Account/Activate/__tests__/Activate.actions.test.js
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,38 @@ | ||
|
||
import * as ac from '../Activate.actions'; | ||
import mockAxios from 'jest-mock-axios'; | ||
import { API_URL } from '../../../../constants'; | ||
|
||
afterEach(() => { | ||
// cleaning up the mess left behind the previous test | ||
mockAxios.reset(); | ||
}); | ||
|
||
describe('Activate actions', () => { | ||
global.window = Object.create(window); | ||
Object.defineProperty(window, 'location', { | ||
value: { | ||
href: 'https://app.cboard.io', | ||
origin: 'https://app.cboard.io' | ||
}, | ||
writable: true | ||
}); | ||
it("fetches results from get language api", () => { | ||
|
||
const url = 'asdf'; | ||
|
||
let catchFn = jest.fn(), | ||
thenFn = jest.fn(); | ||
|
||
//call method | ||
ac.activate(url) | ||
.then(thenFn) | ||
.catch(catchFn); | ||
expect(mockAxios.post).toHaveBeenCalledWith(`${API_URL}/user/activate/${url}`); | ||
// simulating a server response | ||
let responseObj = { data: 'activated!' }; | ||
mockAxios.mockResponse(responseObj); | ||
|
||
|
||
}); | ||
}); |
Oops, something went wrong.