Dotclear

Changeset 2200:0b1f90d5bb2a


Ignore:
Timestamp:
10/02/13 12:05:46 (12 years ago)
Author:
Nicolas <nikrou77@…>
Branch:
default
Message:

Allow checkboxesHelpers to manage checkboxes added dynamically
Add jasmine tests

Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • admin/js/common.js

    r2187 r2200  
    280280          $(e).append(document.createTextNode(' ')); 
    281281 
    282           target = target || $(e).parents('form').find('input[type="checkbox"]'); 
    283            
    284           var a = document.createElement('a'); 
    285           a.href='#'; 
    286           $(a).append(document.createTextNode(dotclear.msg.select_all)); 
    287           a.onclick = function() { 
     282          $('<a href="#">'+dotclear.msg.select_all+'</a>').click(function() { 
     283               if (target === undefined) { 
     284                    target = $(e).parents('form').find('input[type="checkbox"]'); 
     285               } 
    288286               target.check(); 
    289287               return false; 
    290           }; 
    291           $(e).append(a); 
    292  
     288          }).appendTo($(e)); 
    293289          $(e).append(document.createTextNode(' | ')); 
    294290 
    295           a = document.createElement('a'); 
    296           a.href='#'; 
    297           $(a).append(document.createTextNode(dotclear.msg.no_selection)); 
    298           a.onclick = function() { 
     291          $('<a href="#">'+dotclear.msg.no_selection+'</a>').click(function() { 
     292               if (target === undefined) { 
     293                    target = $(e).parents('form').find('input[type="checkbox"]'); 
     294               } 
    299295               target.unCheck(); 
    300296               return false; 
    301           }; 
    302           $(e).append(a); 
    303  
     297          }).appendTo($(e)); 
    304298          $(e).append(document.createTextNode(' - ')); 
    305299 
    306           a = document.createElement('a'); 
    307           a.href='#'; 
    308           $(a).append(document.createTextNode(dotclear.msg.invert_sel)); 
    309           a.onclick = function() { 
     300          $('<a href="#">'+dotclear.msg.invert_sel+'</a>').click(function() { 
     301               if (target === undefined) { 
     302                    target = $(e).parents('form').find('input[type="checkbox"]'); 
     303               } 
    310304               target.toggleCheck(); 
    311305               return false; 
    312           }; 
    313           $(e).append(a); 
     306          }).appendTo($(e)); 
    314307     }, 
    315308 
  • tests/functional/js/fix_include.js

    r1724 r2200  
    2020dotclear.msg.enhanced_uploader_disable = 'Temporarily disable enhanced uploader'; 
    2121 
     22dotclear.msg.to_select = 'Select:'; 
     23dotclear.msg.select_all = 'select all'; 
     24dotclear.msg.no_selection = 'no selection'; 
     25dotclear.msg.invert_sel = 'invert selection'; 
  • tests/functional/spec/common.js

    r1724 r2200  
    8181          }); 
    8282     }); 
     83 
     84     describe("checkboxesHelpers", function() { 
     85          it("Must add links to select all,none or invert selection", function() { 
     86               loadFixtures('entries_list.html'); 
     87               dotclear.checkboxesHelpers($('.checkboxes-helpers', '#form-entries')); 
     88 
     89               expect($('.checkboxes-helpers a', '#form-entries').length).toBe(3); 
     90               expect($('.checkboxes-helpers a:eq(0)', '#form-entries').text()).toBe(dotclear.msg.select_all); 
     91               expect($('.checkboxes-helpers a:eq(1)', '#form-entries').text()).toBe(dotclear.msg.no_selection); 
     92               expect($('.checkboxes-helpers a:eq(2)', '#form-entries').text()).toBe(dotclear.msg.invert_sel); 
     93          }); 
     94 
     95          it("Click all must select all checkboxes", function() { 
     96               loadFixtures('entries_list.html'); 
     97               dotclear.checkboxesHelpers($('.checkboxes-helpers', '#form-entries')); 
     98                
     99               $('.checkboxes-helpers a:eq(0)').click(); 
     100               expect($('#form-entries input[name="entries[]"]:checked').length).toBe(4); 
     101          }); 
     102 
     103          it("Click 'no selection'  must uncheck all checkboxes", function() { 
     104               loadFixtures('entries_list.html'); 
     105               dotclear.checkboxesHelpers($('.checkboxes-helpers', '#form-entries')); 
     106 
     107               $('input[name="entries[]"]:eq(1)').click(); 
     108               $('input[name="entries[]"]:eq(3)').click(); 
     109               $('.checkboxes-helpers a:eq(1)').click(); 
     110               expect($('#form-entries input[name="entries[]"]:checked').length).toBe(0); 
     111          }); 
     112 
     113          it("Click invert must select all uncheck checkboxes", function() { 
     114               loadFixtures('entries_list.html'); 
     115               dotclear.checkboxesHelpers($('.checkboxes-helpers', '#form-entries')); 
     116                
     117               $('input[name="entries[]"]:eq(1)').click(); 
     118               $('.checkboxes-helpers a:eq(2)').click(); 
     119               expect($('#form-entries input[name="entries[]"]:checked').length).toBe(3); 
     120               expect($('input[name="entries[]"]:eq(0)')).toBeChecked(); 
     121               expect($('input[name="entries[]"]:eq(1)')).not.toBeChecked(); 
     122               expect($('input[name="entries[]"]:eq(2)')).toBeChecked(); 
     123               expect($('input[name="entries[]"]:eq(3)')).toBeChecked(); 
     124          }); 
     125 
     126          it("Must take in consideration checkbox added dynamically", function() { 
     127               loadFixtures('entries_list.html'); 
     128               dotclear.checkboxesHelpers($('.checkboxes-helpers', '#form-entries')); 
     129 
     130               $('<li><input type="checkbox" name="entries[]" value="5"/><p>title 5</p></li>').appendTo('#form-entries ul'); 
     131 
     132               $('.checkboxes-helpers a:eq(0)').click(); 
     133               expect($('#form-entries input[name="entries[]"]:checked').length).toBe(5); 
     134          }); 
     135     }); 
    83136}); 
Note: See TracChangeset for help on using the changeset viewer.

Sites map