Automated cherry pick of #3310 (#3318)

* Reset moment local on logout

* Update app/selectors/i18n.js

Co-Authored-By: Elias Nahum <nahumhbl@gmail.com>
This commit is contained in:
Mattermost Build 2019-09-25 10:06:06 +02:00 committed by Saturnino Abril
parent 6b4b4ce75f
commit bd4a119c05
3 changed files with 8 additions and 10 deletions

View file

@ -108,12 +108,8 @@ function loadTranslation(locale) {
}
}
let momentLocale = DEFAULT_LOCALE;
function setMomentLocale(locale) {
if (momentLocale !== locale) {
momentLocale = moment.locale(locale);
}
export function resetMomentLocale() {
moment.locale(DEFAULT_LOCALE);
}
export function getTranslations(locale) {
@ -121,8 +117,6 @@ export function getTranslations(locale) {
loadTranslation(locale);
}
setMomentLocale(locale.toLowerCase());
return TRANSLATIONS[locale] || TRANSLATIONS[DEFAULT_LOCALE];
}

View file

@ -18,7 +18,7 @@ import {selectDefaultChannel} from 'app/actions/views/channel';
import {showOverlay} from 'app/actions/navigation';
import {loadConfigAndLicense, setDeepLinkURL, startDataCleanup} from 'app/actions/views/root';
import {NavigationTypes, ViewTypes} from 'app/constants';
import {getTranslations} from 'app/i18n';
import {getTranslations, resetMomentLocale} from 'app/i18n';
import mattermostManaged from 'app/mattermost_managed';
import PushNotifications from 'app/push_notifications';
import {getCurrentLocale} from 'app/selectors/i18n';
@ -145,6 +145,7 @@ class GlobalEventHandler {
this.store.dispatch(setServerVersion(''));
deleteFileCache();
removeAppCredentials();
resetMomentLocale();
PushNotifications.clearNotifications();

View file

@ -6,6 +6,7 @@ import thunk from 'redux-thunk';
import intitialState from 'app/initial_state';
import PushNotification from 'app/push_notifications';
import * as I18n from 'app/i18n';
import GlobalEventHandler from './global_event_handler';
@ -35,11 +36,13 @@ GlobalEventHandler.store = store;
// TODO: Add Android test as part of https://mattermost.atlassian.net/browse/MM-17110
describe('GlobalEventHandler', () => {
it('should clear notifications on logout', async () => {
it('should clear notifications and reset moment locale on logout', async () => {
const clearNotifications = jest.spyOn(PushNotification, 'clearNotifications');
const resetMomentLocale = jest.spyOn(I18n, 'resetMomentLocale');
await GlobalEventHandler.onLogout();
expect(clearNotifications).toHaveBeenCalled();
expect(resetMomentLocale).toHaveBeenCalledWith();
});
it('should call onAppStateChange after configuration', () => {