import EmberObject from '@ember/object';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, click, findAll, triggerEvent } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';

module('Integration | Component | class field description', function (hooks) {
  setupRenderingTest(hooks);

  test('it renders', async function (assert) {
    this.set('type', 'method');
    this.set(
      'field',
      EmberObject.create({
        access: 'public',
        deprecated: true,
        name: 'concat',
        description: 'concatenates',
        params: [{ name: 'param1' }, { name: 'param2' }, { name: 'param3' }],
      })
    );

    await render(hbs`{{class-field-description type=type field=field}}`);

    assert.dom('.method-name').hasText('concat');
    assert.dom(findAll('.access')[0]).hasText('public');
    assert.dom(findAll('.access')[1]).hasText('deprecated');
    assert.dom(findAll('.args')[0]).hasText('(param1, param2, param3)');
  });

  test('On hover -- the link icon shows up', async function (assert) {
    this.set('type', 'method');
    this.set(
      'field',
      EmberObject.create({
        access: 'public',
        deprecated: true,
        name: 'concat',
        description: 'concatenates',
        params: [{ name: 'param1' }, { name: 'param2' }, { name: 'param3' }],
      })
    );

    await render(hbs`{{class-field-description type=type field=field}}`);

    await triggerEvent('.class-field-description--link', 'mouseenter');
    assert
      .dom('.class-field-description--link-hover')
      .exists('The link icon appears when hovering on the method text');
  });

  test('it calls the provided action on link-click with the field name as an arg', async function (assert) {
    this.set('updateAnchor', (name) => {
      assert.equal(
        name,
        'field-name',
        'expected the field name to be passed into the action'
      );
      assert.step('updateAnchorAction');
    });

    this.set(
      'field',
      EmberObject.create({
        name: 'field-name',
      })
    );

    await render(
      hbs`{{class-field-description field=field updateAnchor=updateAnchor}}`
    );

    await click('.class-field-description--link');

    assert.verifySteps(['updateAnchorAction']);
  });
});

@@ -154,16 +154,22 @@
 findAll,
+ find,
  trigger
@@ -2319,13 +2319,634 @@
 );%0A  %7D);
+%0A%0A  test('parameter props are displayed', async function (assert) %7B%0A    this.set('type', 'method');%0A    this.set(%0A      'field',%0A      EmberObject.create(%7B%0A        access: 'public',%0A        deprecated: true,%0A        name: 'concat',%0A        description: 'concatenates',%0A        params: %5B%7B name: 'param1' %7D, %7B name: 'param2' %7D, %7B name: 'options', props: %5B %7B name: 'prop1' %7D, %7B name: 'prop2' %7D%5D %7D%5D,%0A      %7D)%0A    );%0A%0A    await render(hbs%60%7B%7Bclass-field-description type=type field=field%7D%7D%60);%0A%0A    assert.dom(find('.prop:nth-child(1) dt')).hasText('prop1');%0A    assert.dom(find('.prop:nth-child(2) dt')).hasText('prop2');%0A  %7D);
 %0A%7D);%0A

add a test