Bugfix/fix issue with detection of thousand separator by locale (#4243)
* Fix issue with detection of thousand separator by locale * Update changelog
This commit is contained in:
parent
4b65b6277e
commit
512b84016c
@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
- Fixed an issue with the detection of the thousand separator by locale
|
||||||
- Fixed an issue with the MIME type detection in the scraper configuration
|
- Fixed an issue with the MIME type detection in the scraper configuration
|
||||||
|
|
||||||
## 2.135.0 - 2025-01-19
|
## 2.135.0 - 2025-01-19
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
import { extractNumberFromString } from '@ghostfolio/common/helper';
|
import {
|
||||||
|
extractNumberFromString,
|
||||||
|
getNumberFormatGroup
|
||||||
|
} from '@ghostfolio/common/helper';
|
||||||
|
|
||||||
describe('Helper', () => {
|
describe('Helper', () => {
|
||||||
describe('Extract number from string', () => {
|
describe('Extract number from string', () => {
|
||||||
@ -32,8 +35,85 @@ describe('Helper', () => {
|
|||||||
).toEqual(99999.99);
|
).toEqual(99999.99);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Get decimal number (comma notation) for locale where currency is not grouped by default', () => {
|
||||||
|
expect(
|
||||||
|
extractNumberFromString({ locale: 'es-ES', value: '999,99' })
|
||||||
|
).toEqual(999.99);
|
||||||
|
});
|
||||||
|
|
||||||
it('Not a number', () => {
|
it('Not a number', () => {
|
||||||
expect(extractNumberFromString({ value: 'X' })).toEqual(NaN);
|
expect(extractNumberFromString({ value: 'X' })).toEqual(NaN);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Get number format group', () => {
|
||||||
|
let languageGetter: jest.SpyInstance<string, [], any>;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
languageGetter = jest.spyOn(window.navigator, 'language', 'get');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Get de-CH number format group', () => {
|
||||||
|
expect(getNumberFormatGroup('de-CH')).toEqual('’');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Get de-CH number format group when it is default', () => {
|
||||||
|
languageGetter.mockReturnValue('de-CH');
|
||||||
|
expect(getNumberFormatGroup()).toEqual('’');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Get de-DE number format group', () => {
|
||||||
|
expect(getNumberFormatGroup('de-DE')).toEqual('.');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Get de-DE number format group when it is default', () => {
|
||||||
|
languageGetter.mockReturnValue('de-DE');
|
||||||
|
expect(getNumberFormatGroup()).toEqual('.');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Get en-GB number format group', () => {
|
||||||
|
expect(getNumberFormatGroup('en-GB')).toEqual(',');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Get en-GB number format group when it is default', () => {
|
||||||
|
languageGetter.mockReturnValue('en-GB');
|
||||||
|
expect(getNumberFormatGroup()).toEqual(',');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Get en-US number format group', () => {
|
||||||
|
expect(getNumberFormatGroup('en-US')).toEqual(',');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Get en-US number format group when it is default', () => {
|
||||||
|
languageGetter.mockReturnValue('en-US');
|
||||||
|
expect(getNumberFormatGroup()).toEqual(',');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Get es-ES number format group', () => {
|
||||||
|
expect(getNumberFormatGroup('es-ES')).toEqual('.');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Get es-ES number format group when it is default', () => {
|
||||||
|
languageGetter.mockReturnValue('es-ES');
|
||||||
|
expect(getNumberFormatGroup()).toEqual('.');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Get ru-RU number format group', () => {
|
||||||
|
expect(getNumberFormatGroup('ru-RU')).toEqual(' ');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Get ru-RU number format group when it is default', () => {
|
||||||
|
languageGetter.mockReturnValue('ru-RU');
|
||||||
|
expect(getNumberFormatGroup()).toEqual(' ');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Get zh-CN number format group', () => {
|
||||||
|
expect(getNumberFormatGroup('zh-CN')).toEqual(',');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Get zh-CN number format group when it is default', () => {
|
||||||
|
languageGetter.mockReturnValue('zh-CN');
|
||||||
|
expect(getNumberFormatGroup()).toEqual(',');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -251,7 +251,9 @@ export function getNumberFormatDecimal(aLocale?: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getNumberFormatGroup(aLocale = getLocale()) {
|
export function getNumberFormatGroup(aLocale = getLocale()) {
|
||||||
const formatObject = new Intl.NumberFormat(aLocale).formatToParts(9999.99);
|
const formatObject = new Intl.NumberFormat(aLocale, {
|
||||||
|
useGrouping: true
|
||||||
|
}).formatToParts(9999.99);
|
||||||
|
|
||||||
return formatObject.find((object) => {
|
return formatObject.find((object) => {
|
||||||
return object.type === 'group';
|
return object.type === 'group';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user