import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import Ember from 'ember';

import { run } from '@ember/runloop';

const {
  getProperties,
  get,
  set
} = Ember;

module('Unit | Model | Settings', function(hooks) {
  setupTest(hooks);

  hooks.beforeEach(function() {
    window.localStorage.clear();
  });

  hooks.afterEach(function() {
    window.localStorage.clear();
  });

  test('it has default settings when no local settings are present', function(assert) {
    assert.expect(1);

    const settings = run(() => this.owner.lookup('service:store').createRecord('settings'));

    assert.deepEqual(getProperties(settings, 'keyMap'), {
      keyMap: 'default'
    }, 'default settings are present');
  });

  test('settings stored in localStorage override default settings', function(assert) {
    assert.expect(1);

    const localSettings = JSON.stringify({ keyMap: 'vim' });
    window.localStorage.setItem('ember_twiddle_settings', localSettings);

    const settings = run(() => this.owner.lookup('service:store').createRecord('settings'));

    assert.deepEqual(getProperties(settings, 'keyMap'), {
      keyMap: 'vim'
    }, 'local settings overrode default settings');
  });

  test('save() persists settings to localStorage', function(assert) {
    assert.expect(1);

    const settings = run(() => this.owner.lookup('service:store').createRecord('settings'));

    set(settings, 'keyMap', 'emacs');
    settings.save();

    const anotherSettings = run(() => this.owner.lookup('service:store').createRecord('settings'));
    assert.equal(get(anotherSettings, 'keyMap'), 'emacs',
      'new Settings has previously persisted settings');
  });
});

@@ -98,16 +98,70 @@
 'ember';
+%0Aimport Settings from 'ember-twiddle/models/settings';
 %0A%0Aimport
@@ -595,77 +595,24 @@
 s = 
-run(() =%3E this.owner.lookup('service:store').createRecord('settings')
+Settings.create(
 );%0A%0A
@@ -1011,77 +1011,24 @@
 s = 
-run(() =%3E this.owner.lookup('service:store').createRecord('settings')
+Settings.create(
 );%0A%0A
@@ -1214,16 +1214,22 @@
 torage',
+ async
  functio
@@ -1288,77 +1288,24 @@
 s = 
-run(() =%3E this.owner.lookup('service:store').createRecord('settings')
+Settings.create(
 );%0A%0A
@@ -1396,77 +1396,24 @@
 s = 
-run(() =%3E this.owner.lookup('service:store').createRecord('settings')
+Settings.create(
 );%0A 

fix settings tests