Ver código fonte

Add tests for removing a selection when disabled

These tests should fail because a selection can be removed even
though the container is disabled. This is because the only thing
preventing selections from being removed was the CSS which hid the
remove buttons when the container was disabled.
Kevin Brown 9 anos atrás
pai
commit
7d8f86cbf8
1 arquivos alterados com 50 adições e 2 exclusões
  1. 50 2
      tests/selection/multiple-tests.js

+ 50 - 2
tests/selection/multiple-tests.js

@@ -50,7 +50,7 @@ test('templateSelection can addClass', function (assert) {
   );
 
   var $container = selection.selectionContainer();
-  
+
   var out = selection.display({
     text: 'test'
   }, $container);
@@ -58,7 +58,7 @@ test('templateSelection can addClass', function (assert) {
   assert.ok(called);
 
   assert.equal(out, 'test');
-  
+
   assert.ok($container.hasClass('testclass'));
 });
 
@@ -99,3 +99,51 @@ test('escapeMarkup is being used', function (assert) {
     'The text should be escaped by default to prevent injection'
   );
 });
+
+test('clear button respects the disabled state', function (assert) {
+  var options = new Options({
+    disabled: true
+  });
+
+  var $select = $('#qunit-fixture .multiple');
+
+  var container = new MockContainer();
+  var $container = $('<div></div>');
+
+  var selection = new MultipleSelection(
+    $select,
+    options
+  );
+
+  var $selection = selection.render();
+  $container.append($selection);
+
+  selection.bind(container, $container);
+
+  // Select an option
+  selection.update([{
+    text: 'Test'
+  }]);
+
+  var $rendered = $selection.find('.select2-selection__rendered');
+
+  var $pill = $rendered.find('.select2-selection__choice');
+
+  assert.equal($pill.length, 1, 'There should only be one selection');
+
+  var $remove = $pill.find('.select2-selection__choice__remove');
+
+  assert.equal(
+    $remove.length,
+    1,
+    'The remove icon is displayed for the selection'
+  );
+
+  // Set up the unselect handler
+  selection.on('unselect', function (params) {
+    assert.ok(false, 'The unselect handler should not be triggered');
+  });
+
+  // Trigger the handler for the remove icon
+  $remove.trigger('click');
+});