From 120672dce79b6862cb17a966af06e0617a404b58 Mon Sep 17 00:00:00 2001 From: Kevin Brown Date: Sun, 27 Mar 2016 18:37:27 -0400 Subject: [PATCH] Added tests for multiple tags and tokenizing This adds tests to ensure that 3b8cd2e36990e695e4cb4b966c8658e7ca1574dc will continue to work in the future. --- tests/data/tokenizer-tests.js | 50 ++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/tests/data/tokenizer-tests.js b/tests/data/tokenizer-tests.js index 76197547..011dca4c 100644 --- a/tests/data/tokenizer-tests.js +++ b/tests/data/tokenizer-tests.js @@ -25,7 +25,7 @@ test('triggers the select event', function (assert) { var container = new MockContainer(); container.dropdown = container.selection = {}; - + var $container = $('
'); var data = new TokenizedSelect($select, options); @@ -168,4 +168,52 @@ test('createTag returning null does not cut the term', function (assert) { }, function () { assert.ok(true, 'The callback should have succeeded'); }); +}); + +test('works with multiple tokens given', function (assert) { + expect(4); + + var SelectData = require('select2/data/select'); + var Tokenizer = require('select2/data/tokenizer'); + var Tags = require('select2/data/tags'); + + var Options = require('select2/options'); + var Utils = require('select2/utils'); + + var $ = require('jquery'); + + var TokenizedSelect = Utils.Decorate( + Utils.Decorate(SelectData, Tags), + Tokenizer + ); + var $select = $('#qunit-fixture .multiple'); + + var options = new Options({ + tags: true, + tokenSeparators: [','] + }); + + var container = new MockContainer(); + container.dropdown = container.selection = {}; + + var $container = $('
'); + + var data = new TokenizedSelect($select, options); + data.bind(container, $container); + + data.on('select', function () { + assert.ok(true, 'The select event should be triggered'); + }); + + data.query({ + term: 'first,second,third' + }, function () { + assert.ok(true, 'The callback should have succeeded'); + }); + + assert.equal( + $select.children('option').length, + 3, + 'The two new tags should have been created' + ); }); \ No newline at end of file