From d403d9424c92072ecf599eef9287e03e0e0d9c45 Mon Sep 17 00:00:00 2001 From: mehmet-erim Date: Wed, 13 May 2020 14:11:04 +0300 Subject: [PATCH] test: fix testing errors --- .../packages/core/src/lib/states/config.state.ts | 10 +++++----- .../packages/core/src/lib/tests/config.state.spec.ts | 11 ++++------- .../core/src/lib/tests/localization.service.spec.ts | 8 +------- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/npm/ng-packs/packages/core/src/lib/states/config.state.ts b/npm/ng-packs/packages/core/src/lib/states/config.state.ts index 25f2a69fbe..3527e5445d 100644 --- a/npm/ng-packs/packages/core/src/lib/states/config.state.ts +++ b/npm/ng-packs/packages/core/src/lib/states/config.state.ts @@ -162,7 +162,7 @@ export class ConfigState { if (keys.length < 2) { warn('The localization source separator (::) not found.'); - return key as string; + return defaultValue || (key as string); } if (!state.localization) return defaultValue || keys[1]; @@ -173,7 +173,7 @@ export class ConfigState { const sourceKey = keys[1]; if (sourceName === '_') { - return sourceKey; + return defaultValue || sourceKey; } if (!sourceName) { @@ -181,18 +181,18 @@ export class ConfigState { 'Localization source name is not specified and the defaultResourceName was not defined!', ); - return sourceKey; + return defaultValue || sourceKey; } const source = state.localization.values[sourceName]; if (!source) { warn('Could not find localization source: ' + sourceName); - return sourceKey; + return defaultValue || sourceKey; } let localization = source[sourceKey]; if (typeof localization === 'undefined') { - return sourceKey; + return defaultValue || sourceKey; } interpolateParams = interpolateParams.filter(params => params != null); diff --git a/npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts index aa3740218c..e823328f73 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts @@ -272,7 +272,7 @@ describe('ConfigState', () => { ); expect(ConfigState.getLocalization('AbpIdentity::NoIdentity')(CONFIG_STATE_DATA)).toBe( - 'AbpIdentity::NoIdentity', + 'NoIdentity', ); expect( @@ -287,18 +287,15 @@ describe('ConfigState', () => { )(CONFIG_STATE_DATA), ).toBe('first and second do not match.'); - try { + expect( ConfigState.getLocalization('::Test')({ ...CONFIG_STATE_DATA, environment: { ...CONFIG_STATE_DATA.environment, localization: {} as any, }, - }); - expect(false).toBeTruthy(); // fail - } catch (error) { - expect((error as Error).message).toContain('Please check your environment'); - } + }), + ).toBe('Test'); }); }); diff --git a/npm/ng-packs/packages/core/src/lib/tests/localization.service.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/localization.service.spec.ts index 5600e3aa39..8c5b859f9f 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/localization.service.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/localization.service.spec.ts @@ -44,13 +44,7 @@ describe('LocalizationService', () => { describe('#instant', () => { it('should be return a localization', () => { - store.selectSnapshot.andCallFake( - (selector: (state: any, ...states: any[]) => Observable) => { - return selector({ - ConfigState: { getLocalization: (keys, ...interpolateParams) => keys }, - }); - }, - ); + store.selectSnapshot.andReturn('AbpTest'); expect(service.instant('AbpTest')).toBe('AbpTest'); });