From e08222ef158f7898784bdec604c71448d33e0453 Mon Sep 17 00:00:00 2001
From: Kevin Brown <kevin@kevin-brown.com>
Date: Mon, 23 Nov 2015 18:25:09 -0500
Subject: [PATCH] Tests for the inline search box

This adds tests for the following commits

https://github.com/select2/select2/commit/5f80c5d9f81f3c5398c3e6e3e84fd6c67c8873f1

https://github.com/select2/select2/commit/395e06aff52059f654aff47f03a26cad8955a092
---
 tests/selection/search-tests.js | 81 +++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)

diff --git a/tests/selection/search-tests.js b/tests/selection/search-tests.js
index 8b55dbff..677e9b7b 100644
--- a/tests/selection/search-tests.js
+++ b/tests/selection/search-tests.js
@@ -9,6 +9,87 @@ var Utils = require('select2/utils');
 
 var options = new Options({});
 
+test('backspace will remove a choice', function (assert) {
+  expect(3);
+
+  var KEYS = require('select2/keys');
+
+  var $container = $('#qunit-fixture .event-container');
+  var container = new MockContainer();
+
+  var CustomSelection = Utils.Decorate(MultipleSelection, InlineSearch);
+
+  var $element = $('#qunit-fixture .multiple');
+  var selection = new CustomSelection($element, options);
+
+  var $selection = selection.render();
+  selection.bind(container, $container);
+
+  // The unselect event should be triggered at some point
+  selection.on('unselect', function () {
+    assert.ok(true, 'A choice was unselected');
+  });
+
+  // Add some selections and render the search
+  selection.update([
+    {
+      id: '1',
+      text: 'One'
+    }
+  ]);
+
+  var $search = $selection.find('input');
+  var $choices = $selection.find('.select2-selection__choice');
+
+  assert.equal($search.length, 1, 'The search was visible');
+  assert.equal($choices.length, 1, 'The choice was rendered');
+
+  // Trigger the backspace on the search
+  var backspace = $.Event('keydown', {
+    which: KEYS.BACKSPACE
+  });
+  $search.trigger(backspace);
+});
+
+test('backspace will set the search text', function (assert) {
+  expect(3);
+
+  var KEYS = require('select2/keys');
+
+  var $container = $('#qunit-fixture .event-container');
+  var container = new MockContainer();
+
+  var CustomSelection = Utils.Decorate(MultipleSelection, InlineSearch);
+
+  var $element = $('#qunit-fixture .multiple');
+  var selection = new CustomSelection($element, options);
+
+  var $selection = selection.render();
+  selection.bind(container, $container);
+
+  // Add some selections and render the search
+  selection.update([
+    {
+      id: '1',
+      text: 'One'
+    }
+  ]);
+
+  var $search = $selection.find('input');
+  var $choices = $selection.find('.select2-selection__choice');
+
+  assert.equal($search.length, 1, 'The search was visible');
+  assert.equal($choices.length, 1, 'The choice was rendered');
+
+  // Trigger the backspace on the search
+  var backspace = $.Event('keydown', {
+    which: KEYS.BACKSPACE
+  });
+  $search.trigger(backspace);
+
+  assert.equal($search.val(), 'One', 'The search text was set');
+});
+
 test('updating selection does not shift the focus', function (assert) {
   // Check for IE 8, which triggers a false negative during testing
   if (window.attachEvent && !window.addEventListener) {