import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { visit, currentURL, fillIn, click } from '@ember/test-helpers';
import { selectChoose } from 'ember-power-select/test-support/helpers';
import RSVP from 'rsvp';

function run(fn) {
  return RSVP.resolve().then(() => fn.apply(this, arguments));
}

module('Acceptance | field editors', async function(hooks) {
  setupApplicationTest(hooks);

  test('visiting /editor', async function(assert) {
    await visit('/editor');
    assert.equal(currentURL(), '/editor');

    this.store = this.owner.lookup('service:store');
    let model = await run(() => {
      return this.store.find('driver', 'metalmario');
    });
    let feeling = await model.get('feeling.title');
    let vehicle = await model.get('vehicle.name');
    let alternateVehicle = await model.get('alternateVehicle.name');
    let tracks = await model.get('tracks.length');
    let firstTrack = await model.get('tracks.firstObject.name');
    let lastTrack = await model.get('tracks.lastObject.name');

    assert.equal(model.get('name'), 'Metal Mario', 'driver name is correct');
    assert.equal(model.get('dob'), '1999-01-01', 'driver dob is correct');
    assert.equal(model.get('latestVictory'), '2018-10-25T13:56:05', 'driver latest victory is correct');
    assert.equal(model.get('isGoodGuy'), true, 'driver is a good guy');
    assert.equal(feeling, 'Happy', 'driver is feeling happy');
    assert.equal(vehicle, 'Sport Bike', 'driver is using a sport bike');
    assert.equal(alternateVehicle, 'Standard Kart', 'drivers alternate vehicle is a standard kart');
    assert.equal(tracks, '3', 'drivers has 3 tracks');
    assert.equal(firstTrack, 'Rainbow Road', 'drivers first track is rainbow road');
    assert.equal(lastTrack, 'Koopa City', 'drivers final track is koopa city');

    await fillIn('.ember-text-field:nth-of-type(1)', 'METAL Mario');
    await fillIn('input[type=date]', '1998-01-01');
    await fillIn('input[type=datetime-local]', '2018-10-27T23:56:07');
    await click('.cs-toggle-switch');
    await selectChoose('.feeling-selector', 'Sad');
    await selectChoose('.vehicle-selector', 'Honeycoupe');
    await selectChoose('.alternate-vehicle-selector', 'Wild Wiggler');
    await selectChoose('.tracks-selector', 'Twisted Mansion');

    assert.dom('.feeling-selector .ember-power-select-selected-item').hasText('Sad');
    assert.dom('.vehicle-selector .ember-power-select-selected-item').hasText('Honeycoupe');
    assert.dom('.alternate-vehicle-selector .ember-power-select-selected-item').hasText('Wild Wiggler');
    assert.dom('.tracks-selector .ember-power-select-multiple-option').exists({ count: 4 });
    assert.dom('.tracks-selector .ember-power-select-multiple-option:nth-of-type(1)').hasText('× Rainbow Road');
    assert.dom('.tracks-selector .ember-power-select-multiple-option:nth-of-type(4)').hasText('× Twisted Mansion');

    feeling = await model.get('feeling.title');
    vehicle = await model.get('vehicle.name');
    alternateVehicle = await model.get('alternateVehicle.name');
    lastTrack = await model.get('tracks.lastObject.name');

    assert.equal(model.get('name'), 'METAL Mario', 'metal mario is more metal');
    assert.equal(model.get('dob'), '1998-01-01', 'metal mario was born earlier');
    assert.equal(model.get('latestVictory'), '2018-10-27T23:56:07', 'metal mario won a race more recently');
    assert.equal(model.get('isGoodGuy'), false, 'metal mario is a bad guy');
    assert.equal(feeling, 'Sad', 'metal mario is sad');
    assert.equal(vehicle, 'Honeycoupe', 'metal mario is driving a honeycoupe');
    assert.equal(alternateVehicle, 'Wild Wiggler', 'metal marios alternate vehicle is a wild wiggler');
    assert.equal(lastTrack, 'Twisted Mansion', 'drivers final track is twisted mansion');
  });
});

@@ -176,16 +176,38 @@
 ctChoose
+, removeMultipleOption
  %7D from 
@@ -2336,24 +2336,158 @@
 d Mansion');
+%0A    await removeMultipleOption('.tracks-selector', 'Rainbow Road');%0A    await removeMultipleOption('.tracks-selector', 'Koopa City');
 %0A%0A    assert
@@ -2847,17 +2847,17 @@
  count: 
-4
+2
  %7D);%0A   
@@ -2950,28 +2950,34 @@
 Text('%C3%97 
-Rainbow Road
+Sweet Sweet Canyon
 ');%0A    
@@ -3057,9 +3057,9 @@
 ype(
-4
+2
 )').
@@ -3245,24 +3245,85 @@
 cle.name');%0A
+    firstTrack = await model.get('tracks.firstObject.name');%0A
     lastTrac
@@ -3847,32 +3847,32 @@
 a honeycoupe');%0A
-
     assert.equal
@@ -3951,32 +3951,129 @@
 wild wiggler');%0A
+    assert.equal(firstTrack, 'Sweet Sweet Canyon', 'drivers first track is sweet sweet canyon');%0A
     assert.equal

Test removing selection