diff options
| -rw-r--r-- | test/actions.spec.js | 47 | ||||
| -rw-r--r-- | test/actions/user.spec.js | 117 | ||||
| -rw-r--r-- | test/enum.spec.js | 22 | ||||
| -rw-r--r-- | test/lib/enum.spec.js | 26 | ||||
| -rw-r--r-- | test/reducers.spec.js | 41 | ||||
| -rw-r--r-- | test/reducers/user.spec.js | 25 |
6 files changed, 110 insertions, 168 deletions
diff --git a/test/actions.spec.js b/test/actions.spec.js new file mode 100644 index 0000000000..1303bd7f39 --- /dev/null +++ b/test/actions.spec.js @@ -0,0 +1,47 @@ +import { expect } from 'chai'; +import userActions from '../app/actions/user'; +import connectActions from '../app/actions/connect'; +import settingsActions from '../app/actions/settings'; +import { LoginState, ConnectionState, defaultServer } from '../app/constants'; + +describe('actions', () => { + + it('should create action for USER_LOGIN_CHANGE', () => { + const test = { + type: userActions.loginChange.toString(), + payload: { + account: '1111', + status: LoginState.failed, + error: new Error('Something went wrong') + } + }; + const payload = Object.assign({}, test.payload); + expect(userActions.loginChange(payload)).to.deep.equal(test); + }); + + it('should create action for CONNECTION_CHANGE', () => { + const test = { + type: connectActions.connectionChange.toString(), + payload: { + status: ConnectionState.connected, + serverAddress: '2.1.1.2', + clientIp: '2.1.1.1' + } + }; + const payload = Object.assign({}, test.payload); + expect(connectActions.connectionChange(payload)).to.deep.equal(test); + }); + + it('should create action for SETTINGS_UPDATE', () => { + const test = { + type: settingsActions.updateSettings.toString(), + payload: { + autoSecure: true, + preferredServer: defaultServer + } + }; + const payload = Object.assign({}, test.payload); + expect(settingsActions.updateSettings(payload)).to.deep.equal(test); + }); + +}); diff --git a/test/actions/user.spec.js b/test/actions/user.spec.js deleted file mode 100644 index b2c758d021..0000000000 --- a/test/actions/user.spec.js +++ /dev/null @@ -1,117 +0,0 @@ -import chai, { expect } from 'chai'; -import spy from 'chai-spies'; -import actions from '../../app/actions/user'; -import { LoginState } from '../../app/constants'; - -chai.use(spy); - -describe('actions', () => { - - describe('user', () => { - - it('should create action for USER_LOGIN_CHANGE', () => { - const test = { - type: actions.loginChange.toString(), - payload: { - account: '1111', - status: LoginState.failed, - error: new Error('Something went wrong') - } - }; - const payload = Object.assign({}, test.payload); - expect(actions.loginChange(payload)).to.deep.equal(test); - }); - - it('should successfully login', (done) => { - const actionType = actions.loginChange.toString(); - const account = '1234'; - const getState = () => ({}); - let callCounter = 0; - const dispatch = chai.spy(() => { - callCounter += 1; - - if(callCounter == 2) { - expect(dispatch).to.have.been.called.with({ - type: actionType, - payload: { account, status: LoginState.connecting } - }); - - expect(dispatch).to.have.been.called.with({ - type: actionType, - payload: { status: LoginState.ok } - }); - - done(); - } - }); - - const backend = { - login: () => Promise.resolve() - }; - - const action = actions.login(backend, account); - - action(dispatch, getState); - }); - - it('should fail login', (done) => { - const actionType = actions.loginChange.toString(); - const account = '1234'; - const getState = () => ({}); - let callCounter = 0; - const dispatch = chai.spy(() => { - callCounter += 1; - - if(callCounter == 2) { - expect(dispatch).to.have.been.called.with({ - type: actionType, - payload: { account, status: LoginState.connecting } - }); - - expect(dispatch).to.have.been.called.with({ - type: actionType, - payload: { status: LoginState.failed, error: new Error('Failed') } - }); - - done(); - } - }); - - const backend = { - login: () => Promise.reject(new Error('Failed')) - }; - - const action = actions.login(backend, account); - - action(dispatch, getState); - }); - - it('should log out', (done) => { - let callCount = 0; - const getState = () => ({ account: '1234', status: LoginState.ok }); - const dispatch = chai.spy( () => { - callCount += 1; - - if(callCount === 1) { - expect(dispatch).to.have.been.called.with({ - type: actions.loginChange.toString(), - payload: { - account: '', - status: LoginState.none, - error: null - } - }); - - done(); - } - }); - const backend = { - logout: () => Promise.resolve() - }; - const action = actions.logout(backend); - - action(dispatch, getState); - }); - - }); -}); diff --git a/test/enum.spec.js b/test/enum.spec.js new file mode 100644 index 0000000000..dec15b219c --- /dev/null +++ b/test/enum.spec.js @@ -0,0 +1,22 @@ +import { expect } from 'chai'; +import Enum from '../app/lib/enum'; + +describe('enum', () => { + it('should be able to compare values', () => { + const e = Enum('NORTH', 'SOUTH', 'WEST', 'EAST'); + expect(e.NORTH).to.be.equal('NORTH'); + }); + + it('should not be able to modify enum', () => { + let e = Enum('NORTH', 'SOUTH', 'WEST', 'EAST'); + expect(() => e.ANYWHERE = 'ANYWHERE').to.throw(); + }); + + it('should be able to validate enum keys', () => { + let e = Enum('NORTH', 'SOUTH', 'WEST', 'EAST'); + expect(e.isValid('SOUTH')).to.be.true; + expect(e.isValid('ANYWHERE')).to.be.false; + expect(e.isValid()).to.be.false; + expect(e.isValid(null)).to.be.false; + }); +}); diff --git a/test/lib/enum.spec.js b/test/lib/enum.spec.js deleted file mode 100644 index 20de191d08..0000000000 --- a/test/lib/enum.spec.js +++ /dev/null @@ -1,26 +0,0 @@ -import { expect } from 'chai'; -import Enum from '../../app/lib/enum'; - -describe('lib', () => { - - describe('enum', () => { - it('should be able to compare values', () => { - const e = Enum('NORTH', 'SOUTH', 'WEST', 'EAST'); - expect(e.NORTH).to.be.equal('NORTH'); - }); - - it('should not be able to modify enum', () => { - let e = Enum('NORTH', 'SOUTH', 'WEST', 'EAST'); - expect(() => e.ANYWHERE = 'ANYWHERE').to.throw(); - }); - - it('should be able to validate enum keys', () => { - let e = Enum('NORTH', 'SOUTH', 'WEST', 'EAST'); - expect(e.isValid('SOUTH')).to.be.true; - expect(e.isValid('ANYWHERE')).to.be.false; - expect(e.isValid()).to.be.false; - expect(e.isValid(null)).to.be.false; - }); - }); - -}); diff --git a/test/reducers.spec.js b/test/reducers.spec.js new file mode 100644 index 0000000000..109c0f5619 --- /dev/null +++ b/test/reducers.spec.js @@ -0,0 +1,41 @@ +import { expect } from 'chai'; +import userReducer from '../app/reducers/user'; +import connectReducer from '../app/reducers/connect'; +import settingsReducer from '../app/reducers/settings'; +import userActions from '../app/actions/user'; +import connectActions from '../app/actions/connect'; +import settingsActions from '../app/actions/settings'; +import { LoginState, ConnectionState, defaultServer } from '../app/constants'; + +describe('reducers', () => { + + it('should handle USER_LOGIN_CHANGE', () => { + const action = userActions.loginChange({ + account: '1111', + status: LoginState.failed, + error: new Error('Something went wrong') + }); + const test = Object.assign({}, action.payload); + expect(userReducer({}, action)).to.deep.equal(test); + }); + + it('should handle CONNECTION_CHANGE', () => { + const action = connectActions.connectionChange({ + status: ConnectionState.connected, + serverAddress: '2.1.1.2', + clientIp: '2.1.1.1' + }); + const test = Object.assign({}, action.payload); + expect(connectReducer({}, action)).to.deep.equal(test); + }); + + it('should handle SETTINGS_CHANGE', () => { + const action = settingsActions.updateSettings({ + autoSecure: true, + preferredServer: defaultServer + }); + const test = Object.assign({}, action.payload); + expect(settingsReducer({}, action)).to.deep.equal(test); + }); + +}); diff --git a/test/reducers/user.spec.js b/test/reducers/user.spec.js deleted file mode 100644 index 9d3107768c..0000000000 --- a/test/reducers/user.spec.js +++ /dev/null @@ -1,25 +0,0 @@ -import { expect } from 'chai'; -import reducer from '../../app/reducers/user'; -import actions from '../../app/actions/user'; -import { LoginState } from '../../app/constants'; - -describe('reducers', () => { - - describe('user', () => { - - it('should handle USER_LOGIN_CHANGE', () => { - const action = { - type: actions.loginChange.toString(), - payload: { - account: '1111', - status: LoginState.failed, - error: new Error('Something went wrong') - } - }; - const test = Object.assign({}, action.payload); - expect(reducer({}, action)).to.deep.equal(test); - }); - - }); - -}); |
