{"size": 2092, "ext": "js", "max_stars_repo_path": "src/test/set-get-value.js", "max_stars_repo_name": "marconucara/custom-select", "max_stars_repo_stars_event_min_datetime": "2016-09-12T14:22:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-05T12:58:28.000Z", "max_issues_repo_path": "src/test/set-get-value.js", "max_issues_repo_name": "marconucara/custom-select", "max_issues_repo_issues_event_min_datetime": "2016-09-07T14:11:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-06T19:00:26.000Z", "max_forks_repo_path": "src/test/set-get-value.js", "max_forks_repo_name": "marconucara/custom-select", "max_forks_repo_forks_event_min_datetime": "2016-09-14T10:49:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-29T10:31:19.000Z"}
{"max_stars_count": 90, "max_issues_count": 29, "max_forks_count": 14, "avg_line_length": 26.15, "max_line_length": 91, "alphanum_fraction": 0.6754302103}
import test from 'tape';
import customSelect from './../';

var select;
var cstSelect;
var eventMessage;

test('With the public property set the value', assert => {
  document.body.innerHTML = '';

  select = document.createElement('select');
  select.innerHTML = `
    <option value="fruit">mango</option>
    <option value="flower">rose</option>
    <option value="fruit">pineapple</option>
    <option value="flower">lotus</option>
    <option value="flower">lily</option>
  `;
  document.body.appendChild(select);

  cstSelect = customSelect('select');

  // Adds the change event on the select for the next test
  select.addEventListener('change',
    () => { eventMessage = 'Select has changed it\'s value'; });

  cstSelect[0].value = 'flower';

  const actual = select.value;
  const expected = 'flower';

  assert.deepEqual(actual, expected,
    'should return flower');
  assert.end();
});

test('... and, like the native select, doesn\'t dispatch the change event', assert => {
  assert.notEqual(eventMessage, 'Select has changed it\'s value',
    'Select has changed it\'s value');
  assert.end();
});

test('... and use public property to get the value', assert => {
  const actual = cstSelect[0].value;
  const expected = 'flower';

  assert.deepEqual(actual, expected,
    'should return flower');
  assert.end();
});

test('... and checks that the correct custom option is selected', assert => {
  const actual = select.options[1].customSelectCstOption.classList.contains('is-selected');
  const expected = true;

  assert.deepEqual(actual, expected,
    'should return true');
  assert.end();
});

test('... and only one option is selected ', assert => {
  const actual = document.querySelectorAll('.is-selected').length;
  const expected = 1;

  assert.deepEqual(actual, expected,
    'should return 1');
  assert.end();
});

test('With the public property set an unexisting value', assert => {
  cstSelect[0].value = 'random';

  const actual = select.value;
  const expected = 'fruit';

  assert.deepEqual(actual, expected,
    'should return fruit');
  assert.end();
});
