|
|
|
@ -1,8 +1,11 @@ |
|
|
|
import { ConfigStateService, LocalizationService } from '@abp/ng.core'; |
|
|
|
import { ConfigStateService, ExtensionEnumFieldDto, LocalizationService } from '@abp/ng.core'; |
|
|
|
import { BehaviorSubject, of } from 'rxjs'; |
|
|
|
import { take } from 'rxjs/operators'; |
|
|
|
import { PropData } from '../lib/models/props'; |
|
|
|
import { createEnum, createEnumOptions, createEnumValueResolver } from '../lib/utils/enum.util'; |
|
|
|
import { createSpyObject } from '@ngneat/spectator' |
|
|
|
import { AbpApplicationLocalizationService } from '@abp/ng.core'; |
|
|
|
|
|
|
|
|
|
|
|
const mockSessionState = { |
|
|
|
languageChange$: new BehaviorSubject('tr'), |
|
|
|
@ -11,10 +14,10 @@ const mockSessionState = { |
|
|
|
onLanguageChange$: () => new BehaviorSubject('tr'), |
|
|
|
} as any; |
|
|
|
|
|
|
|
const fields = [ |
|
|
|
{ name: 'foo', value: 1 }, |
|
|
|
{ name: 'bar', value: 2 }, |
|
|
|
{ name: 'baz', value: 3 }, |
|
|
|
const fields: ExtensionEnumFieldDto[] = [ |
|
|
|
{ name: 'foo', value: {number: 1} }, |
|
|
|
{ name: 'bar', value: {number: 2} }, |
|
|
|
{ name: 'baz', value: {number: 3} }, |
|
|
|
]; |
|
|
|
|
|
|
|
class MockPropData<R = any> extends PropData<R> { |
|
|
|
@ -42,17 +45,13 @@ describe('Enum Utils', () => { |
|
|
|
describe('#createEnum', () => { |
|
|
|
const enumFromFields = createEnum(fields); |
|
|
|
|
|
|
|
test.each` |
|
|
|
key | expected |
|
|
|
${'foo'} | ${1} |
|
|
|
${'bar'} | ${2} |
|
|
|
${'baz'} | ${3} |
|
|
|
${1} | ${'foo'} |
|
|
|
${2} | ${'bar'} |
|
|
|
${3} | ${'baz'} |
|
|
|
`('should create an enum that returns $expected when $key is accessed', ({ key, expected }) => {
|
|
|
|
expect(enumFromFields[key]).toBe(expected); |
|
|
|
}); |
|
|
|
test.each([ |
|
|
|
{name:'foo', value: 'number', expected: 1}, |
|
|
|
{name:'bar', value: 'number', expected: 2}, |
|
|
|
{name:'baz', value: 'number', expected: 3} |
|
|
|
])('',({name, value, expected})=>{ |
|
|
|
expect(enumFromFields[name][value]).toBe(expected); |
|
|
|
}) |
|
|
|
}); |
|
|
|
|
|
|
|
describe('#createEnumValueResolver', () => { |
|
|
|
@ -75,7 +74,7 @@ describe('Enum Utils', () => { |
|
|
|
'EnumProp', |
|
|
|
); |
|
|
|
const propData = new MockPropData({ |
|
|
|
extraProperties: { EnumProp: value }, |
|
|
|
extraProperties: { EnumProp: value }, |
|
|
|
}); |
|
|
|
propData.getInjected = () => service as any; |
|
|
|
|
|
|
|
@ -111,8 +110,9 @@ describe('Enum Utils', () => { |
|
|
|
|
|
|
|
function createMockLocalizationService() { |
|
|
|
const fakeAppConfigService = { get: () => of({ localization: mockL10n }) } as any; |
|
|
|
const configState = new ConfigStateService(fakeAppConfigService); |
|
|
|
let abpApplicationLocalizationService = createSpyObject<AbpApplicationLocalizationService>(AbpApplicationLocalizationService) |
|
|
|
const configState = new ConfigStateService(fakeAppConfigService, abpApplicationLocalizationService, true); |
|
|
|
configState.refreshAppState(); |
|
|
|
|
|
|
|
return new LocalizationService(mockSessionState, null, null, configState); |
|
|
|
} |
|
|
|
} |