import Ember from 'ember';
import I18nInstanceInitializer from 'ember-flexberry/instance-initializers/i18n';
import { module, test } from 'qunit';
import startApp from '../../helpers/start-app';
import destroyApp from '../../helpers/destroy-app';

let application;
let appInstance;

module('Unit | Instance Initializer | i18n', {
  beforeEach: function() {
    application = startApp();
    appInstance = application.buildInstance();
  },
  afterEach: function() {
    Ember.run(appInstance, 'destroy');
    destroyApp(appInstance);
  }
});

test('It works', function(assert) {
  assert.expect(1);
  I18nInstanceInitializer.initialize(appInstance);
  assert.ok(true);
});

test('Add true logic', function(assert) {
  assert.expect(2);
  assert.strictEqual(appInstance.__container__.factoryCache['service:i18n'], undefined);
  I18nInstanceInitializer.initialize(appInstance);
  assert.strictEqual(appInstance.__container__.factoryCache['service:i18n']._toString, 'dummy@service:i18n:');
});

test('Configures i18n service for locale', function(assert) {
  assert.expect(1);

  var controlValue = window.navigator.languages ? window.navigator.languages[0] : (window.navigator.language || window.navigator.userLanguage);
  I18nInstanceInitializer.initialize(appInstance);
  assert.strictEqual(appInstance.__container__.cache['service:i18n'].locale, controlValue);
});

import I18nInstanceInitializer from 'ember-flexberry/instance-initializers/i18n';
import { module, test } from 'qunit';
import startApp from '../../helpers/start-app';
import destroyApp from '../../helpers/destroy-app';

let application;
let appInstance;
let fakeLocale;

module('Unit | Instance Initializer | i18n', {
  beforeEach: function() {
    application = startApp();
    appInstance = application.buildInstance();

    // Set 'fake-locale' as default i18n-service locale.
    let i18n = appInstance.lookup('service:i18n');
    fakeLocale = 'fake-locale';
    i18n.set('locale', fakeLocale);
  },
  afterEach: function() {
    destroyApp(appInstance);
    destroyApp(application);
  }
});

test('Configures i18n service for locale', function(assert) {
  assert.expect(2);

  let i18n = appInstance.lookup('service:i18n');
  assert.strictEqual(i18n.get('locale'), fakeLocale, 'Default i18n-service locale is \'' + fakeLocale + '\'');

  var browserCurrentLocale = window.navigator.languages ? window.navigator.languages[0] : (window.navigator.language || window.navigator.userLanguage);
  I18nInstanceInitializer.initialize(appInstance);

  assert.strictEqual(i18n.get('locale'), browserCurrentLocale, 'Current i18n-service locale is \'' + browserCurrentLocale + '\'');
});

Remove unnecessary tests from i18n instance-initializer tests