<commit_before>import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';

moduleForComponent('bs-tab', 'Integration | Component | bs-tab', {
  integration: true
});

function assertActiveTab(assert, tabIndex, active = true) {
  assert.equal(this.$(`ul.nav.nav-tabs li:eq(${tabIndex})`).hasClass('active'), active, active ? 'tab is active' : 'tab is inactive');
  assert.equal(this.$(`.tab-content .tab-pane:eq(${tabIndex})`).hasClass('active'), active, active ? 'tab pane is active' : 'tab pane is inactive');
}

test('it generates tab navigation', function(assert) {
  this.render(hbs`
    {{#bs-tab}}
      {{#bs-tab-pane title="Tab 1"}}
        tabcontent 1
      {{/bs-tab-pane}}
      {{#bs-tab-pane title="Tab 2"}}
        tabcontent 2
      {{/bs-tab-pane}}
    {{/bs-tab}}
  `);

  assert.equal(this.$('ul.nav.nav-tabs').length, 1, 'has tabs navigation');
  assert.equal(this.$('ul.nav.nav-tabs > li').length, 2, 'has tabs navigation items');
  assert.equal(this.$('ul.nav.nav-tabs > li:eq(0) > a').text().trim(), 'Tab 1', 'navigation item shows pane title');
  assert.equal(this.$('ul.nav.nav-tabs > li:eq(1) > a').text().trim(), 'Tab 2', 'navigation item shows pane title');
});

test('first tab is active by default', function(assert) {
  this.render(hbs`
    {{#bs-tab}}
      {{#bs-tab-pane title="Tab 1"}}
        tabcontent 1
      {{/bs-tab-pane}}
      {{#bs-tab-pane title="Tab 2"}}
        tabcontent 2
      {{/bs-tab-pane}}
    {{/bs-tab}}
  `);

  assertActiveTab(assert, 0, true);
  assertActiveTab(assert, 1, false);
});

test('clicking tab activates it', function(assert) {
  this.render(hbs`
    {{#bs-tab fade=false}}
      {{#bs-tab-pane title="Tab 1"}}
        tabcontent 1
      {{/bs-tab-pane}}
      {{#bs-tab-pane title="Tab 2"}}
        tabcontent 2
      {{/bs-tab-pane}}
    {{/bs-tab}}
  `);

  this.$('ul.nav.nav-tabs li:eq(1) a').click();

  assertActiveTab(assert, 0, false);
  assertActiveTab(assert, 1, true);
});

test('activeId activates tabs', function(assert) {
  this.set('paneId', 'pane1');
  this.render(hbs`
    {{#bs-tab fade=false activeId=paneId}}
      {{#bs-tab-pane elementId="pane1" title="Tab 1"}}
        tabcontent 1
      {{/bs-tab-pane}}
      {{#bs-tab-pane elementId="pane2" title="Tab 2"}}
        tabcontent 2
      {{/bs-tab-pane}}
    {{/bs-tab}}
  `);

  assertActiveTab(assert, 0, true);
  assertActiveTab(assert, 1, false);

  this.set('paneId', 'pane2');

  assertActiveTab(assert, 0, false);
  assertActiveTab(assert, 1, true);
});

