import {moduleForComponent, test} from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import registration from 'admin/tests/helpers/registration';

var store;

moduleForComponent('issue-detail', 'integration: issue-detail test', {
    integration: true,
    setup() {
        store = registration(this.container, this.registry, ['model:issue', 'model:status']);
    }
});

test('each status should be option in the status select box', function(assert) {
    var issue = store.push('issue', {id: 1});
    store.push('status', {id: 8, name: 'Open'});
    store.push('status', {id: 9, name: 'Closed'});
    var statuses = store.find('status');
    this.set('model', issue);
    this.set('statuses', statuses);
    this.render(hbs`{{issue-detail model=model statuses=statuses}}`);
    var selector = 'select.detail-status + .selectize-control';
    var component = this.$(selector);
    assert.equal(component.find('div.option').length, 2);
    assert.equal(component.find('div.option:eq(0)').data('value'), 8);
    assert.equal(component.find('div.option:eq(1)').data('value'), 9);
    assert.equal(component.find('div.option:eq(0)').text(), 'Open');
    assert.equal(component.find('div.option:eq(1)').text(), 'Closed');
});

test('selected status will match the status of the user', function(assert) {
import {module, test} from 'admin/tests/helpers/qunit';
import users from 'admin/vendor/fixtures/users';
import UserDeserializer from 'admin/deserializers/user';
import User from 'admin/models/user';
import registration from 'admin/tests/helpers/registration';

var store;

module('unit: user deserializer test', {
    beforeEach() {
        store = registration(this.container, this.registry, ['model:user']);
    }
});

test('api response deserialized into user models', (assert) => {
    var subject = UserDeserializer.create({simpleStore: store});
    subject.deserialize(users.list());
    var models = store.find('user');
    assert.equal(models.get('length'), 3);
    assert.equal(models.objectAt(0).get('name'), users.list()[0].name);
});

test('scott wat', (assert) => {
    const user = store.push('user', {id: 1})
    var models = store.find('user');
    assert.equal(models.get('length'), 1);
    assert.equal(user.get('wat').get('length'), 1);
});

test('scott wat2', (assert) => {
    const user = User.create({simpleStore: store, id: 1})
import {test, module} from 'admin/tests/helpers/qunit';
import registration from 'admin/tests/helpers/registration';

var store, service;

module('unit: store service test', {
    beforeEach() {
        store = registration(this.container, this.registry, ['model:status', 'service:store']);
        service = this.container.lookup('service:store');
    }
});

test('will proxy any method to the actual store object', function(assert) {
    service.push('status', {id: 1, name: 'x'});
    service.push('status', {id: 2, name: 'y'});
    assert.equal(service.find('status').get('length'), 2);
    assert.equal(store.find('status').get('length'), 2);
    service.clear('status');
    assert.equal(service.find('status').get('length'), 0);
    assert.equal(store.find('status').get('length'), 0);
});