mirror of https://github.com/ghostfolio/ghostfolio
				
				
			
			
			
				Browse Source
			
			
			
			
				
		* Set up test * Add support for international formatted numbers * Expose locale in scraper configuration * Update changelogpull/2865/head
							committed by
							
								
								GitHub
							
						
					
				
				 9 changed files with 90 additions and 13 deletions
			
			
		@ -0,0 +1,39 @@ | 
				
			|||||
 | 
					import { extractNumberFromString } from '@ghostfolio/common/helper'; | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					describe('Helper', () => { | 
				
			||||
 | 
					  describe('Extract number from string', () => { | 
				
			||||
 | 
					    it('Get decimal number', async () => { | 
				
			||||
 | 
					      expect(extractNumberFromString({ value: '999.99' })).toEqual(999.99); | 
				
			||||
 | 
					    }); | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					    it('Get decimal number (with spaces)', async () => { | 
				
			||||
 | 
					      expect(extractNumberFromString({ value: ' 999.99 ' })).toEqual(999.99); | 
				
			||||
 | 
					    }); | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					    it('Get decimal number (with currency)', async () => { | 
				
			||||
 | 
					      expect(extractNumberFromString({ value: '999.99 CHF' })).toEqual(999.99); | 
				
			||||
 | 
					    }); | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					    it('Get decimal number (comma notation)', async () => { | 
				
			||||
 | 
					      expect( | 
				
			||||
 | 
					        extractNumberFromString({ locale: 'de-DE', value: '999,99' }) | 
				
			||||
 | 
					      ).toEqual(999.99); | 
				
			||||
 | 
					    }); | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					    it('Get decimal number with group (dot notation)', async () => { | 
				
			||||
 | 
					      expect( | 
				
			||||
 | 
					        extractNumberFromString({ locale: 'de-CH', value: '99’999.99' }) | 
				
			||||
 | 
					      ).toEqual(99999.99); | 
				
			||||
 | 
					    }); | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					    it('Get decimal number with group (comma notation)', async () => { | 
				
			||||
 | 
					      expect( | 
				
			||||
 | 
					        extractNumberFromString({ locale: 'de-DE', value: '99.999,99' }) | 
				
			||||
 | 
					      ).toEqual(99999.99); | 
				
			||||
 | 
					    }); | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					    it('Not a number', async () => { | 
				
			||||
 | 
					      expect(extractNumberFromString({ value: 'X' })).toEqual(NaN); | 
				
			||||
 | 
					    }); | 
				
			||||
 | 
					  }); | 
				
			||||
 | 
					}); | 
				
			||||
@ -1,6 +1,7 @@ | 
				
			|||||
export interface ScraperConfiguration { | 
					export interface ScraperConfiguration { | 
				
			||||
  defaultMarketPrice?: number; | 
					  defaultMarketPrice?: number; | 
				
			||||
  headers?: { [key: string]: string }; | 
					  headers?: { [key: string]: string }; | 
				
			||||
 | 
					  locale?: string; | 
				
			||||
  selector: string; | 
					  selector: string; | 
				
			||||
  url: string; | 
					  url: string; | 
				
			||||
} | 
					} | 
				
			||||
 | 
				
			|||||
					Loading…
					
					
				
		Reference in new issue