|
| 1 | +module('Selection containers - Inline search - Placeholder'); |
| 2 | + |
| 3 | +var MultipleSelection = require('select2/selection/multiple'); |
| 4 | +var InlineSearch = require('select2/selection/search'); |
| 5 | +var SelectionPlaceholder = require('select2/selection/placeholder'); |
| 6 | + |
| 7 | +var $ = require('jquery'); |
| 8 | +var Options = require('select2/options'); |
| 9 | +var Utils = require('select2/utils'); |
| 10 | + |
| 11 | +var CustomSelection = Utils.Decorate( |
| 12 | + Utils.Decorate(MultipleSelection, SelectionPlaceholder), |
| 13 | + InlineSearch |
| 14 | +); |
| 15 | + |
| 16 | +test('width does not extend the search box', function (assert) { |
| 17 | + assert.expect(2); |
| 18 | + |
| 19 | + var $container = $( |
| 20 | + '<div style="width: 100px; display: table-cell">' + |
| 21 | + '<div style="width: 100%" ' + |
| 22 | + 'class="select2-container select2-container--default"></div>' + |
| 23 | + '</div>' |
| 24 | + ); |
| 25 | + var container = new MockContainer(); |
| 26 | + |
| 27 | + var $element = $('#qunit-fixture .multiple'); |
| 28 | + var selection = new CustomSelection($element, new Options({ |
| 29 | + placeholder: 'Test placeholder' |
| 30 | + })); |
| 31 | + |
| 32 | + var $selection = selection.render(); |
| 33 | + selection.bind(container, $container); |
| 34 | + |
| 35 | + // Make it visible so the browser can place focus on the search |
| 36 | + $container.append($selection); |
| 37 | + $('#qunit-fixture').append($container); |
| 38 | + |
| 39 | + // Update the selection so the search is rendered |
| 40 | + selection.update([]); |
| 41 | + |
| 42 | + var $search = $selection.find('input'); |
| 43 | + |
| 44 | + assert.equal( |
| 45 | + $search.outerWidth(), |
| 46 | + 60, |
| 47 | + 'The search should not be the entire width of the container' |
| 48 | + ); |
| 49 | + |
| 50 | + assert.equal( |
| 51 | + $container.children().outerWidth(), |
| 52 | + 100, |
| 53 | + 'The container should be the width assigned to the parent in CSS' |
| 54 | + ); |
| 55 | + }); |
0 commit comments