import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { setupMirage } from 'ember-cli-mirage/test-support';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';

module('Integration | Component | meal-list', function(hooks) {
  setupRenderingTest(hooks);
  setupMirage(hooks);

  hooks.beforeEach(initMeals);

  test('it renders existing meals into a list', async function(assert) {
    await render(hbs`<MealList />`);

    assert.dom('[data-test-id=meal-item]').exists({ count: 2 });
  });

  // TODO Add sortable tests

  async function initMeals() {
    let store = this.owner.lookup('service:store');
    let meal = {
      area: 'area',
      category: 'category',
      ingredients: [
        { name: 'Love', measure: 'Infinity' },
        { name: 'Chocolate', measure: 'As much as you like!' },
      ],
    };
    this.server.create('meal', Object.assign({}, meal, { name: 'Meal 1', id: 1 }));
    this.server.create('meal', Object.assign({}, meal, { name: 'Meal 2', id: 2 }));
    await store.findRecord('meal', 1);
    await store.findRecord('meal', 2);
  }
});
