{"size": 2926, "ext": "js", "max_stars_repo_path": "src/basic-list-box/test/basic-list-box.tests.js", "max_stars_repo_name": "Teino1978-Corp/Teino1978-Corp-basic-web-components", "max_stars_repo_stars_event_min_datetime": "2015-01-03T15:44:14.000Z", "max_stars_repo_stars_event_max_datetime": "2015-07-26T18:13:58.000Z", "max_issues_repo_path": "src/basic-list-box/test/basic-list-box.tests.js", "max_issues_repo_name": "Teino1978-Corp/Teino1978-Corp-basic-web-components", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/basic-list-box/test/basic-list-box.tests.js", "max_forks_repo_name": "Teino1978-Corp/Teino1978-Corp-basic-web-components", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 4, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 29.5555555556, "max_line_length": 84, "alphanum_fraction": 0.6503759398}
suite('basic-list-box', function() {

  var container = document.getElementById('container');

  teardown(function() {
    container.innerHTML = '';
    listBox = null;
  });

  test("new list box has empty items collection", function() {
    var listBox = document.createElement('basic-list-box');
    assert.equal(listBox.items.length, 0);
  });

  test("selectedItem initially null", function(done) {
    var listBox = createSampleListBox();
    Polymer.dom(container).appendChild(listBox);
    flush(function() {
      assert.isNull(listBox.selectedItem);
      assert.equal(listBox.selectedIndex, -1);
      done();
    });
  });

  test("setting selectingIndex also updates selectedItem", function(done) {
    var listBox = createSampleListBox();
    Polymer.dom(container).appendChild(listBox);
    flush(function() {
      listBox.selectedIndex = 2;
      assert.equal(listBox.selectedItem, Polymer.dom(listBox).children[2]);
      done();
    });
  });

  test("setting selectedItem also updates selectedIndex", function(done) {
    var listBox = createSampleListBox();
    Polymer.dom(container).appendChild(listBox);
    flush(function() {
      listBox.selectedItem = Polymer.dom(listBox).children[2];
      assert.equal(listBox.selectedIndex, 2);
      done();
    });
  });

  test("setting selectedItem also updates value", function(done) {
    var listBox = createSampleListBox();
    Polymer.dom(container).appendChild(listBox);
    flush(function() {
      assert.equal(listBox.value, '');
      listBox.selectedIndex = 2;
      assert.equal(listBox.value, 'Two');
      done();
    });
  });

  test("setting value updates selectedItem", function(done) {
    var listBox = createSampleListBox();
    Polymer.dom(container).appendChild(listBox);
    flush(function() {
      listBox.value = 'Two';
      assert.equal(listBox.selectedIndex, 2);
      done();
    });
  });

  test("can set selectedIndex in markup", function(done) {
    var html = '<basic-list-box selected-index="0"><span></span></basic-list-box>';
    Polymer.dom(container).innerHTML = html;
    flush(function() {
      var list = Polymer.dom(container).children[0];
      var span = Polymer.dom(list).children[0];
      assert.equal(list.selectedItem, span);
      done();
    });
  });

  test("changing selection raises the selected-item-changed event", function(done) {
    var listBox = createSampleListBox();
    Polymer.dom(container).appendChild(listBox);
    flush(function() {
      listBox.addEventListener('selected-item-changed', function() {
        done();
      });
      listBox.selectedIndex = 1;
    });
  });

});

function createSampleListBox() {
  var listBox = document.createElement('basic-list-box');
  var texts = ['Zero', 'One', 'Two'];
  texts.forEach(function(text) {
    var div = document.createElement('div');
    div.textContent = text;
    Polymer.dom(listBox).appendChild(div);
  });
  return listBox;
}