* Remove mattermost-redux * Move mm-redux files into app/redux * Add @redux path to tsconfig.json * Fix imports * Install missing dependencies * Fix tsc errors * Fix i18n_utils test * Fix more imports * Remove redux websocket * Fix tests * Rename @redux * Apply changes from mattermost-redux PR 1103 * Remove mattermost-redux mention in template * Add missing imports * Rename app/redux/ to app/mm-redux/ * Remove test file * Fix fetching Sidebar GM profiles Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
102 lines
3 KiB
JavaScript
102 lines
3 KiB
JavaScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {GeneralTypes} from '@mm-redux/action_types';
|
|
|
|
import reducer from './websocket';
|
|
|
|
describe('websocket', () => {
|
|
describe('lastConnectAt', () => {
|
|
test('should update lastConnectAt when first connecting', () => {
|
|
let state = reducer(undefined, {});
|
|
|
|
state = reducer(state, {
|
|
type: GeneralTypes.WEBSOCKET_SUCCESS,
|
|
timestamp: 1000,
|
|
});
|
|
|
|
expect(state.connected).toBe(true);
|
|
expect(state.lastConnectAt).toBe(1000);
|
|
});
|
|
|
|
test('should not update lastConnectAt when already connected', () => {
|
|
let state = reducer(undefined, {});
|
|
|
|
state = reducer(state, {
|
|
type: GeneralTypes.WEBSOCKET_SUCCESS,
|
|
timestamp: 1000,
|
|
});
|
|
|
|
state = reducer(state, {
|
|
type: GeneralTypes.WEBSOCKET_SUCCESS,
|
|
timestamp: 2000,
|
|
});
|
|
|
|
expect(state.connected).toBe(true);
|
|
expect(state.lastConnectAt).toBe(1000);
|
|
});
|
|
|
|
test('should update when reconnecting', () => {
|
|
let state = reducer(undefined, {});
|
|
|
|
state = reducer(state, {
|
|
type: GeneralTypes.WEBSOCKET_SUCCESS,
|
|
timestamp: 1000,
|
|
});
|
|
|
|
state = reducer(state, {
|
|
type: GeneralTypes.WEBSOCKET_FAILURE,
|
|
timestamp: 2000,
|
|
});
|
|
|
|
state = reducer(state, {
|
|
type: GeneralTypes.WEBSOCKET_SUCCESS,
|
|
timestamp: 3000,
|
|
});
|
|
|
|
expect(state.connected).toBe(true);
|
|
expect(state.lastConnectAt).toBe(3000);
|
|
});
|
|
});
|
|
|
|
describe('lastDisconnectAt', () => {
|
|
test('should update lastDisconnectAt when disconnected', () => {
|
|
let state = reducer(undefined, {});
|
|
|
|
state = reducer(state, {
|
|
type: GeneralTypes.WEBSOCKET_SUCCESS,
|
|
timestamp: 1000,
|
|
});
|
|
|
|
state = reducer(state, {
|
|
type: GeneralTypes.WEBSOCKET_FAILURE,
|
|
timestamp: 2000,
|
|
});
|
|
|
|
expect(state.connected).toBe(false);
|
|
expect(state.lastDisconnectAt).toBe(2000);
|
|
});
|
|
|
|
test('should not update lastDisconnectAt when failing to reconnect', () => {
|
|
let state = reducer(undefined, {});
|
|
|
|
state = reducer(state, {
|
|
type: GeneralTypes.WEBSOCKET_SUCCESS,
|
|
timestamp: 1000,
|
|
});
|
|
|
|
state = reducer(state, {
|
|
type: GeneralTypes.WEBSOCKET_FAILURE,
|
|
timestamp: 2000,
|
|
});
|
|
|
|
state = reducer(state, {
|
|
type: GeneralTypes.WEBSOCKET_FAILURE,
|
|
timestamp: 3000,
|
|
});
|
|
|
|
expect(state.connected).toBe(false);
|
|
expect(state.lastDisconnectAt).toBe(2000);
|
|
});
|
|
});
|
|
});
|