mattermost-mobile/app/store/utils.test.js
Miguel Alatzar 7afa9aed01
[MM-23698] [MM-19559] Remove redux-offline and updated redux-persist (#4120)
* Remove redux-offline and configure redux-persist

* Fix typo

* Fix configure store

* Upgrade to redux-persist 6.0.0

* Add migration from redux-persist v4 to v6

* Replace AsyncStorage with MMKVStorage to boost storage speed

* Mock RNFastStorage

* Fix reactions test

* Fix clearing the store on logout

* Remove the need for LOGOUT_SUCCESS

* No need to pass persistConfig to middlewares()

* Remove unused imports

* Export connection

Accidentally removed this export.

* Add batch action name

Co-Authored-By: Elias Nahum <nahumhbl@gmail.com>

* Add batch action name

Co-Authored-By: Elias Nahum <nahumhbl@gmail.com>

* Add batch action name

Co-Authored-By: Elias Nahum <nahumhbl@gmail.com>

* Add batch action name

Co-Authored-By: Elias Nahum <nahumhbl@gmail.com>

* Fix delete post

* Fix leave channel

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
2020-04-08 13:44:54 -07:00

83 lines
3 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import initialState from 'app/initial_state';
import {getStateForReset} from 'app/store/utils';
/*
const {currentUserId} = currentState.entities.users;
const currentUserProfile = currentState.entities.users.profiles[currentUserId];
const {currentTeamId} = currentState.entities.teams;
const myPreferences = {...currentState.entities.preferences.myPreferences};
Object.keys(myPreferences).forEach((key) => {
if (!key.startsWith('theme--')) {
Reflect.deleteProperty(myPreferences, key);
}
});
*/
describe('getStateForReset', () => {
const currentUserId = 'current-user-id';
const otherUserId = 'other-user-id';
const currentTeamId = 'current-team-id';
const currentState = {
entities: {
users: {
currentUserId,
profiles: {
[currentUserId]: {},
[otherUserId]: {},
},
},
teams: {
currentTeamId,
},
preferences: {
myPreferences: {
'channel_open_time--1': {},
'channel_open_time--2': {},
'direct_channel_show--1': {},
'direct_channel_show--2': {},
'display_settings--1': {},
'display_settings--2': {},
'favorite_channel--1': {},
'favorite_channel--2': {},
'flagged_post--1': {},
'flagged_post--2': {},
'group_channel_show--1': {},
'group_channel_show--2': {},
'tutorial_step--1': {},
'tutorial_step--2': {},
'theme--1': {},
'theme--2': {},
},
},
},
views: {
selectServer: {
serverUrl: 'localhost:8065',
},
},
};
it('should keep the current user\'s ID and profile', () => {
const resetState = getStateForReset(initialState, currentState);
const {users} = resetState.entities;
expect(users.currentUserId).toEqual(currentUserId);
expect(Object.keys(users.profiles).length).toEqual(1);
expect(users.profiles[currentUserId]).toBeDefined();
});
it('should keep the current team ID', () => {
const resetState = getStateForReset(initialState, currentState);
const {teams} = resetState.entities;
expect(teams.currentTeamId).toEqual(currentTeamId);
});
it('should keep theme preferences', () => {
const resetState = getStateForReset(initialState, currentState);
const {myPreferences} = resetState.entities.preferences;
const preferenceKeys = Object.keys(myPreferences);
const themeKeys = preferenceKeys.filter((key) => key.startsWith('theme--'));
expect(themeKeys.length).toEqual(2);
});
});