2017-04-25 03:13:57 +00:00
|
|
|
import Immutable from 'immutable';
|
2017-05-26 06:20:00 +00:00
|
|
|
import reducer, { connect } from '../servers';
|
2017-04-25 03:13:57 +00:00
|
|
|
import * as actions from '../actions';
|
|
|
|
|
|
|
|
describe('reducers/servers', () => {
|
|
|
|
it('adds the server on CONNECT', () => {
|
|
|
|
let state = reducer(undefined, connect('127.0.0.1:1337', 'nick', {}));
|
|
|
|
|
|
|
|
expect(state.toJS()).toEqual({
|
|
|
|
'127.0.0.1': {
|
|
|
|
connected: false,
|
|
|
|
name: '127.0.0.1',
|
|
|
|
nick: 'nick'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
state = reducer(state, connect('127.0.0.1:1337', 'nick', {}));
|
|
|
|
|
|
|
|
expect(state.toJS()).toEqual({
|
|
|
|
'127.0.0.1': {
|
|
|
|
connected: false,
|
|
|
|
name: '127.0.0.1',
|
|
|
|
nick: 'nick'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
state = reducer(state, connect('127.0.0.2:1337', 'nick', {
|
|
|
|
name: 'srv'
|
|
|
|
}));
|
|
|
|
|
|
|
|
expect(state.toJS()).toEqual({
|
|
|
|
'127.0.0.1': {
|
|
|
|
connected: false,
|
|
|
|
name: '127.0.0.1',
|
|
|
|
nick: 'nick'
|
|
|
|
},
|
|
|
|
'127.0.0.2': {
|
|
|
|
connected: false,
|
|
|
|
name: 'srv',
|
|
|
|
nick: 'nick'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes the server on DISCONNECT', () => {
|
|
|
|
let state = Immutable.fromJS({
|
|
|
|
srv: {},
|
|
|
|
srv2: {}
|
|
|
|
});
|
|
|
|
|
|
|
|
state = reducer(state, {
|
|
|
|
type: actions.DISCONNECT,
|
|
|
|
server: 'srv2'
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(state.toJS()).toEqual({
|
|
|
|
srv: {}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates the nick on SOCKET_NICK', () => {
|
|
|
|
let state = reducer(undefined, connect('127.0.0.1:1337', 'nick', {}));
|
|
|
|
state = reducer(state, {
|
2017-05-26 06:20:00 +00:00
|
|
|
type: actions.socket.NICK,
|
2017-04-25 03:13:57 +00:00
|
|
|
server: '127.0.0.1',
|
|
|
|
old: 'nick',
|
|
|
|
new: 'nick2'
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(state.toJS()).toEqual({
|
|
|
|
'127.0.0.1': {
|
|
|
|
connected: false,
|
|
|
|
name: '127.0.0.1',
|
|
|
|
nick: 'nick2'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('adds the servers on SOCKET_SERVERS', () => {
|
|
|
|
let state = reducer(undefined, {
|
2017-05-26 06:20:00 +00:00
|
|
|
type: actions.socket.SERVERS,
|
2017-04-25 03:13:57 +00:00
|
|
|
data: [
|
|
|
|
{
|
|
|
|
host: '127.0.0.1',
|
|
|
|
name: 'stuff',
|
|
|
|
nick: 'nick',
|
|
|
|
connected: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
host: '127.0.0.2',
|
|
|
|
name: 'stuffz',
|
|
|
|
nick: 'nick2',
|
|
|
|
connected: false
|
|
|
|
},
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(state.toJS()).toEqual({
|
|
|
|
'127.0.0.1': {
|
|
|
|
name: 'stuff',
|
|
|
|
nick: 'nick',
|
|
|
|
connected: true
|
|
|
|
},
|
|
|
|
'127.0.0.2': {
|
|
|
|
name: 'stuffz',
|
|
|
|
nick: 'nick2',
|
|
|
|
connected: false
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates connection status on SOCKET_CONNECTION_UPDATE', () => {
|
|
|
|
let state = reducer(undefined, connect('127.0.0.1:1337', 'nick', {}));
|
|
|
|
state = reducer(state, {
|
2017-05-26 06:20:00 +00:00
|
|
|
type: actions.socket.CONNECTION_UPDATE,
|
2017-04-25 03:13:57 +00:00
|
|
|
'127.0.0.1': true
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(state.toJS()).toEqual({
|
|
|
|
'127.0.0.1': {
|
|
|
|
name: '127.0.0.1',
|
|
|
|
nick: 'nick',
|
|
|
|
connected: true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|