Commit 08c7013e authored by David Stutz's avatar David Stutz

Some more tests for collapsible optgroups.

parent ed5ab6a4
...@@ -267,7 +267,7 @@ ...@@ -267,7 +267,7 @@
selected += label + delimiter; selected += label + delimiter;
}); });
return selected.substr(0, selected.length - 2); return selected.substr(0, selected.length - this.delimiterText.length);
} }
}, },
/** /**
...@@ -289,7 +289,7 @@ ...@@ -289,7 +289,7 @@
var label = ($(this).attr('label') !== undefined) ? $(this).attr('label') : $(this).text(); var label = ($(this).attr('label') !== undefined) ? $(this).attr('label') : $(this).text();
selected += label + delimiter; selected += label + delimiter;
}); });
return selected.substr(0, selected.length - 2); return selected.substr(0, selected.length - this.delimiterText.length);
} }
}, },
/** /**
...@@ -768,6 +768,9 @@ ...@@ -768,6 +768,9 @@
// Cannot use select or deselect here because it would call updateOptGroups again. // Cannot use select or deselect here because it would call updateOptGroups again.
this.options.onChange($options, checked); this.options.onChange($options, checked);
this.updateButtonText();
this.updateSelectAll();
}, this)); }, this));
} }
......
...@@ -294,6 +294,7 @@ describe('Bootstrap Multiselect "Clickable Optgroups"', function() { ...@@ -294,6 +294,7 @@ describe('Bootstrap Multiselect "Clickable Optgroups"', function() {
$select.multiselect({ $select.multiselect({
buttonContainer: '<div id="multiselect-container"></div>', buttonContainer: '<div id="multiselect-container"></div>',
enableClickableOptGroups: true, enableClickableOptGroups: true,
numberDisplayed: 10,
onChange: function(option, checked) { onChange: function(option, checked) {
fired++; fired++;
} }
...@@ -360,6 +361,42 @@ describe('Bootstrap Multiselect "Clickable Optgroups"', function() { ...@@ -360,6 +361,42 @@ describe('Bootstrap Multiselect "Clickable Optgroups"', function() {
}); });
}); });
it('Should update button text.', function() {
expect($('#multiselect option:selected').length).toBe(10);
expect(fired).toBe(0);
var i = 0;
$('#multiselect-container li.multiselect-group').each(function() {
if (i == 0) {
var text = ''
$('option:selected', $('#multiselect optgroup')[i]).each(function() {
text += $(this).text() + ', '
});
text = text.substr(0, text.length - 2);
expect($('#multiselect-container .multiselect-selected-text').text()).toBe(text);
$('label', $(this)).click()
}
else {
$('label', $(this)).click();
var text = ''
$('option:selected', $('#multiselect optgroup')[i]).each(function() {
text += $(this).text() + ', '
});
text = text.substr(0, text.length - 2);
expect($('#multiselect-container .multiselect-selected-text').text()).toBe(text);
$('label', $(this)).click();
}
i++;
});
});
afterEach(function() { afterEach(function() {
$('#multiselect').multiselect('destroy'); $('#multiselect').multiselect('destroy');
$('#multiselect').remove(); $('#multiselect').remove();
...@@ -569,10 +606,7 @@ describe('Bootstrap Multiselect "Clickable+Collapsible+SelectAll Optgroups"', fu ...@@ -569,10 +606,7 @@ describe('Bootstrap Multiselect "Clickable+Collapsible+SelectAll Optgroups"', fu
enableClickableOptGroups: true, enableClickableOptGroups: true,
enableCollapsibleOptGroups: true, enableCollapsibleOptGroups: true,
includeSelectAllOption: true, includeSelectAllOption: true,
selectAllValue: 'multiselect-all', selectAllValue: 'multiselect-all'
onChange: function(option, checked) {
fired++;
}
}); });
}); });
...@@ -581,12 +615,12 @@ describe('Bootstrap Multiselect "Clickable+Collapsible+SelectAll Optgroups"', fu ...@@ -581,12 +615,12 @@ describe('Bootstrap Multiselect "Clickable+Collapsible+SelectAll Optgroups"', fu
$('#multiselect-container li.multiselect-group .caret-container').click(); $('#multiselect-container li.multiselect-group .caret-container').click();
$('#multiselect-container input[value="multiselect-all"]').click(); $('#multiselect-container input[value="multiselect-all"]').click();
$groups = $('#multiselect-container li.multiselect-group'); var $groups = $('#multiselect-container li.multiselect-group');
$groups.each(function() { $groups.each(function() {
expect($(this).hasClass('active')).toBe(false); expect($(this).hasClass('active')).toBe(false);
}); });
$lis = $('#multiselect-container li:not(.multiselect-group)'); var $lis = $('#multiselect-container li:not(.multiselect-group)');
$lis.each(function() { $lis.each(function() {
expect($(this).hasClass('active')).toBe(true); expect($(this).hasClass('active')).toBe(true);
}); });
...@@ -596,12 +630,25 @@ describe('Bootstrap Multiselect "Clickable+Collapsible+SelectAll Optgroups"', fu ...@@ -596,12 +630,25 @@ describe('Bootstrap Multiselect "Clickable+Collapsible+SelectAll Optgroups"', fu
//$('#multiselect-container li.multiselect-group .caret-container').click(); //$('#multiselect-container li.multiselect-group .caret-container').click();
$('#multiselect-container input[value="multiselect-all"]').click(); $('#multiselect-container input[value="multiselect-all"]').click();
$lis = $('#multiselect-container li'); var $lis = $('#multiselect-container li');
$lis.each(function() { $lis.each(function() {
expect($('input', this).prop('checked')).toBe(true); expect($('input', this).prop('checked')).toBe(true);
}); });
}); });
it('Should automatically update select all.', function() {
var i = 0;
$('#multiselect-container li.multiselect-group').each(function() {
$('label', $(this)).click();
expect($('option:selected', $('#multiselect optgroup')[i]).length).toBe(10);
expect($('#multiselect option:selected').length).toBe((i + 1)*10);
i++;
});
expect($('#multiselect-container li input[value="multiselect-all"]').prop('checked')).toBe(true);
});
afterEach(function() { afterEach(function() {
$('#multiselect').multiselect('destroy'); $('#multiselect').multiselect('destroy');
$('#multiselect').remove(); $('#multiselect').remove();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment