Skip to content

Commit

Permalink
fix: enable locale override for development mode (#1139)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhhyi authored May 3, 2022
1 parent c4bfe88 commit ae7237b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ import {
getRestEndpoint,
} from './configuration.selectors';

// mock `isDevMode` to return `false`
jest.mock('@angular/core', () => {
const originalModule = jest.requireActual('@angular/core');
return {
...originalModule,
isDevMode: jest.fn(() => false),
};
});

describe('Configuration Selectors', () => {
let store$: StoreWithSnapshots;

Expand Down
11 changes: 7 additions & 4 deletions src/app/core/store/core/configuration/configuration.selectors.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isDevMode } from '@angular/core';
import { createSelector, createSelectorFactory, resultMemoize } from '@ngrx/store';
import { isEqual } from 'lodash-es';

Expand Down Expand Up @@ -59,10 +60,12 @@ export const getCurrentLocale = createSelector(
internalDefaultLocale,
getServerConfigParameter<string>('general.defaultLocale'),
(available, requested, defaultLocale, configuredDefault) =>
available?.find(l => l === requested) ??
available?.find(l => l === configuredDefault) ??
available?.find(l => l === defaultLocale) ??
available?.[0]
isDevMode() && defaultLocale
? defaultLocale
: available?.find(l => l === requested) ??
available?.find(l => l === configuredDefault) ??
available?.find(l => l === defaultLocale) ??
available?.[0]
);

export const getAvailableCurrencies = createSelector(
Expand Down
3 changes: 1 addition & 2 deletions src/environments/environment.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export interface Environment {
// default device type used for initial page responses
defaultDeviceType: DeviceType;

// default locale that is used as fallback if no default locale from the ICM REST call is available
// default locale that is used as fallback if no default locale from the ICM REST call is available (should only be set for local development)
defaultLocale?: string;

// configuration filtering available locales and their active currencies
Expand Down Expand Up @@ -146,7 +146,6 @@ export const ENVIRONMENT_DEFAULTS: Omit<Environment, 'icmChannel'> = {
},
defaultProductListingViewType: 'grid',
defaultDeviceType: 'mobile',
defaultLocale: 'en_US',
multiSiteLocaleMap: {
en_US: '/en',
de_DE: '/de',
Expand Down

0 comments on commit ae7237b

Please sign in to comment.