test: fix testing errors

pull/3936/head
mehmet-erim 5 years ago
parent 5368a09afb
commit d403d9424c

@ -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);

@ -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');
});
});

@ -44,13 +44,7 @@ describe('LocalizationService', () => {
describe('#instant', () => {
it('should be return a localization', () => {
store.selectSnapshot.andCallFake(
(selector: (state: any, ...states: any[]) => Observable<string>) => {
return selector({
ConfigState: { getLocalization: (keys, ...interpolateParams) => keys },
});
},
);
store.selectSnapshot.andReturn('AbpTest');
expect(service.instant('AbpTest')).toBe('AbpTest');
});

Loading…
Cancel
Save