describe("with search", function() {
var $multiselect,
$multiselect_to;
beforeEach(function() {
var html = '
'+
'
'+
' '+
'
'+
' '+
'
'+
' '+
' '+
' '+
' '+
'
'+
' '+
'
'+
' '+
'
'+
'
';
jasmine.getFixtures().set(html);
$multiselect = $('#search').multiselect({
search: {
left: '',
right: '',
},
fireSearch: function(value) {
return value.length > 3;
}
});
$multiselect_to = $('#search_to');
});
it("multiselect is instantiated and contains options", function() {
expect($multiselect.attr('id')).toBe('search');
expect($multiselect.find('option').length).toBe(5);
expect($multiselect_to.attr('id')).toBe('search_to');
expect($multiselect_to.find('option').length).toBe(0);
});
it("move all to right", function() {
// Click move all to right
$('#search_rightAll').trigger('click');
expect($multiselect.find('option').length).toBe(0);
expect($multiselect_to.find('option').length).toBe(5);
});
it("move one to right", function() {
$multiselect.find('option:eq(0)').attr('selected', true);
// Click move selected to right
$('#search_rightSelected').trigger('click');
expect($multiselect.find('option').length).toBe(4);
expect($multiselect_to.find('option').length).toBe(1);
});
it("move all selected to right", function() {
$multiselect.find('option:nth-child(2n)').attr('selected', true);
// Click move selected to right
$('#search_rightSelected').trigger('click');
expect($multiselect.find('option').length).toBe(3);
expect($multiselect_to.find('option').length).toBe(2);
});
it("move all to left", function() {
// Click move all to right
$('#search_rightAll').trigger('click');
// Click move all to left
$('#search_leftAll').trigger('click');
expect($multiselect.find('option').length).toBe(5);
expect($multiselect_to.find('option').length).toBe(0);
});
it("move one to left", function() {
// Click move all to right
$('#search_rightAll').trigger('click');
$multiselect_to.find('option:eq(0)').attr('selected', true);
// Click move selected to right
$('#search_leftSelected').trigger('click');
expect($multiselect.find('option').length).toBe(1);
expect($multiselect_to.find('option').length).toBe(4);
});
it("move all selected to left", function() {
// Click move all to right
$('#search_rightAll').trigger('click');
$multiselect_to.find('option:nth-child(2n)').attr('selected', true);
// Click move selected to right
$('#search_leftSelected').trigger('click');
expect($multiselect.find('option').length).toBe(2);
expect($multiselect_to.find('option').length).toBe(3);
});
it("search on the left side", function() {
// Search for "Item 1"
$('#search').prev('[name="q"]').val('Item 1').trigger('keyup');
expect($multiselect.find('option:visible').length).toBe(1);
// Search for "Item"
$('#search').prev('[name="q"]').val('Item').trigger('keyup');
expect($multiselect.find('option:visible').length).toBe(5);
});
it("search on the right side", function() {
// Click move all to right
$('#search_rightAll').trigger('click');
// Search for "Item 1"
$('#search_to').prev('[name="q"]').val('Item 1').trigger('keyup');
expect($multiselect_to.find('option:visible').length).toBe(1);
// Search for "Item"
$('#search_to').prev('[name="q"]').val('Item').trigger('keyup');
expect($multiselect_to.find('option:visible').length).toBe(5);
});
});