Skip to content

Redux Tests #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jun 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
sudo: required
language: node_js
node_js:
- "4.1"
- "5.3"
- "6.0"
branches:
only:
- master
- phase-1
env:
global:
- CXX=g++-4.8
Expand All @@ -19,13 +17,15 @@ addons:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
before_script:
before_install:
- npm cache clean
- npm install -g grunt-cli
- if [ "$GIT_VERSION" = "edge" ]; then sudo add-apt-repository ppa:git-core/ppa -y && sudo apt-get update -q && sudo apt-get install -y git; fi
- git config --global user.email "test@testy.com"
- git config --global user.name "Test testy"
- git version
- grunt -d
after_script:
- grunt travisnpmpublish
install:
- npm install

script:
- node -v
- npm run test-react
23 changes: 23 additions & 0 deletions config/localStorageMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class LocalStorageMock {
constructor() {
this.store = {};
}

clear() {
this.store = {};
}

getItem(key) {
return this.store[key];
}

setItem(key, value) {
this.store[key] = value.toString();
}

removeItem(key) {
delete this.store[key];
}
};

global.localStorage = new LocalStorageMock;
15 changes: 11 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"react-dom": "^15.5.4",
"react-redux": "^5.0.4",
"redux": "^3.6.0",
"redux-thunk": "^2.2.0",
"redux-api-middleware": "^1.0.3",
"rimraf": "~2.6.1",
"semver": "~5.3.0",
"serve-static": "~1.12.2",
Expand Down Expand Up @@ -125,13 +125,16 @@
"jest": "18.1.0",
"json-loader": "0.5.4",
"mocha": "~3.3.0",
"nock": "^9.0.13",
"node-sass": "^4.5.3",
"object-assign": "4.1.1",
"phantomjs-prebuilt": "~2.1.14",
"postcss-loader": "1.2.2",
"promise": "7.1.1",
"react-dev-utils": "^0.5.2",
"redux-mock-store": "^1.2.3",
"sass-loader": "^6.0.5",
"sinon": "^2.3.4",
"style-loader": "0.13.1",
"supertest": "~3.0.0",
"url-loader": "0.5.7",
Expand All @@ -145,10 +148,11 @@
"src/**/*.{js,jsx}"
],
"setupFiles": [
"<rootDir>/config/polyfills.js"
"<rootDir>/config/polyfills.js",
"<rootDir>/config/localStorageMock.js"
],
"testPathIgnorePatterns": [
"<rootDir>[/\\\\](build|docs|node_modules|scripts)[/\\\\]"
"<rootDir>[/\\\\](build|docs|node_modules|scripts|clicktests)[/\\\\]"
],
"testEnvironment": "node",
"testURL": "http://localhost",
Expand All @@ -162,7 +166,10 @@
],
"moduleNameMapper": {
"^react-native$": "react-native-web"
}
},
"modulePaths": [
"src-react"
]
},
"babel": {
"presets": [
Expand Down
5 changes: 5 additions & 0 deletions scripts/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
'use strict';
const regeneratorRuntime = require('babel-runtime/regenerator');

if (!regeneratorRuntime.default) {
regeneratorRuntime.default = regeneratorRuntime;
}

process.env.NODE_ENV = 'test';
process.env.PUBLIC_URL = '';
Expand Down
22 changes: 22 additions & 0 deletions src-react/__tests__/actions/ungit-config.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { CALL_API } from 'redux-api-middleware';
import expect from 'expect.js';

import * as types from 'constants/action-types';
import { fetchUngitConfig } from 'actions/ungit-config';

describe('ungit-config.js action', () => {
describe('fetchUngitConfig', () => {
it('returns CALL_API action object', function(){
const action = fetchUngitConfig();

expect(action[CALL_API]).to.be.an('object');
expect(action[CALL_API].endpoint).to.eql('http://localhost:8448/ungit/config');
expect(action[CALL_API].method).to.eql('GET');
expect(action[CALL_API].types).to.be.an('array');
expect(action[CALL_API].types[0]).to.eql(types.FETCH_UNGIT_CONFIG_REQUEST);
expect(action[CALL_API].types[1]).to.be.an('object');
expect(action[CALL_API].types[1].type).to.eql(types.FETCH_UNGIT_CONFIG_SUCCESS);
expect(action[CALL_API].types[2]).to.eql(types.FETCH_UNGIT_CONFIG_FAILURE);
});
});
});
21 changes: 21 additions & 0 deletions src-react/__tests__/actions/user-config.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { CALL_API } from 'redux-api-middleware';
import expect from 'expect.js';

import * as types from 'constants/action-types';
import { fetchUserConfig } from 'actions/user-config';

describe('user-config.js action', () => {
describe('fetchUserConfig', () => {
it('returns CALL_API action object', function(){
const action = fetchUserConfig();

expect(action[CALL_API]).to.be.an('object');
expect(action[CALL_API].endpoint).to.eql('http://localhost:8448/api/userconfig');
expect(action[CALL_API].method).to.eql('GET');
expect(action[CALL_API].types).to.be.an('array');
expect(action[CALL_API].types[0]).to.eql(types.FETCH_USER_CONFIG_REQUEST);
expect(action[CALL_API].types[1]).to.eql(types.FETCH_USER_CONFIG_SUCCESS);
expect(action[CALL_API].types[2]).to.eql(types.FETCH_USER_CONFIG_FAILURE);
});
});
});
35 changes: 35 additions & 0 deletions src-react/__tests__/actions/version.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { CALL_API } from 'redux-api-middleware';
import expect from 'expect.js';

import * as types from 'constants/action-types';
import { fetchLatestVersion, fetchGitVersion } from 'actions/version';

describe('version.js action', () => {
describe('fetchLatestVersion', () => {
it('returns CALL_API action object', function(){
const action = fetchLatestVersion();

expect(action[CALL_API]).to.be.an('object');
expect(action[CALL_API].endpoint).to.eql('http://localhost:8448/api/latestversion');
expect(action[CALL_API].method).to.eql('GET');
expect(action[CALL_API].types).to.be.an('array');
expect(action[CALL_API].types[0]).to.eql(types.FETCH_LATEST_VERSION_REQUEST);
expect(action[CALL_API].types[1]).to.eql(types.FETCH_LATEST_VERSION_SUCCESS);
expect(action[CALL_API].types[2]).to.eql(types.FETCH_LATEST_VERSION_FAILURE);
});
});

describe('fetchGitVersion', () => {
it('returns CALL_API action object', function(){
const action = fetchGitVersion();

expect(action[CALL_API]).to.be.an('object');
expect(action[CALL_API].endpoint).to.eql('http://localhost:8448/api/gitversion');
expect(action[CALL_API].method).to.eql('GET');
expect(action[CALL_API].types).to.be.an('array');
expect(action[CALL_API].types[0]).to.eql(types.FETCH_GIT_VERSION_REQUEST);
expect(action[CALL_API].types[1]).to.eql(types.FETCH_GIT_VERSION_SUCCESS);
expect(action[CALL_API].types[2]).to.eql(types.FETCH_GIT_VERSION_FAILURE);
});
});
});
79 changes: 79 additions & 0 deletions src-react/__tests__/middlewares/redux-api/ungit-config.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import nock from 'nock';
import sinon from 'sinon';
import expect from 'expect.js';
import configureStore from 'redux-mock-store';
import { createStore, applyMiddleware } from 'redux';
import { apiMiddleware, CALL_API } from 'redux-api-middleware';

import * as types from 'constants/action-types';
import { fetchUngitConfig } from 'actions/ungit-config';

const createMockStore = configureStore([ apiMiddleware ]);

describe('redux-api-middleware::ungit-config', () => {
describe('fetchUngitConfig successfully', () => {
const mockPayload = { message: 'success' };

beforeEach(() => {
nock('http://localhost:8448')
.get('/ungit/config')
.reply(200, mockPayload);

nock('http://localhost:8448')
.get('/api/userconfig')
.reply(200, mockPayload);
});

it('should dispatch \'FETCH_UNGIT_CONFIG_REQUEST\'', done => {
const store = createMockStore({});

store.subscribe(() => {
const dispatchedActions = store.getActions();
if (dispatchedActions.length === 1) {
expect(dispatchedActions[0].type).to.eql(types.FETCH_UNGIT_CONFIG_REQUEST);
done();
}
});
store.dispatch(fetchUngitConfig());
});

it('should dispatch \'FETCH_UNGIT_CONFIG_SUCCESS\'', done => {
const store = createMockStore({});

store.subscribe(() => {
const dispatchedActions = store.getActions();
if (dispatchedActions.length === 2) {
expect(dispatchedActions[0].type).to.eql(types.FETCH_UNGIT_CONFIG_REQUEST);
expect(dispatchedActions[1].type).to.eql(types.FETCH_UNGIT_CONFIG_SUCCESS);
expect(dispatchedActions[1].payload).to.eql(mockPayload);
done();
}
});
store.dispatch(fetchUngitConfig());
});
});

describe('fetchUngitConfig fails', () => {

beforeEach(() => {
nock('http://localhost:8448')
.get('/ungit/config')
.reply(500, null);
});

it('should dispatch \'FETCH_UNGIT_CONFIG_FAILURE\'', done => {
const store = createMockStore({});

store.subscribe(() => {
const dispatchedActions = store.getActions();
if (dispatchedActions.length === 2) {
expect(dispatchedActions[0].type).to.eql(types.FETCH_UNGIT_CONFIG_REQUEST);
expect(dispatchedActions[1].type).to.eql(types.FETCH_UNGIT_CONFIG_FAILURE);
expect(dispatchedActions[1].payload).to.be.an('object');
done();
}
});
store.dispatch(fetchUngitConfig());
});
});
});
75 changes: 75 additions & 0 deletions src-react/__tests__/middlewares/redux-api/user-config.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import nock from 'nock';
import sinon from 'sinon';
import expect from 'expect.js';
import configureStore from 'redux-mock-store';
import { createStore, applyMiddleware } from 'redux';
import { apiMiddleware, CALL_API } from 'redux-api-middleware';

import * as types from 'constants/action-types';
import { fetchUserConfig } from 'actions/user-config';

const createMockStore = configureStore([ apiMiddleware ]);

describe('redux-api-middleware::user-config', () => {
describe('fetchUserConfig successfully', () => {
const mockPayload = { message: 'success' };

beforeEach(() => {
nock('http://localhost:8448')
.get('/api/userconfig')
.reply(200, mockPayload);
});

it('should dispatch \'FETCH_USER_CONFIG_REQUEST\'', done => {
const store = createMockStore({});

store.subscribe(() => {
const dispatchedActions = store.getActions();
if (dispatchedActions.length === 1) {
expect(dispatchedActions[0].type).to.eql(types.FETCH_USER_CONFIG_REQUEST);
done();
}
});
store.dispatch(fetchUserConfig());
});

it('should dispatch \'FETCH_USER_CONFIG_SUCCESS\'', done => {
const store = createMockStore({});

store.subscribe(() => {
const dispatchedActions = store.getActions();
if (dispatchedActions.length === 2) {
expect(dispatchedActions[0].type).to.eql(types.FETCH_USER_CONFIG_REQUEST);
expect(dispatchedActions[1].type).to.eql(types.FETCH_USER_CONFIG_SUCCESS);
expect(dispatchedActions[1].payload).to.eql(mockPayload);
done();
}
});
store.dispatch(fetchUserConfig());
});
});

describe('fetchUserConfig fails', () => {

beforeEach(() => {
nock('http://localhost:8448')
.get('/api/userconfig')
.reply(500, null);
});

it('should dispatch \'FETCH_USER_CONFIG_FAILURE\'', done => {
const store = createMockStore({});

store.subscribe(() => {
const dispatchedActions = store.getActions();
if (dispatchedActions.length === 2) {
expect(dispatchedActions[0].type).to.eql(types.FETCH_USER_CONFIG_REQUEST);
expect(dispatchedActions[1].type).to.eql(types.FETCH_USER_CONFIG_FAILURE);
expect(dispatchedActions[1].payload).to.be.an('object');
done();
}
});
store.dispatch(fetchUserConfig());
});
});
});
Loading