diff options
author | Marvin Borner | 2018-07-13 19:06:45 +0200 |
---|---|---|
committer | Marvin Borner | 2018-07-13 19:06:45 +0200 |
commit | 6fcfb7c04d32e1c8b26a312295bf7ac3ec2d2ad7 (patch) | |
tree | dbc87ef16fa01d5d99116de283592b8fe5e02944 /public/bower_components/select2/tests/options | |
parent | dfd839f27146df0ad0494e11734fc7d310c70ebf (diff) |
Fixed many permissions and began admin interface
Diffstat (limited to 'public/bower_components/select2/tests/options')
5 files changed, 420 insertions, 0 deletions
diff --git a/public/bower_components/select2/tests/options/ajax-tests.js b/public/bower_components/select2/tests/options/ajax-tests.js new file mode 100644 index 0000000..7d8537a --- /dev/null +++ b/public/bower_components/select2/tests/options/ajax-tests.js @@ -0,0 +1,32 @@ +module('Defaults - Ajax'); + +test('options are merged recursively with default options', function (assert) { + var defaults = require('select2/defaults'); + + var ajaxDelay = 250; + var ajaxUrl = 'http://www.test.com'; + + var mergedOptions; + + defaults.set('ajax--delay', ajaxDelay); + + mergedOptions = defaults.apply({ + ajax: { + url: ajaxUrl + } + }); + + assert.equal( + mergedOptions.ajax.delay, + ajaxDelay, + 'Ajax default options are present on the merged options' + ); + + assert.equal( + mergedOptions.ajax.url, + ajaxUrl, + 'Ajax provided options are present on the merged options' + ); + + defaults.reset(); +});
\ No newline at end of file diff --git a/public/bower_components/select2/tests/options/data-tests.js b/public/bower_components/select2/tests/options/data-tests.js new file mode 100644 index 0000000..107a2f0 --- /dev/null +++ b/public/bower_components/select2/tests/options/data-tests.js @@ -0,0 +1,44 @@ +module('Options - Attributes'); + +var $ = require('jquery'); + +var Options = require('select2/options'); + +test('no nesting', function (assert) { + var $test = $('<select data-test="test"></select>'); + + var options = new Options({}, $test); + + assert.equal(options.get('test'), 'test'); +}); + +test('with nesting', function (assert) { + var $test = $('<select data-first--second="test"></select>'); + + if ($test[0].dataset == null) { + assert.ok( + true, + 'We can not run this test with jQuery 1.x if dataset is not implemented' + ); + + return; + } + + var options = new Options({}, $test); + + assert.ok(!(options.get('first-Second'))); + assert.equal(options.get('first').second, 'test'); +}); + +test('overrides initialized data', function (assert) { + var $test = $('<select data-override="yes" data-data="yes"></select>'); + + var options = new Options({ + options: 'yes', + override: 'no' + }, $test); + + assert.equal(options.get('options'), 'yes'); + assert.equal(options.get('override'), 'yes'); + assert.equal(options.get('data'), 'yes'); +}); diff --git a/public/bower_components/select2/tests/options/deprecated-tests.js b/public/bower_components/select2/tests/options/deprecated-tests.js new file mode 100644 index 0000000..a51bba3 --- /dev/null +++ b/public/bower_components/select2/tests/options/deprecated-tests.js @@ -0,0 +1,250 @@ +module('Options - Deprecated - initSelection'); + +var $ = require('jquery'); +var Options = require('select2/options'); + +test('converted into dataAdapter.current', function (assert) { + assert.expect(5); + + var $test = $('<select></select>'); + var called = false; + + var options = new Options({ + initSelection: function ($element, callback) { + called = true; + + callback([{ + id: '1', + text: '2' + }]); + } + }, $test); + + assert.ok(!called, 'initSelection should not have been called'); + + var DataAdapter = options.get('dataAdapter'); + var data = new DataAdapter($test, options); + + data.current(function (data) { + assert.equal( + data.length, + 1, + 'There should have only been one object selected' + ); + + var item = data[0]; + + assert.equal( + item.id, + '1', + 'The id should have been set by initSelection' + ); + + assert.equal( + item.text, + '2', + 'The text should have been set by initSelection' + ); + }); + + assert.ok(called, 'initSelection should have been called'); +}); + +test('single option converted to array automatically', function (assert) { + assert.expect(2); + + var $test = $('<select></select>'); + var called = false; + + var options = new Options({ + initSelection: function ($element, callback) { + called = true; + + callback({ + id: '1', + text: '2' + }); + } + }, $test); + + var DataAdapter = options.get('dataAdapter'); + var data = new DataAdapter($test, options); + + data.current(function (data) { + assert.ok( + $.isArray(data), + 'The data should have been converted to an array' + ); + }); + + assert.ok(called, 'initSelection should have been called'); +}); + +test('only called once', function (assert) { + assert.expect(8); + + var $test = $('<select><option value="3" selected>4</option></select>'); + var called = 0; + + var options = new Options({ + initSelection: function ($element, callback) { + called++; + + callback([{ + id: '1', + text: '2' + }]); + } + }, $test); + + var DataAdapter = options.get('dataAdapter'); + var data = new DataAdapter($test, options); + + data.current(function (data) { + assert.equal( + data.length, + 1, + 'There should have only been a single option' + ); + + var item = data[0]; + + assert.equal( + item.id, + '1', + 'The id should match the one given by initSelection' + ); + + assert.equal( + item.text, + '2', + 'The text should match the one given by initSelection' + ); + }); + + assert.equal( + called, + 1, + 'initSelection should have been called' + ); + + data.current(function (data) { + assert.equal( + data.length, + 1, + 'There should have only been a single option' + ); + + var item = data[0]; + + assert.equal( + item.id, + '3', + 'The id should match the value given in the DOM' + ); + + assert.equal( + item.text, + '4', + 'The text should match the text given in the DOM' + ); + }); + + assert.equal( + called, + 1, + 'initSelection should have only been called once' + ); +}); + +module('Options - Deprecated - query'); + +test('converted into dataAdapter.query automatically', function (assert) { + assert.expect(6); + + var $test = $('<select></select>'); + var called = false; + + var options = new Options({ + query: function (params) { + called = true; + + params.callback({ + results: [ + { + id: 'test', + text: params.term + } + ] + }); + } + }, $test); + + assert.ok(!called, 'The query option should not have been called'); + + var DataAdapter = options.get('dataAdapter'); + var data = new DataAdapter($test, options); + + data.query({ + term: 'term' + }, function (data) { + assert.ok( + 'results' in data, + 'It should have included the results key' + ); + + assert.equal( + data.results.length, + 1, + 'There should have only been a single result returned' + ); + + var item = data.results[0]; + + assert.equal( + item.id, + 'test', + 'The id should have been returned from the query function' + ); + + assert.equal( + item.text, + 'term', + 'The text should have matched the term that was passed in' + ); + }); + + assert.ok(called, 'The query function should have been called'); +}); + +module('Options - deprecated - data-ajax-url'); + +test('converted ajax-url to ajax--url automatically', function (assert) { + var $test = $('<select data-ajax-url="test://url"></select>'); + var options = new Options({}, $test); + + assert.ok( + options.get('ajax'), + 'The `ajax` key was automatically created' + ); + assert.equal( + options.get('ajax').url, + 'test://url', + 'The `url` property for the `ajax` option was filled in correctly' + ); +}); + +test('converted select2-tags to data/tags automatically', function (assert) { + var $test = $('<select data-select2-tags="original data"></select>'); + var options = new Options({}, $test); + + assert.ok( + options.get('tags'), + 'The `tags` key is automatically set to true' + ); + assert.equal( + options.get('data'), + 'original data', + 'The `data` key is created with the original data' + ); +}); diff --git a/public/bower_components/select2/tests/options/translation-tests.js b/public/bower_components/select2/tests/options/translation-tests.js new file mode 100644 index 0000000..ab433b6 --- /dev/null +++ b/public/bower_components/select2/tests/options/translation-tests.js @@ -0,0 +1,28 @@ +module('Options - Translations'); + +var $ = require('jquery'); +var Options = require('select2/options'); + +test('partial dictionaries can be passed', function (assert) { + var options = new Options({ + language: { + searching: function () { + return 'Something'; + } + } + }); + + var translations = options.get('translations'); + + assert.equal( + translations.get('searching')(), + 'Something', + 'The partial dictionary still overrides translations' + ); + + assert.equal( + translations.get('noResults')(), + 'No results found', + 'You can still get English translations for keys not passed in' + ); +}); diff --git a/public/bower_components/select2/tests/options/width-tests.js b/public/bower_components/select2/tests/options/width-tests.js new file mode 100644 index 0000000..e724034 --- /dev/null +++ b/public/bower_components/select2/tests/options/width-tests.js @@ -0,0 +1,66 @@ +module('Options - Width'); + +var $ = require('jquery'); + +var Select2 = require('select2/core'); +var select = new Select2($('<select></select>')); + +test('string passed as width', function (assert) { + var $test = $('<select></select>'); + + var width = select._resolveWidth($test, '80%'); + + assert.equal(width, '80%'); +}); + +test('width from style attribute', function (assert) { + var $test = $('<select style="width: 50%;"></selct>'); + + var width = select._resolveWidth($test, 'style'); + + assert.equal(width, '50%'); +}); + +test('width from style returns null if nothing is found', function (assert) { + var $test = $('<select></selct>'); + + var width = select._resolveWidth($test, 'style'); + + assert.equal(width, null); +}); + +test('width from computed element width', function (assert) { + var $style = $( + '<style type="text/css">.css-set-width { width: 500px; }</style>' + ); + var $test = $('<select class="css-set-width"></select>'); + + $('#qunit-fixture').append($style); + $('#qunit-fixture').append($test); + + var width = select._resolveWidth($test, 'element'); + + assert.equal(width, '500px'); +}); + +test('resolve gets the style if it is there', function (assert) { + var $test = $('<select style="width: 20%;"></selct>'); + + var width = select._resolveWidth($test, 'resolve'); + + assert.equal(width, '20%'); +}); + +test('resolve falls back to element if there is no style', function (assert) { + var $style = $( + '<style type="text/css">.css-set-width { width: 500px; }</style>' + ); + var $test = $('<select class="css-set-width"></select>'); + + $('#qunit-fixture').append($style); + $('#qunit-fixture').append($test); + + var width = select._resolveWidth($test, 'resolve'); + + assert.equal(width, '500px'); +}); |