test('tab navigation is groupable', function(assert) {
  this.render(hbs`
    {{#bs-tab}}
      {{#bs-tab-pane title="Tab 1"}}
          tabcontent 1
      {{/bs-tab-pane}}
      {{#bs-tab-pane title="Tab 2"}}
          tabcontent 2
      {{/bs-tab-pane}}
      {{#bs-tab-pane title="Tab 3" groupTitle="Dropdown"}}
          tabcontent 3
      {{/bs-tab-pane}}
      {{#bs-tab-pane title="Tab 4" groupTitle="Dropdown"}}
          tabcontent 4
      {{/bs-tab-pane}}
    {{/bs-tab}}
  `);

  assert.equal(this.$('ul.nav.nav-tabs').length, 1, 'has tabs navigation');
  assert.equal(this.$('ul.nav.nav-tabs > li').length, 3, 'has tabs navigation items');
  assert.equal(this.$('ul.nav.nav-tabs > li:eq(0) > a').text().trim(), 'Tab 1', 'navigation item shows pane title');
  assert.equal(this.$('ul.nav.nav-tabs > li:eq(1) > a').text().trim(), 'Tab 2', 'navigation item shows pane title');
  assert.equal(this.$('ul.nav.nav-tabs > li:eq(2)').hasClass('dropdown'), true, 'adds dropdown for grouped items');
  assert.equal(this.$('ul.nav.nav-tabs > li:eq(2) > a').text().trim(), 'Dropdown', 'drop down item shows pane groupTitle');<commit_msg>test(Tab): fixed broken assertActiveTab scope<commit_after>import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';

moduleForComponent('bs-tab', 'Integration | Component | bs-tab', {
  integration: true
});

function assertActiveTab(assert, tabIndex, active = true) {
  assert.equal(this.$(`ul.nav.nav-tabs li:eq(${tabIndex})`).hasClass('active'), active, active ? 'tab is active' : 'tab is inactive');
  assert.equal(this.$(`.tab-content .tab-pane:eq(${tabIndex})`).hasClass('active'), active, active ? 'tab pane is active' : 'tab pane is inactive');
}

test('it generates tab navigation', function(assert) {
  this.render(hbs`
    {{#bs-tab}}
      {{#bs-tab-pane title="Tab 1"}}
        tabcontent 1
      {{/bs-tab-pane}}
      {{#bs-tab-pane title="Tab 2"}}
        tabcontent 2
      {{/bs-tab-pane}}
    {{/bs-tab}}
  `);

  assert.equal(this.$('ul.nav.nav-tabs').length, 1, 'has tabs navigation');
  assert.equal(this.$('ul.nav.nav-tabs > li').length, 2, 'has tabs navigation items');
  assert.equal(this.$('ul.nav.nav-tabs > li:eq(0) > a').text().trim(), 'Tab 1', 'navigation item shows pane title');
  assert.equal(this.$('ul.nav.nav-tabs > li:eq(1) > a').text().trim(), 'Tab 2', 'navigation item shows pane title');
});

test('first tab is active by default', function(assert) {
  this.render(hbs`
    {{#bs-tab}}
      {{#bs-tab-pane title="Tab 1"}}
        tabcontent 1
      {{/bs-tab-pane}}
      {{#bs-tab-pane title="Tab 2"}}
        tabcontent 2
      {{/bs-tab-pane}}
    {{/bs-tab}}
  `);

  assertActiveTab.call(this, assert, 0, true);
  assertActiveTab.call(this, assert, 1, false);
});

test('clicking tab activates it', function(assert) {
  this.render(hbs`
    {{#bs-tab fade=false}}
      {{#bs-tab-pane title="Tab 1"}}
        tabcontent 1
      {{/bs-tab-pane}}
      {{#bs-tab-pane title="Tab 2"}}
        tabcontent 2
      {{/bs-tab-pane}}
    {{/bs-tab}}
  `);

  this.$('ul.nav.nav-tabs li:eq(1) a').click();

  assertActiveTab.call(this, assert, 0, false);
  assertActiveTab.call(this, assert, 1, true);
});

test('activeId activates tabs', function(assert) {
  this.set('paneId', 'pane1');
  this.render(hbs`
    {{#bs-tab fade=false activeId=paneId}}
      {{#bs-tab-pane elementId="pane1" title="Tab 1"}}
        tabcontent 1
      {{/bs-tab-pane}}
      {{#bs-tab-pane elementId="pane2" title="Tab 2"}}
        tabcontent 2
      {{/bs-tab-pane}}
    {{/bs-tab}}
  `);

  assertActiveTab.call(this, assert, 0, true);
  assertActiveTab.call(this, assert, 1, false);

  this.set('paneId', 'pane2');

  assertActiveTab.call(this, assert, 0, false);
  assertActiveTab.call(this, assert, 1, true);
});

test('tab navigation is groupable', function(assert) {
  this.render(hbs`
    {{#bs-tab}}
      {{#bs-tab-pane title="Tab 1"}}
          tabcontent 1
      {{/bs-tab-pane}}
      {{#bs-tab-pane title="Tab 2"}}
          tabcontent 2
      {{/bs-tab-pane}}
      {{#bs-tab-pane title="Tab 3" groupTitle="Dropdown"}}
          tabcontent 3
      {{/bs-tab-pane}}
      {{#bs-tab-pane title="Tab 4" groupTitle="Dropdown"}}
          tabcontent 4
      {{/bs-tab-pane}}
    {{/bs-tab}}
  `);

  assert.equal(this.$('ul.nav.nav-tabs').length, 1, 'has tabs navigation');
  assert.equal(this.$('ul.nav.nav-tabs > li').length, 3, 'has tabs navigation items');
  assert.equal(this.$('ul.nav.nav-tabs > li:eq(0) > a').text().trim(), 'Tab 1', 'navigation item shows pane title');
  assert.equal(this.$('ul.nav.nav-tabs > li:eq(1) > a').text().trim(), 'Tab 2', 'navigation item shows pane title');
  assert.equal(this.$('ul.nav.nav-tabs > li:eq(2)').hasClass('dropdown'), true, 'adds dropdown for grouped items');
  assert.equal(this.$('ul.nav.nav-tabs > li:eq(2) > a').text().trim(), 'Dropdown', 'drop down item shows pane groupTitle');
{'fraction_non_alphanumeric': 0.21150253536162264, 'fraction_numerical': 0.013610888710968775, 'mean_word_length': 3.3298671288272677, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '923295', 'n_tokens_mistral': 2840, 'n_tokens_neox': 2707, 'n_words': 561}