var config = require('./config');

var i18n = require('./i18n');

var strings = {
  FOO: 'Foo'
};
describe('i18n', function () {
  beforeAll(function () {
    config.testConfig();
  });
  it('rejects loading if loader not configured', function () {
    return i18n.loadStrings().then(function () {
      throw new Error('This should not be reached');
    }).catch(function (e) {
      expect(e.message).toBe('Strings loader have not been configured yet, check startup sequence');
    });
  });
  it('resolves with strings', function () {
    i18n.setStringsLoader(function () {
      return Promise.resolve(strings);
    });
    return i18n.loadStrings().then(function (strs) {
      expect(strs).toEqual(strings);
      expect(i18n.getStrings()).toEqual(strings);
    });
  });
  it('fails when strings are not loaded', function () {
    i18n.setStrings(undefined); // simulate not loaded strings

    expect(function () {
      i18n.getStrings();
    }).toThrow('Strings have not been loaded yet, check startup sequence');
  });
});