<commit_before><commit_msg>prepare test for remove method<commit_after>import test from 'tape';
import fullSelect from './../';

let actual;
let expected;

document.body.innerHTML = '';
const select = document.createElement('select');
select.innerHTML = `
  <option value="">Select...</option>
  <optgroup label="Moto">
    <option value="suzuki">Suzuki</option>
  </optgroup>
  <optgroup label="Auto">
    <option value="mercedes">Mercedes</option>
    <option value="audi">Audi</option>
  </optgroup>`;
document.body.appendChild(select);
const fullselect = fullSelect('select')[0];

test('Remove an option', assert => {
  var target = select.children[2].children[1]; // Audi option

  const removed = fullselect.remove(target);

  assert.test('... and the returned option is the same', q => {
    actual = removed;
    expected = target;
    q.deepEqual(actual, expected,
      'the two elements should be the same');
    q.end();
  });

  assert.test('... and the option is not in the select anymore', q => {
    actual = select.options.indexOf(removed);
    expected = '-1';
    q.deepEqual(actual, expected,
      'should be -1');
    q.end();
  });

  assert.test('... and the custom option is not in the panel anymore', q => {
    actual = fullselect.panel.querySelector(`[data-value="${removed.getAttribute('value')}"]`);
    expected = 0;
    q.deepEqual(actual.length, expected,
      'should be 0');
    q.end();
  });

  assert.test('... and the custom options are one less', q => {
    actual = fullselect.panel.querySelectorAll(fullselect.getOptions().optionClass);
    expected = 3;
    q.deepEqual(actual.length, expected,
      'should be 3');
    q.end();
  });
});

test('Remove an option group', assert => {
  var targetGroup = select.children[2].children[1]; // Audi option

  const removedGroup = fullselect.remove(targetGroup);

  assert.test('... and the returned option group is the same', q => {
    actual = removedGroup;
    expected = targetGroup;
    q.deepEqual(actual, expected,
      'the two elements should be the same');
    q.end();
  });

  assert.test('... and the option group is not in the select anymore', q => {
    actual = [].indexOf.call(select.getElementsByTagName('optgroup'),
      removedGroup.fullSelectOriginalOptgroup);
    expected = '-1';
    q.deepEqual(actual, expected,
      'should be -1');
    q.end();
  });

  assert.test('... and the custom option group is not in the panel anymore', q => {
    actual = [].indexOf.call(select.getElementsByTagName(fullselect.getOptions().optgroupClass),
      removedGroup.fullSelectOriginalOptgroup);
    expected = '-1';
    q.deepEqual(actual, expected,
      'should be -1');
    q.end();
  });
});
{'fraction_non_alphanumeric': 0.16111111111111112, 'fraction_numerical': 0.005555555555555556, 'mean_word_length': 3.4278688524590164, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 24, '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': '7177035', 'n_tokens_mistral': 815, 'n_tokens_neox': 810, 'n_words': 219}