HEX
Server: nginx/1.18.0
System: Linux test-ipsremont 5.4.0-214-generic #234-Ubuntu SMP Fri Mar 14 23:50:27 UTC 2025 x86_64
User: ips (1000)
PHP: 8.0.30
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/quadcode/frontend/node_modules/custom-select/src/test/set-get-value.js
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();
});