mirror of https://github.com/abpframework/abp.git
committed by
GitHub
6 changed files with 75 additions and 2 deletions
@ -0,0 +1,30 @@ |
|||
import { mapEnumToOptions } from '../utils/form-utils'; |
|||
|
|||
enum SomeEnum { |
|||
NotApplicable = 'N/A', |
|||
Foo = 0, |
|||
Bar, |
|||
} |
|||
|
|||
describe('Form Utils', () => { |
|||
describe('#mapEnumToOptions', () => { |
|||
it('should return options from enum', () => { |
|||
const options = mapEnumToOptions(SomeEnum); |
|||
|
|||
expect(options).toEqual([ |
|||
{ |
|||
key: 'NotApplicable', |
|||
value: SomeEnum.NotApplicable, |
|||
}, |
|||
{ |
|||
key: 'Foo', |
|||
value: SomeEnum.Foo, |
|||
}, |
|||
{ |
|||
key: 'Bar', |
|||
value: SomeEnum.Bar, |
|||
}, |
|||
]); |
|||
}); |
|||
}); |
|||
}); |
|||
@ -0,0 +1,17 @@ |
|||
import { isNumber } from '../utils/number-utils'; |
|||
|
|||
describe('Number Utils', () => { |
|||
describe('#isNumber', () => { |
|||
it('should return true if input is a numeric expression', () => { |
|||
expect(isNumber(0)).toBe(true); |
|||
expect(isNumber(0.15)).toBe(true); |
|||
expect(isNumber(2e8)).toBe(true); |
|||
expect(isNumber(Infinity)).toBe(true); |
|||
|
|||
expect(isNumber('0')).toBe(true); |
|||
expect(isNumber('0.15')).toBe(true); |
|||
expect(isNumber('2e8')).toBe(true); |
|||
expect(isNumber('Infinity')).toBe(true); |
|||
}); |
|||
}); |
|||
}); |
|||
@ -0,0 +1,15 @@ |
|||
import { ABP } from '../models/common'; |
|||
import { isNumber } from './number-utils'; |
|||
|
|||
export function mapEnumToOptions<T>(_enum: T): ABP.Option<T>[] { |
|||
const options: ABP.Option<T>[] = []; |
|||
|
|||
for (const member in _enum) |
|||
if (!isNumber(member)) |
|||
options.push({ |
|||
key: member, |
|||
value: _enum[member], |
|||
}); |
|||
|
|||
return options; |
|||
} |
|||
@ -1,6 +1,8 @@ |
|||
export * from './common-utils'; |
|||
export * from './form-utils'; |
|||
export * from './generator-utils'; |
|||
export * from './initial-utils'; |
|||
export * from './lazy-load-utils'; |
|||
export * from './number-utils'; |
|||
export * from './route-utils'; |
|||
export * from './rxjs-utils'; |
|||
|
|||
@ -0,0 +1,4 @@ |
|||
export function isNumber(value: string | number): boolean { |
|||
/* tslint:disable-next-line:triple-equals */ |
|||
return value == Number(value); |
|||
} |
|||
Loading…
Reference in new issue