<commit_before>import { assert } from 'chai';
import I18nManager from './I18nManager';

describe('I18nManager', () => {
  let i18n;
  let deI18n;

  before('instantiate new intl manager', () => {
    const formatInfos = {
      'en-US': {
        datePattern: 'dd/MM/yyyy',
        dateTimePattern: 'dd/MM/yyyy HH:mm:ss',
        integerPattern: '#,##0',
        numberPattern: '#,##0.00',
        numberDecimalSeparator: '.',
        numberGroupingSeparator: ',',
        numberGroupingSeparatorUse: true,
      },
    };
    i18n = new I18nManager('en-US', [{
      locales: ['en-US'],
      messages: {
        test: 'test',
      },
    }], formatInfos);
    i18n = i18n.register('component', [{
      locales: ['en-US'],
      messages: {
        component: {
          test: 'test component',
          format: 'min={min}, max={max}',
        },
      },
    }]);
  });

  it('should get fallback message', () => {
    deI18n = new I18nManager('de-DE', [], {});

    deI18n.register('test_component', [
      {
        locales: ['en'],
        messages: {
          component: {
            testMessage1: 'en test message 1',
            testMessage2: 'en test message 2',
          },
        },
      },
      {
        locales: ['de'],
        messages: {
          component: {
            testMessage2: 'de test message 2',
          },
        },
      },
    ]);

    assert.equal('en test message 1', deI18n.getMessage('component.testMessage1'));
    assert.equal('de test message 2', deI18n.getMessage('component.testMessage2'));
    assert.equal('component.testMessage3', deI18n.getMessage('component.testMessage3'));
  });

  it('should contain test message', () => {
    const message = i18n.getMessage('test');
    assert.equal('test', message);
  });

  it('should contain component test message', () => {
    const message = i18n.getMessage('component.test');
    assert.equal('test component', message);
  });

  it('test object message', () => {
    const message = i18n.getMessage('component');
    assert.equal('component', message);
  });

  it('should format and parse date', () => {
    const date = new Date(2001, 0, 10);
    const dateAsString = i18n.formatDate(date);
    assert.equal('10/01/2001', dateAsString);

    const dateAsObject = i18n.parseDate(dateAsString);
    assert.equal(date.toString(), dateAsObject.toString());
  });

  it('should format and parse date and time', () => {
    const date = new Date(2001, 0, 10);
    const dateTimeAsString = i18n.formatDateTime(date);
    assert.equal('10/01/2001 00:00:00', dateTimeAsString);
  });

  it('should format and parse numbers', () => {
    assert.equal('10,000', i18n.formatNumber(10000));
    assert.equal(10000, i18n.parseNumber('10,000'));

    assert.equal('10,000.00', i18n.formatDecimalNumber(10000));
    assert.equal(10000, i18n.parseDecimalNumber('10,000.00'));
  });

  it('should formatted message', () => {
    let message = i18n.getMessage('component.format');
    assert.equal('min={min}, max={max}', message);

    message = i18n.getMessage('component.format', { min: 10, max: 100 });
    assert.equal('min=10, max=100', message);
  });
});
<commit_msg>(CMMN-5044) Added tests for formatDecimalNumber method.<commit_after>import { assert } from 'chai';
import I18nManager from './I18nManager';

describe('I18nManager', () => {
  let i18n;
  let deI18n;

  before('instantiate new intl manager', () => {
    const formatInfos = {
      'en-US': {
        datePattern: 'dd/MM/yyyy',
        dateTimePattern: 'dd/MM/yyyy HH:mm:ss',
        integerPattern: '#,##0',
        numberPattern: '#,##0.00',
        numberDecimalSeparator: '.',
        numberGroupingSeparator: ',',
        numberGroupingSeparatorUse: true,
      },
    };
    i18n = new I18nManager('en-US', [{
      locales: ['en-US'],
      messages: {
        test: 'test',
      },
    }], formatInfos);
    i18n = i18n.register('component', [{
      locales: ['en-US'],
      messages: {
        component: {
          test: 'test component',
          format: 'min={min}, max={max}',
        },
      },
    }]);
  });

  it('should get fallback message', () => {
    deI18n = new I18nManager('de-DE', [], {});

    deI18n.register('test_component', [
      {
        locales: ['en'],
        messages: {
          component: {
            testMessage1: 'en test message 1',
            testMessage2: 'en test message 2',
          },
        },
      },
      {
        locales: ['de'],
        messages: {
          component: {
            testMessage2: 'de test message 2',
          },
        },
      },
    ]);

    assert.equal('en test message 1', deI18n.getMessage('component.testMessage1'));
    assert.equal('de test message 2', deI18n.getMessage('component.testMessage2'));
    assert.equal('component.testMessage3', deI18n.getMessage('component.testMessage3'));
  });

  it('should contain test message', () => {
    const message = i18n.getMessage('test');
    assert.equal('test', message);
  });

  it('should contain component test message', () => {
    const message = i18n.getMessage('component.test');
    assert.equal('test component', message);
  });

  it('test object message', () => {
    const message = i18n.getMessage('component');
    assert.equal('component', message);
  });

  it('should format and parse date', () => {
    const date = new Date(2001, 0, 10);
    const dateAsString = i18n.formatDate(date);
    assert.equal('10/01/2001', dateAsString);

    const dateAsObject = i18n.parseDate(dateAsString);
    assert.equal(date.toString(), dateAsObject.toString());
  });

  it('should format and parse date and time', () => {
    const date = new Date(2001, 0, 10);
    const dateTimeAsString = i18n.formatDateTime(date);
    assert.equal('10/01/2001 00:00:00', dateTimeAsString);
  });

  it('should format and parse numbers', () => {
    assert.equal('10,000', i18n.formatNumber(10000));
    assert.equal(10000, i18n.parseNumber('10,000'));

    assert.equal('10,000.00', i18n.formatDecimalNumber(10000));
    assert.equal(10000, i18n.parseDecimalNumber('10,000.00'));

    assert.strictEqual(i18n.formatDecimalNumber(123456789.12), '123,456,789.12');
    assert.strictEqual(i18n.formatDecimalNumber(55454545.12), '55,454,545.12');
  });

  it('should formatted message', () => {
    let message = i18n.getMessage('component.format');
    assert.equal('min={min}, max={max}', message);

    message = i18n.getMessage('component.format', { min: 10, max: 100 });
    assert.equal('min=10, max=100', message);
  });
});

{'fraction_non_alphanumeric': 0.1763355273228226, 'fraction_numerical': 0.056635542629726005, 'mean_word_length': 2.854867256637168, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2620528', 'n_tokens_mistral': 2304, 'n_tokens_neox': 2063, 'n_words': 401}