/* global start */
/* global stop */

import Ember from 'ember';
import { module, test } from 'qunit';
import startApp from '../helpers/start-app';

var App, users, cars, store;

module('Acceptance: Smoke Test', {
  beforeEach: function() {
    App = startApp();
    users = server.createList('user', 2);
    cars = server.createList('car', 4);
    store = App.__container__.lookup('service:store');
  },
  afterEach: function() {
    Ember.run(() => {
      window.localforage.setItem("foo", "");
    });
    Ember.run(App, 'destroy');
  }
});

test('localforage is populated on #findAll', function(assert) {
  assert.expect(6);

  visit('/');
  stop();
  andThen(() => {


    Ember.run.later(() => {
      store = App.__container__.lookup('service:store');

      let lfItems = window.localforage.getItem("foo");

      return lfItems.then(result => {
        assert.equal(result.user.records[1].firstName, users[0].firstName, "Record 1 from server === record 1 in locaclforage");
        assert.equal(result.user.records[2].firstName, users[1].firstName, "Record 2 from server === record 2 in locaclforage");
        assert.equal(store.peelAll('user').get('firstObject').firstName, users[0].firstName, "Record 1 in store === record 1 from server ");
        assert.equal(store.peelAll('user').get('lastObject').firstName, users[1].firstName, "Record 2 in store === record 2 from server ");
        assert.equal(store.peelAll('user').get('firstObject').firstName, result.user.records[1].firstName, "Record 1 in store === record 1 in localforage");
        assert.equal(store.peelAll('user').get('lastObject').firstName, result.user.records[2].firstName, "Record 2 in store === record 2 in localforage");
        start();
      });
    },3000);
  });
});

test('localforage is populated on #find', function(assert) {
  assert.expect(2);
  visit('/users/1');

  stop();
  andThen(() => {

    Ember.run.later(() => {
      let lfItems = window.localforage.getItem("foo");
      return lfItems.then(result => {
        console.log(JSON.stringify(result));
        assert.equal(result.car.records[1].label, cars[0].label);
        assert.equal(result.car.records[2].label, cars[1].label);
        start();
      });
    },4500);
  });
});

@@ -1128,33 +1128,33 @@
 .equal(store.pee
-l
+k
 All('user').get(
@@ -1160,32 +1160,37 @@
 ('firstObject').
+get('
 firstName, users
@@ -1174,32 +1174,34 @@
 ).get('firstName
+')
 , users%5B0%5D.first
@@ -1276,33 +1276,33 @@
 .equal(store.pee
-l
+k
 All('user').get(
@@ -1307,32 +1307,37 @@
 t('lastObject').
+get('
 firstName, users
@@ -1321,32 +1321,34 @@
 ).get('firstName
+')
 , users%5B1%5D.first
@@ -1423,33 +1423,33 @@
 .equal(store.pee
-l
+k
 All('user').get(
@@ -1455,32 +1455,37 @@
 ('firstObject').
+get('
 firstName, resul
@@ -1469,32 +1469,34 @@
 ).get('firstName
+')
 , result.user.re
@@ -1595,17 +1595,17 @@
 tore.pee
-l
+k
 All('use
@@ -1626,16 +1626,21 @@
 bject').
+get('
 firstNam
@@ -1640,16 +1640,18 @@
 irstName
+')
 , result

fix acceptence #1