Dotclear


Ignore:
Timestamp:
09/27/13 16:18:17 (12 years ago)
Author:
Nicolas <nikrou77@…>
Branch:
default
Children:
2114:7f63aa8eeebf, 2134:b3b9847a5d45
Message:

Refactoring for jQuery pageTabs plugin
Navigation in history comes back (onhashchange)
Fix ie7-hashchange to not use $.browser
Fix use of trigger for onetabload and tabload events

Add tests for onhashchange
Add tests for onetabload and tabload event
(Tested on chrome, IE8 and firefox 24)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/functional/spec/page_tabs.js

    r2054 r2113  
    4141          expect($('#part-user-favorites')).not.toBeVisible(); 
    4242 
    43           $('.part-tabs ul li a[href="#user-profile"]').click(); 
     43          $.pageTabs.clickTab('user-profile'); 
    4444          expect($('#part-tabs-user-profile')).toHaveClass('part-tabs-active');       
    4545          expect($('#part-user-options')).not.toBeVisible(); 
     
    5151          loadStyleFixtures('default.css'); 
    5252 
    53           spyOn(jQuery, 'pageTabsGetHash').andReturn('user-favorites'); 
     53          spyOn(jQuery.pageTabs, 'getLocationHash').andReturn('user-favorites'); 
    5454          $.pageTabs(); 
    5555          expect($('#part-user-options')).not.toBeVisible(); 
     
    5757          expect($('#part-user-favorites')).toBeVisible();        
    5858     }); 
     59 
     60     it("Must trigger event onetabload only the first time the tab is loaded", function() { 
     61          loadFixtures('tabs.html'); 
     62          loadStyleFixtures('default.css'); 
     63 
     64          var user_option_count_call = user_profile_count_call = user_favorites_count_call = 0; 
     65          spyOn(jQuery.fn, 'onetabload').andCallThrough(); 
     66          $('#user-options').onetabload(function() {user_option_count_call++;}); 
     67          $('#user-profile').onetabload(function() {user_profile_count_call++;}); 
     68          $('#user-favorites').onetabload(function() {user_favorites_count_call++;}); 
     69 
     70          $.pageTabs('user-options'); 
     71          expect(jQuery.fn.onetabload).toHaveBeenCalled(); 
     72          $.pageTabs.clickTab('user-profile'); 
     73          $.pageTabs.clickTab('user-options'); 
     74 
     75          expect(user_option_count_call).toBe(1); 
     76          expect(user_profile_count_call).toBe(1); 
     77          expect(user_favorites_count_call).toBe(0); 
     78     }); 
     79 
     80     it("Must trigger event tabload every first time the tab is loaded", function() { 
     81          loadFixtures('tabs.html'); 
     82          loadStyleFixtures('default.css'); 
     83           
     84          spyOn(jQuery.fn, 'tabload').andCallThrough(); 
     85 
     86          var user_option_count_call = user_profile_count_call = user_favorites_count_call = 0; 
     87          $('#user-options').tabload(function() {user_option_count_call++;}); 
     88          $('#user-profile').tabload(function() {user_profile_count_call++;}); 
     89          $('#user-favorites').tabload(function() {user_favorites_count_call++;}); 
     90      
     91          $.pageTabs('user-options'); 
     92          $.pageTabs.clickTab('user-profile'); 
     93          $.pageTabs.clickTab('user-options'); 
     94 
     95          expect(user_option_count_call).toBe(2); 
     96          expect(user_profile_count_call).toBe(1); 
     97          expect(user_favorites_count_call).toBe(0); 
     98     }); 
     99 
     100     it("Must keeps history of navigation in tabs", function() { 
     101          loadFixtures('tabs.html'); 
     102          loadStyleFixtures('default.css'); 
     103 
     104          var navigation = ['user-options', 'user-profile', 'user-favorites']; 
     105          var current_index = 0; 
     106 
     107          $.pageTabs(navigation[current_index]); 
     108          current_index++; 
     109          expect($('#part-user-options')).toBeVisible(); 
     110          expect($('#part-user-profile')).not.toBeVisible(); 
     111          expect($('#part-user-favorites')).not.toBeVisible(); 
     112           
     113          $.pageTabs.clickTab(navigation[current_index]); 
     114          current_index++; 
     115          expect($('#part-user-options')).not.toBeVisible(); 
     116          expect($('#part-user-profile')).toBeVisible(); 
     117          expect($('#part-user-favorites')).not.toBeVisible(); 
     118 
     119          $.pageTabs.clickTab(navigation[current_index]); 
     120          expect($('#part-user-options')).not.toBeVisible(); 
     121          expect($('#part-user-profile')).not.toBeVisible(); 
     122          expect($('#part-user-favorites')).toBeVisible(); 
     123 
     124          // simulate back : window.history.back(); 
     125          current_index--; 
     126          spyOn(jQuery.pageTabs, 'getLocationHash').andReturn(navigation[current_index]); 
     127          jQuery.event.trigger('hashchange'); 
     128           
     129          expect($('#part-user-options')).not.toBeVisible(); 
     130          expect($('#part-user-profile')).toBeVisible(); 
     131          expect($('#part-user-favorites')).not.toBeVisible(); 
     132     }); 
    59133}); 
    60134 
Note: See TracChangeset for help on using the changeset viewer.

Sites map