2017-06-12 04:18:32 +00:00
|
|
|
import reducer, { connect, setServerName } from '../servers';
|
2017-04-25 03:13:57 +00:00
|
|
|
import * as actions from '../actions';
|
|
|
|
|
2017-06-12 04:39:24 +00:00
|
|
|
describe('server reducer', () => {
|
2017-04-25 03:13:57 +00:00
|
|
|
it('adds the server on CONNECT', () => {
|
2018-05-16 03:02:48 +00:00
|
|
|
let state = reducer(
|
|
|
|
undefined,
|
|
|
|
connect({ host: '127.0.0.1', nick: 'nick' })
|
|
|
|
);
|
2017-04-25 03:13:57 +00:00
|
|
|
|
2018-04-25 03:36:27 +00:00
|
|
|
expect(state).toEqual({
|
2017-04-25 03:13:57 +00:00
|
|
|
'127.0.0.1': {
|
|
|
|
name: '127.0.0.1',
|
2017-06-21 05:23:07 +00:00
|
|
|
nick: 'nick',
|
2017-07-02 01:31:00 +00:00
|
|
|
editedNick: null,
|
|
|
|
status: {
|
|
|
|
connected: false,
|
|
|
|
error: null
|
|
|
|
}
|
2017-04-25 03:13:57 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-05-16 03:02:48 +00:00
|
|
|
state = reducer(state, connect({ host: '127.0.0.1', nick: 'nick' }));
|
2017-04-25 03:13:57 +00:00
|
|
|
|
2018-04-25 03:36:27 +00:00
|
|
|
expect(state).toEqual({
|
2017-04-25 03:13:57 +00:00
|
|
|
'127.0.0.1': {
|
|
|
|
name: '127.0.0.1',
|
2017-06-21 05:23:07 +00:00
|
|
|
nick: 'nick',
|
2017-07-02 01:31:00 +00:00
|
|
|
editedNick: null,
|
|
|
|
status: {
|
|
|
|
connected: false,
|
|
|
|
error: null
|
|
|
|
}
|
2017-04-25 03:13:57 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-04-05 23:46:22 +00:00
|
|
|
state = reducer(
|
|
|
|
state,
|
2018-05-16 03:02:48 +00:00
|
|
|
connect({ host: '127.0.0.2', nick: 'nick', name: 'srv' })
|
2018-04-05 23:46:22 +00:00
|
|
|
);
|
2017-04-25 03:13:57 +00:00
|
|
|
|
2018-04-25 03:36:27 +00:00
|
|
|
expect(state).toEqual({
|
2017-04-25 03:13:57 +00:00
|
|
|
'127.0.0.1': {
|
|
|
|
name: '127.0.0.1',
|
2017-06-21 05:23:07 +00:00
|
|
|
nick: 'nick',
|
2017-07-02 01:31:00 +00:00
|
|
|
editedNick: null,
|
|
|
|
status: {
|
|
|
|
connected: false,
|
|
|
|
error: null
|
|
|
|
}
|
2017-04-25 03:13:57 +00:00
|
|
|
},
|
|
|
|
'127.0.0.2': {
|
|
|
|
name: 'srv',
|
2017-06-21 05:23:07 +00:00
|
|
|
nick: 'nick',
|
2017-07-02 01:31:00 +00:00
|
|
|
editedNick: null,
|
|
|
|
status: {
|
|
|
|
connected: false,
|
|
|
|
error: null
|
|
|
|
}
|
2017-04-25 03:13:57 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes the server on DISCONNECT', () => {
|
2018-04-25 03:36:27 +00:00
|
|
|
let state = {
|
2017-04-25 03:13:57 +00:00
|
|
|
srv: {},
|
|
|
|
srv2: {}
|
2018-04-25 03:36:27 +00:00
|
|
|
};
|
2017-04-25 03:13:57 +00:00
|
|
|
|
|
|
|
state = reducer(state, {
|
|
|
|
type: actions.DISCONNECT,
|
|
|
|
server: 'srv2'
|
|
|
|
});
|
|
|
|
|
2018-04-25 03:36:27 +00:00
|
|
|
expect(state).toEqual({
|
2017-04-25 03:13:57 +00:00
|
|
|
srv: {}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-06-12 04:18:32 +00:00
|
|
|
it('handles SET_SERVER_NAME', () => {
|
2018-04-25 03:36:27 +00:00
|
|
|
let state = {
|
2017-06-12 04:18:32 +00:00
|
|
|
srv: {
|
|
|
|
name: 'cake'
|
|
|
|
}
|
2018-04-25 03:36:27 +00:00
|
|
|
};
|
2017-06-12 04:18:32 +00:00
|
|
|
|
|
|
|
state = reducer(state, setServerName('pie', 'srv'));
|
|
|
|
|
2018-04-25 03:36:27 +00:00
|
|
|
expect(state).toEqual({
|
2017-06-12 04:18:32 +00:00
|
|
|
srv: {
|
|
|
|
name: 'pie'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-06-21 05:23:07 +00:00
|
|
|
it('sets editedNick when editing the nick', () => {
|
2018-05-16 03:02:48 +00:00
|
|
|
let state = reducer(
|
|
|
|
undefined,
|
|
|
|
connect({ host: '127.0.0.1', nick: 'nick' })
|
|
|
|
);
|
2017-06-21 05:23:07 +00:00
|
|
|
state = reducer(state, {
|
|
|
|
type: actions.SET_NICK,
|
|
|
|
server: '127.0.0.1',
|
|
|
|
nick: 'nick2',
|
|
|
|
editing: true
|
|
|
|
});
|
|
|
|
|
2018-04-25 03:36:27 +00:00
|
|
|
expect(state).toMatchObject({
|
2017-06-21 05:23:07 +00:00
|
|
|
'127.0.0.1': {
|
|
|
|
name: '127.0.0.1',
|
|
|
|
nick: 'nick',
|
|
|
|
editedNick: 'nick2'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('clears editedNick when receiving an empty nick after editing finishes', () => {
|
2018-05-16 03:02:48 +00:00
|
|
|
let state = reducer(
|
|
|
|
undefined,
|
|
|
|
connect({ host: '127.0.0.1', nick: 'nick' })
|
|
|
|
);
|
2017-06-21 05:23:07 +00:00
|
|
|
state = reducer(state, {
|
|
|
|
type: actions.SET_NICK,
|
|
|
|
server: '127.0.0.1',
|
|
|
|
nick: 'nick2',
|
|
|
|
editing: true
|
|
|
|
});
|
|
|
|
state = reducer(state, {
|
|
|
|
type: actions.SET_NICK,
|
|
|
|
server: '127.0.0.1',
|
|
|
|
nick: ''
|
|
|
|
});
|
|
|
|
|
2018-04-25 03:36:27 +00:00
|
|
|
expect(state).toMatchObject({
|
2017-06-21 05:23:07 +00:00
|
|
|
'127.0.0.1': {
|
|
|
|
name: '127.0.0.1',
|
|
|
|
nick: 'nick',
|
|
|
|
editedNick: null
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-04-25 03:13:57 +00:00
|
|
|
it('updates the nick on SOCKET_NICK', () => {
|
2018-05-16 03:02:48 +00:00
|
|
|
let state = reducer(
|
|
|
|
undefined,
|
|
|
|
connect({ host: '127.0.0.1', nick: 'nick' })
|
|
|
|
);
|
2017-04-25 03:13:57 +00:00
|
|
|
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',
|
2017-06-21 05:23:07 +00:00
|
|
|
oldNick: 'nick',
|
|
|
|
newNick: 'nick2'
|
|
|
|
});
|
|
|
|
|
2018-04-25 03:36:27 +00:00
|
|
|
expect(state).toMatchObject({
|
2017-06-21 05:23:07 +00:00
|
|
|
'127.0.0.1': {
|
|
|
|
name: '127.0.0.1',
|
|
|
|
nick: 'nick2',
|
|
|
|
editedNick: null
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('clears editedNick on SOCKET_NICK_FAIL', () => {
|
2018-05-16 03:02:48 +00:00
|
|
|
let state = reducer(
|
|
|
|
undefined,
|
|
|
|
connect({ host: '127.0.0.1', nick: 'nick' })
|
|
|
|
);
|
2017-06-21 05:23:07 +00:00
|
|
|
state = reducer(state, {
|
|
|
|
type: actions.SET_NICK,
|
|
|
|
server: '127.0.0.1',
|
|
|
|
nick: 'nick2',
|
|
|
|
editing: true
|
|
|
|
});
|
|
|
|
state = reducer(state, {
|
|
|
|
type: actions.socket.NICK_FAIL,
|
|
|
|
server: '127.0.0.1'
|
2017-04-25 03:13:57 +00:00
|
|
|
});
|
|
|
|
|
2018-04-25 03:36:27 +00:00
|
|
|
expect(state).toMatchObject({
|
2017-04-25 03:13:57 +00:00
|
|
|
'127.0.0.1': {
|
|
|
|
name: '127.0.0.1',
|
2017-06-21 05:23:07 +00:00
|
|
|
nick: 'nick',
|
|
|
|
editedNick: null
|
2017-04-25 03:13:57 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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',
|
2017-07-02 01:31:00 +00:00
|
|
|
status: {
|
|
|
|
connected: true
|
|
|
|
}
|
2017-04-25 03:13:57 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
host: '127.0.0.2',
|
|
|
|
name: 'stuffz',
|
|
|
|
nick: 'nick2',
|
2017-07-02 01:31:00 +00:00
|
|
|
status: {
|
|
|
|
connected: false
|
|
|
|
}
|
2018-04-05 23:46:22 +00:00
|
|
|
}
|
2017-04-25 03:13:57 +00:00
|
|
|
]
|
|
|
|
});
|
|
|
|
|
2018-04-25 03:36:27 +00:00
|
|
|
expect(state).toEqual({
|
2017-04-25 03:13:57 +00:00
|
|
|
'127.0.0.1': {
|
|
|
|
name: 'stuff',
|
|
|
|
nick: 'nick',
|
2018-05-16 03:02:48 +00:00
|
|
|
editedNick: null,
|
2017-07-02 01:31:00 +00:00
|
|
|
status: {
|
2018-04-25 03:36:27 +00:00
|
|
|
connected: true
|
2017-07-02 01:31:00 +00:00
|
|
|
}
|
2017-04-25 03:13:57 +00:00
|
|
|
},
|
|
|
|
'127.0.0.2': {
|
|
|
|
name: 'stuffz',
|
|
|
|
nick: 'nick2',
|
2018-05-16 03:02:48 +00:00
|
|
|
editedNick: null,
|
2017-07-02 01:31:00 +00:00
|
|
|
status: {
|
2018-04-25 03:36:27 +00:00
|
|
|
connected: false
|
2017-07-02 01:31:00 +00:00
|
|
|
}
|
2017-04-25 03:13:57 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates connection status on SOCKET_CONNECTION_UPDATE', () => {
|
2018-05-16 03:02:48 +00:00
|
|
|
let state = reducer(
|
|
|
|
undefined,
|
|
|
|
connect({ host: '127.0.0.1', nick: 'nick' })
|
|
|
|
);
|
2017-04-25 03:13:57 +00:00
|
|
|
state = reducer(state, {
|
2017-05-26 06:20:00 +00:00
|
|
|
type: actions.socket.CONNECTION_UPDATE,
|
2017-07-02 01:31:00 +00:00
|
|
|
server: '127.0.0.1',
|
|
|
|
connected: true
|
|
|
|
});
|
|
|
|
|
2018-04-25 03:36:27 +00:00
|
|
|
expect(state).toEqual({
|
2017-07-02 01:31:00 +00:00
|
|
|
'127.0.0.1': {
|
|
|
|
name: '127.0.0.1',
|
|
|
|
nick: 'nick',
|
|
|
|
editedNick: null,
|
|
|
|
status: {
|
2018-04-25 03:36:27 +00:00
|
|
|
connected: true
|
2017-07-02 01:31:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
state = reducer(state, {
|
|
|
|
type: actions.socket.CONNECTION_UPDATE,
|
|
|
|
server: '127.0.0.1',
|
|
|
|
connected: false,
|
|
|
|
error: 'Bad stuff happened'
|
2017-04-25 03:13:57 +00:00
|
|
|
});
|
|
|
|
|
2018-04-25 03:36:27 +00:00
|
|
|
expect(state).toEqual({
|
2017-04-25 03:13:57 +00:00
|
|
|
'127.0.0.1': {
|
|
|
|
name: '127.0.0.1',
|
|
|
|
nick: 'nick',
|
2017-06-21 05:23:07 +00:00
|
|
|
editedNick: null,
|
2017-07-02 01:31:00 +00:00
|
|
|
status: {
|
|
|
|
connected: false,
|
|
|
|
error: 'Bad stuff happened'
|
|
|
|
}
|
2017-04-25 03:13:57 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|