mirror of https://github.com/abpframework/abp.git
2 changed files with 45 additions and 0 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,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; |
||||
|
} |
||||
Loading…
Reference in new issue