|
| 1 | +module('Selection containers - Single'); |
| 2 | + |
| 3 | +var SingleSelection = require('select2/selection/single'); |
| 4 | + |
| 5 | +var $ = require('jquery'); |
| 6 | +var Options = require('select2/options'); |
| 7 | +var Utils = require('select2/utils'); |
| 8 | + |
| 9 | +var options = new Options({}); |
| 10 | + |
| 11 | +test('display uses templateSelection', function (assert) { |
| 12 | + var called = false; |
| 13 | + |
| 14 | + var templateOptions = new Options({ |
| 15 | + templateSelection: function (data) { |
| 16 | + called = true; |
| 17 | + |
| 18 | + return data.text; |
| 19 | + } |
| 20 | + }); |
| 21 | + |
| 22 | + var selection = new SingleSelection( |
| 23 | + $('#qunit-fixture .single'), |
| 24 | + templateOptions |
| 25 | + ); |
| 26 | + |
| 27 | + var out = selection.display({ |
| 28 | + text: 'test' |
| 29 | + }); |
| 30 | + |
| 31 | + assert.ok(called); |
| 32 | + |
| 33 | + assert.equal(out, 'test'); |
| 34 | +}); |
| 35 | + |
| 36 | +test('empty update clears the selection', function (assert) { |
| 37 | + var selection = new SingleSelection( |
| 38 | + $('#qunit-fixture .single'), |
| 39 | + options |
| 40 | + ); |
| 41 | + |
| 42 | + var $selection = selection.render(); |
| 43 | + var $rendered = $selection.find('.select2-selection__rendered'); |
| 44 | + |
| 45 | + $rendered.text('testing'); |
| 46 | + |
| 47 | + selection.update([]); |
| 48 | + |
| 49 | + assert.equal($rendered.text(), ''); |
| 50 | +}); |
| 51 | + |
| 52 | +test('update renders the data text', function (assert) { |
| 53 | + var selection = new SingleSelection( |
| 54 | + $('#qunit-fixture .single'), |
| 55 | + options |
| 56 | + ); |
| 57 | + |
| 58 | + var $selection = selection.render(); |
| 59 | + var $rendered = $selection.find('.select2-selection__rendered'); |
| 60 | + |
| 61 | + selection.update([{ |
| 62 | + text: 'test' |
| 63 | + }]); |
| 64 | + |
| 65 | + assert.equal($rendered.text(), 'test'); |
| 66 | +}); |
0 commit comments