$(function (){ var $b = $('#builder'); QUnit.module('plugins-gui', { afterEach: function (){ $b.queryBuilder('destroy'); } } ); QUnit.test('bt-checkbox', function (assert){ $b.queryBuilder({ plugins: ['bt-checkbox'] , filters: [{ id: 'no-color', type: 'integer', input: 'checkbox', values: { 10: 'foo', 20: 'bar'} } , { id: 'one-color', type: 'integer', input: 'checkbox', values: { 1: 'one', 2: 'two', 3: 'three'} , color: 'primary'} , { id: 'multi-color', type: 'integer', input: 'radio', values: { 0: 'no', 1: 'yes', 2: 'perhaps'} , colors: { 0: 'danger', 1: 'success'} } ] , rules: { condition: 'AND', rules: [{ id: 'no-color', value: 10} , { id: 'one-color', value: [1, 2, 3] } , { id: 'multi-color', value: 2} ] } } ); assert.ok(_AN_Read_length('length', $('#builder_rule_0 .checkbox.checkbox-default')) == 2, 'Should have 2 checkboxes with default color'); assert.ok(_AN_Read_length('length', $('#builder_rule_1 .checkbox.checkbox-primary')) == 3, 'Should have 3 checkboxes with primary color'); assert.ok(_AN_Read_length('length', $('#builder_rule_2 .radio.radio-danger')) == 1 && _AN_Read_length('length', $('#builder_rule_2 .radio.radio-success')) == 1 && _AN_Read_length('length', $('#builder_rule_2 .radio.radio-default')) == 1, 'Should have 3 radios with danger, success and default colors'); } ); QUnit.test('chosen-selectpicker', function (assert){ $b.queryBuilder({ plugins: ['chosen-selectpicker'] , filters: basic_filters, rules: basic_rules} ); assert.ok(_AN_Read_length('length', $b.find('.chosen-single')) == 8, 'Should have initialized chosen on all filters and operators selectors'); } ); QUnit.test('bt-tooltip-errors', function (assert){ $b.queryBuilder({ plugins: ['bt-tooltip-errors'] , filters: basic_filters, rules: { condition: 'AND', rules: [{ id: 'id', operator: 'equal', value: ''} ] } } ); $b.queryBuilder('validate'); assert.equal($('#builder_group_0 .error-container').eq(0).data('bs-toggle'), 'tooltip', 'Should have added data-bs-toggle="tooltip" in the template'); assert.equal($('#builder_rule_0 .error-container').data('originalTitle'), 'Empty value', 'Error title should be "Empty value"'); } ); QUnit.test('filter-description', function (assert){ var filters = [{ id: 'name', type: 'string', description: 'Lorem Ipsum sit amet.'} , { id: 'age', type: 'integer', description: function (rule){ return 'Description of operator ' + rule.operator.type; } } ] ; var rules = { condition: 'AND', rules: [{ id: 'name', value: 'Mistic'} , { id: 'age', value: 25} ] } ; $b.queryBuilder({ plugins: { 'filter-description': { mode: 'inline'} } , filters: filters, rules: rules} ); assert.match($('#builder_rule_0 p.filter-description').html(), new RegExp('Lorem Ipsum sit amet.'), 'Paragraph should contain filter description'); assert.match($('#builder_rule_1 p.filter-description').html(), new RegExp('Description of operator equal'), 'Paragraph should contain filter description after function execution'); $b.queryBuilder('destroy'); $b.queryBuilder({ plugins: { 'filter-description': { mode: 'popover'} } , filters: filters, rules: rules} ); assert.ok($('#builder_rule_0 button.filter-description').data('bs-toggle') == 'popover', 'Rule should contain a new button enabled with Popover'); $b.queryBuilder('destroy'); $b.queryBuilder({ plugins: { 'filter-description': { mode: 'bootbox'} } , filters: filters, rules: rules} ); assert.ok($('#builder_rule_0 button.filter-description').data('bs-toggle') == 'bootbox', 'Rule should contain a new button enabled with Bootbox'); } ); QUnit.test('sortable', function (assert){ $b.queryBuilder({ filters: basic_filters, rules: basic_rules, plugins: ['sortable'] } ); assert.ok(_AN_Read_length('length', $b.find('.drag-handle')) > 0, 'Should add the drag handles'); $b.queryBuilder('destroy'); $b.queryBuilder({ plugins: { 'sortable': { disable_template: true } } , filters: basic_filters, rules: basic_rules} ); assert.ok(_AN_Read_length('length', $b.find('.drag-handle')) === 0, 'Should not have added the handles with disable_template=true'); } ); } );