{"size": 2738, "ext": "js", "max_stars_repo_path": "tests/integration/components/dashboard/selected-term-tree-test.js", "max_stars_repo_name": "stopfstedt/common", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tests/integration/components/dashboard/selected-term-tree-test.js", "max_issues_repo_name": "stopfstedt/common", "max_issues_repo_issues_event_min_datetime": "2021-05-05T09:22:58.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T09:25:52.000Z", "max_forks_repo_path": "tests/integration/components/dashboard/selected-term-tree-test.js", "max_forks_repo_name": "stopfstedt/common", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 170, "max_forks_count": null, "avg_line_length": 31.4712643678, "max_line_length": 92, "alphanum_fraction": 0.6176040906}
import EmberObject from '@ember/object';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { setupIntl } from 'ember-intl/test-support';
import { render, click } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';

module('Integration | Component | dashboard/SelectedTermTree', function (hooks) {
  setupRenderingTest(hooks);
  setupIntl(hooks, 'en-us');

  const tree = [
    EmberObject.create({
      id: 1,
      title: 'top 1',
      children: [],
    }),
    EmberObject.create({
      id: 2,
      title: 'top 2',
      children: [
        EmberObject.create({
          id: 3,
          title: 'top 2 child 1',
          children: [],
        }),
      ],
    }),
  ];

  test('it renders a tree', async function (assert) {
    this.set('tree', tree);
    this.set('selectedTermIds', [3]);
    await render(hbs`<Dashboard::SelectedTermTree
      @terms={{this.tree}}
      @selectedTermIds={{this.selectedTermIds}}
      @add={{(noop)}}
      @remove={{(noop)}}
    />`);
    const topTerms = 'ul:nth-of-type(1) > li';
    const firstTopTerm = `${topTerms}:nth-of-type(1)`;
    const firstTopTermCheckbox = `${firstTopTerm} input`;
    const secondTopTerm = `${topTerms}:nth-of-type(2)`;
    const firstTopTermChildren = `${firstTopTerm} ul > li`;
    const secondTopTermChildren = `${secondTopTerm} ul > li`;
    const secondTopTermFirstChildCheckbox = `${secondTopTermChildren}:nth-of-type(1) input`;

    assert.dom(firstTopTerm).hasText('top 1');
    assert.dom(firstTopTermCheckbox).isNotChecked();
    assert.dom(secondTopTerm).hasText('top 2 top 2 child 1');
    assert.dom(firstTopTermChildren).doesNotExist();
    assert.dom(secondTopTermChildren).hasText('top 2 child 1');
    assert.dom(secondTopTermFirstChildCheckbox).isChecked();
  });

  test('clicking unchecked checkbox fires add', async function (assert) {
    assert.expect(1);
    this.set('tree', tree);
    this.set('add', (id) => {
      assert.strictEqual(id, 1);
    });
    await render(hbs`<Dashboard::SelectedTermTree
      @terms={{this.tree}}
      @selectedTermIds={{(array)}}
      @add={{this.add}}
      @remove={{(noop)}}
    />`);
    await click('[data-test-target]:nth-of-type(1)');
  });

  test('clicking checked checkbox fires add', async function (assert) {
    assert.expect(1);
    this.set('tree', tree);
    this.set('selectedTermIds', [1]);
    this.set('remove', (id) => {
      assert.strictEqual(id, 1);
    });
    await render(hbs`<Dashboard::SelectedTermTree
      @terms={{this.tree}}
      @selectedTermIds={{this.selectedTermIds}}
      @add={{(noop)}}
      @remove={{this.remove}}
    />`);
    await click('[data-test-target]:nth-of-type(1)');
  });
});
