|
|
|
@ -2,37 +2,37 @@ import { extractNumberFromString } from '@ghostfolio/common/helper';
|
|
|
|
|
|
|
|
|
|
describe('Helper', () => {
|
|
|
|
|
describe('Extract number from string', () => {
|
|
|
|
|
it('Get decimal number', async () => {
|
|
|
|
|
it('Get decimal number', () => {
|
|
|
|
|
expect(extractNumberFromString({ value: '999.99' })).toEqual(999.99);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('Get decimal number (with spaces)', async () => {
|
|
|
|
|
it('Get decimal number (with spaces)', () => {
|
|
|
|
|
expect(extractNumberFromString({ value: ' 999.99 ' })).toEqual(999.99);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('Get decimal number (with currency)', async () => {
|
|
|
|
|
it('Get decimal number (with currency)', () => {
|
|
|
|
|
expect(extractNumberFromString({ value: '999.99 CHF' })).toEqual(999.99);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('Get decimal number (comma notation)', async () => {
|
|
|
|
|
it('Get decimal number (comma notation)', () => {
|
|
|
|
|
expect(
|
|
|
|
|
extractNumberFromString({ locale: 'de-DE', value: '999,99' })
|
|
|
|
|
).toEqual(999.99);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('Get decimal number with group (dot notation)', async () => {
|
|
|
|
|
it('Get decimal number with group (dot notation)', () => {
|
|
|
|
|
expect(
|
|
|
|
|
extractNumberFromString({ locale: 'de-CH', value: '99’999.99' })
|
|
|
|
|
).toEqual(99999.99);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('Get decimal number with group (comma notation)', async () => {
|
|
|
|
|
it('Get decimal number with group (comma notation)', () => {
|
|
|
|
|
expect(
|
|
|
|
|
extractNumberFromString({ locale: 'de-DE', value: '99.999,99' })
|
|
|
|
|
).toEqual(99999.99);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('Not a number', async () => {
|
|
|
|
|
it('Not a number', () => {
|
|
|
|
|
expect(extractNumberFromString({ value: 'X' })).toEqual(NaN);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|