2017-05-26 06:20:00 +00:00
|
|
|
import reducer, { setSelectedTab } from '../tab';
|
2017-04-24 01:08:48 +00:00
|
|
|
import * as actions from '../actions';
|
2018-04-05 19:13:32 +00:00
|
|
|
import { locationChanged } from 'utils/router';
|
2017-04-24 01:08:48 +00:00
|
|
|
|
2017-06-12 04:39:24 +00:00
|
|
|
describe('tab reducer', () => {
|
2017-05-07 20:19:15 +00:00
|
|
|
it('selects the tab and adds it to history', () => {
|
2017-04-24 01:08:48 +00:00
|
|
|
let state = reducer(undefined, setSelectedTab('srv', '#chan'));
|
|
|
|
|
2018-04-25 03:36:27 +00:00
|
|
|
expect(state).toEqual({
|
2017-04-24 01:08:48 +00:00
|
|
|
selected: { server: 'srv', name: '#chan' },
|
2018-04-05 23:46:22 +00:00
|
|
|
history: [{ server: 'srv', name: '#chan' }]
|
2017-04-24 01:08:48 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
state = reducer(state, setSelectedTab('srv', 'user1'));
|
|
|
|
|
2018-04-25 03:36:27 +00:00
|
|
|
expect(state).toEqual({
|
2017-04-24 01:08:48 +00:00
|
|
|
selected: { server: 'srv', name: 'user1' },
|
|
|
|
history: [
|
|
|
|
{ server: 'srv', name: '#chan' },
|
|
|
|
{ server: 'srv', name: 'user1' }
|
|
|
|
]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes the tab from history on PART', () => {
|
|
|
|
let state = reducer(undefined, setSelectedTab('srv', '#chan'));
|
|
|
|
state = reducer(state, setSelectedTab('srv1', 'bob'));
|
|
|
|
state = reducer(state, setSelectedTab('srv', '#chan'));
|
|
|
|
state = reducer(state, setSelectedTab('srv', '#chan3'));
|
|
|
|
|
|
|
|
state = reducer(state, {
|
|
|
|
type: actions.PART,
|
|
|
|
server: 'srv',
|
|
|
|
channels: ['#chan']
|
|
|
|
});
|
|
|
|
|
2018-04-25 03:36:27 +00:00
|
|
|
expect(state).toEqual({
|
2017-04-24 01:08:48 +00:00
|
|
|
selected: { server: 'srv', name: '#chan3' },
|
|
|
|
history: [
|
|
|
|
{ server: 'srv1', name: 'bob' },
|
|
|
|
{ server: 'srv', name: '#chan3' }
|
|
|
|
]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes the tab from history on CLOSE_PRIVATE_CHAT', () => {
|
|
|
|
let state = reducer(undefined, setSelectedTab('srv', '#chan'));
|
|
|
|
state = reducer(state, setSelectedTab('srv1', 'bob'));
|
|
|
|
state = reducer(state, setSelectedTab('srv', '#chan'));
|
|
|
|
state = reducer(state, setSelectedTab('srv', '#chan3'));
|
|
|
|
|
|
|
|
state = reducer(state, {
|
|
|
|
type: actions.CLOSE_PRIVATE_CHAT,
|
|
|
|
server: 'srv1',
|
|
|
|
nick: 'bob'
|
|
|
|
});
|
|
|
|
|
2018-04-25 03:36:27 +00:00
|
|
|
expect(state).toEqual({
|
2017-04-24 01:08:48 +00:00
|
|
|
selected: { server: 'srv', name: '#chan3' },
|
|
|
|
history: [
|
|
|
|
{ server: 'srv', name: '#chan' },
|
|
|
|
{ server: 'srv', name: '#chan' },
|
2018-04-05 23:46:22 +00:00
|
|
|
{ server: 'srv', name: '#chan3' }
|
2017-04-24 01:08:48 +00:00
|
|
|
]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes all tabs related to server from history on DISCONNECT', () => {
|
|
|
|
let state = reducer(undefined, setSelectedTab('srv', '#chan'));
|
|
|
|
state = reducer(state, setSelectedTab('srv1', 'bob'));
|
|
|
|
state = reducer(state, setSelectedTab('srv', '#chan'));
|
|
|
|
state = reducer(state, setSelectedTab('srv', '#chan3'));
|
|
|
|
|
|
|
|
state = reducer(state, {
|
|
|
|
type: actions.DISCONNECT,
|
2018-04-05 23:46:22 +00:00
|
|
|
server: 'srv'
|
2017-04-24 01:08:48 +00:00
|
|
|
});
|
|
|
|
|
2018-04-25 03:36:27 +00:00
|
|
|
expect(state).toEqual({
|
2017-04-24 01:08:48 +00:00
|
|
|
selected: { server: 'srv', name: '#chan3' },
|
2018-04-05 23:46:22 +00:00
|
|
|
history: [{ server: 'srv1', name: 'bob' }]
|
2017-04-24 01:08:48 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('clears the tab when navigating to a non-tab page', () => {
|
|
|
|
let state = reducer(undefined, setSelectedTab('srv', '#chan'));
|
|
|
|
|
2020-05-08 08:12:21 +00:00
|
|
|
state = reducer(state, locationChanged('settings', {}, {}));
|
2017-04-24 01:08:48 +00:00
|
|
|
|
2018-04-25 03:36:27 +00:00
|
|
|
expect(state).toEqual({
|
|
|
|
selected: {},
|
2018-04-05 23:46:22 +00:00
|
|
|
history: [{ server: 'srv', name: '#chan' }]
|
2017-04-24 01:08:48 +00:00
|
|
|
});
|
|
|
|
});
|
2017-05-07 20:19:15 +00:00
|
|
|
|
|
|
|
it('selects the tab and adds it to history when navigating to a tab', () => {
|
2018-04-05 23:46:22 +00:00
|
|
|
const state = reducer(
|
|
|
|
undefined,
|
2020-05-08 08:12:21 +00:00
|
|
|
locationChanged(
|
|
|
|
'chat',
|
|
|
|
{
|
|
|
|
server: 'srv',
|
|
|
|
name: '#chan'
|
|
|
|
},
|
|
|
|
{}
|
|
|
|
)
|
2017-05-07 20:19:15 +00:00
|
|
|
);
|
|
|
|
|
2018-04-25 03:36:27 +00:00
|
|
|
expect(state).toEqual({
|
2017-05-07 20:19:15 +00:00
|
|
|
selected: { server: 'srv', name: '#chan' },
|
2018-04-05 23:46:22 +00:00
|
|
|
history: [{ server: 'srv', name: '#chan' }]
|
2017-05-07 20:19:15 +00:00
|
|
|
});
|
|
|
|
});
|
2017-04-24 01:08:48 +00:00
|
|
|
});
|