[1737] | 1 | describe("tabs method (admin/js/pageTabs.js)", function() { |
---|
[2010] | 2 | it("Must construct tabs using div content", function() { |
---|
| 3 | loadFixtures('tabs.html'); |
---|
| 4 | loadStyleFixtures('default.css'); |
---|
| 5 | |
---|
| 6 | expect($('#user-options')).toBeVisible(); |
---|
| 7 | expect($('#user-profile')).toBeVisible(); |
---|
| 8 | expect($('#user-favorites')).toBeVisible(); |
---|
| 9 | expect($('.part-tabs')).not.toExist(); |
---|
| 10 | |
---|
[2054] | 11 | $.pageTabs('user-favorites'); |
---|
| 12 | expect($('#part-user-options')).not.toBeVisible(); |
---|
[2010] | 13 | expect($('#part-user-profile')).not.toBeVisible(); |
---|
[2054] | 14 | expect($('#part-user-favorites')).toBeVisible(); |
---|
[2010] | 15 | |
---|
| 16 | expect($('.part-tabs')).toExist(); |
---|
| 17 | expect($('.part-tabs ul li#part-tabs-user-options')).toExist(); |
---|
| 18 | expect($('.part-tabs ul li#part-tabs-user-profile')).toExist(); |
---|
| 19 | expect($('.part-tabs ul li#part-tabs-user-favorites')).toExist(); |
---|
[2054] | 20 | expect($('#part-tabs-user-favorites')).toHaveClass('part-tabs-active'); |
---|
[2010] | 21 | }); |
---|
| 22 | |
---|
| 23 | it("Must open first part if pageTabs called without argument", function() { |
---|
| 24 | loadFixtures('tabs.html'); |
---|
| 25 | loadStyleFixtures('default.css'); |
---|
| 26 | |
---|
| 27 | $.pageTabs(); |
---|
| 28 | expect($('#part-user-options')).toBeVisible(); |
---|
| 29 | expect($('#part-user-profile')).not.toBeVisible(); |
---|
| 30 | expect($('#part-user-favorites')).not.toBeVisible(); |
---|
| 31 | expect($('#part-tabs-user-options')).toHaveClass('part-tabs-active'); |
---|
| 32 | }); |
---|
| 33 | |
---|
| 34 | it("Must change visible part when clicking another tab", function() { |
---|
| 35 | loadFixtures('tabs.html'); |
---|
| 36 | loadStyleFixtures('default.css'); |
---|
[1737] | 37 | |
---|
[2010] | 38 | $.pageTabs('user-options'); |
---|
| 39 | expect($('#part-user-options')).toBeVisible(); |
---|
| 40 | expect($('#part-user-profile')).not.toBeVisible(); |
---|
| 41 | expect($('#part-user-favorites')).not.toBeVisible(); |
---|
| 42 | |
---|
[2113] | 43 | $.pageTabs.clickTab('user-profile'); |
---|
[2010] | 44 | expect($('#part-tabs-user-profile')).toHaveClass('part-tabs-active'); |
---|
| 45 | expect($('#part-user-options')).not.toBeVisible(); |
---|
| 46 | expect($('#part-user-profile')).toBeVisible(); |
---|
| 47 | }); |
---|
| 48 | |
---|
| 49 | it("Must change opened part if corresponding anchor is in url", function() { |
---|
[1737] | 50 | loadFixtures('tabs.html'); |
---|
[2010] | 51 | loadStyleFixtures('default.css'); |
---|
| 52 | |
---|
[2113] | 53 | spyOn(jQuery.pageTabs, 'getLocationHash').andReturn('user-favorites'); |
---|
[2010] | 54 | $.pageTabs(); |
---|
| 55 | expect($('#part-user-options')).not.toBeVisible(); |
---|
| 56 | expect($('#part-user-profile')).not.toBeVisible(); |
---|
| 57 | expect($('#part-user-favorites')).toBeVisible(); |
---|
[1737] | 58 | }); |
---|
[2113] | 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 | }); |
---|
[2010] | 133 | }); |
---|
[1737] | 134 | |
---|