| [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 | |
|---|
| [2726] | 53 | spyOn(jQuery.pageTabs, 'getLocationHash').and.returnValue('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; |
|---|
| [2726] | 65 | spyOn(jQuery.fn, 'onetabload').and.callThrough(); |
|---|
| [2113] | 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 | |
|---|
| [2726] | 84 | spyOn(jQuery.fn, 'tabload').and.callThrough(); |
|---|
| [2113] | 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--; |
|---|
| [2726] | 126 | spyOn(jQuery.pageTabs, 'getLocationHash').and.returnValue(navigation[current_index]); |
|---|
| [2113] | 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 | }); |
|---|
| [2162] | 133 | |
|---|
| 134 | it("Must open first tab when clicking back until hash is empty", function() { |
|---|
| 135 | loadFixtures('tabs.html'); |
|---|
| 136 | loadStyleFixtures('default.css'); |
|---|
| 137 | |
|---|
| 138 | var navigation = ['', 'user-profile', 'user-favorites']; |
|---|
| 139 | var current_index = 0; |
|---|
| 140 | |
|---|
| 141 | $.pageTabs(); |
|---|
| 142 | current_index++; |
|---|
| 143 | $.pageTabs.clickTab(navigation[current_index]); |
|---|
| 144 | // tab is now user-profile |
|---|
| 145 | |
|---|
| 146 | // simulate back : window.history.back(); |
|---|
| 147 | current_index--; |
|---|
| [2726] | 148 | spyOn(jQuery.pageTabs, 'getLocationHash').and.returnValue(navigation[current_index]); |
|---|
| [2162] | 149 | jQuery.event.trigger('hashchange'); |
|---|
| 150 | |
|---|
| 151 | expect($('#part-user-options')).toBeVisible(); |
|---|
| 152 | expect($('#part-user-profile')).not.toBeVisible(); |
|---|
| 153 | expect($('#part-user-favorites')).not.toBeVisible(); |
|---|
| 154 | }); |
|---|
| [2479] | 155 | |
|---|
| 156 | /* ticket 1723 and 1794 |
|---|
| 157 | * |
|---|
| [2471] | 158 | * The problem occurs when cliking an anchor in the page |
|---|
| 159 | */ |
|---|
| [2479] | 160 | it("Must try to find tab to open in page when hash refer ton an anchor and not to an existing div content", function() { |
|---|
| [2471] | 161 | loadFixtures('tabs.html'); |
|---|
| 162 | loadStyleFixtures('default.css'); |
|---|
| 163 | |
|---|
| [2479] | 164 | var anchor_name = 'anchor-in-favorites'; |
|---|
| 165 | $('<div id="anchor-in-favorites"></div>').appendTo($('#user-favorites')); |
|---|
| 166 | |
|---|
| [2471] | 167 | $.pageTabs('user-profile'); |
|---|
| 168 | expect($('#part-user-options')).not.toBeVisible(); |
|---|
| 169 | expect($('#part-user-profile')).toBeVisible(); |
|---|
| 170 | expect($('#part-user-favorites')).not.toBeVisible(); |
|---|
| 171 | |
|---|
| [2726] | 172 | spyOn(jQuery.pageTabs, 'getLocationHash').and.returnValue(anchor_name); |
|---|
| [2471] | 173 | jQuery.event.trigger('hashchange'); |
|---|
| 174 | expect($('#part-user-options')).not.toBeVisible(); |
|---|
| [2479] | 175 | expect($('#part-user-profile')).not.toBeVisible(); |
|---|
| 176 | expect($('#part-user-favorites')).toBeVisible(); |
|---|
| [2471] | 177 | }); |
|---|
| 178 | |
|---|
| [2479] | 179 | it("Must open first tab when hash does not refer to an existing div content", function() { |
|---|
| [2348] | 180 | loadFixtures('tabs.html'); |
|---|
| 181 | loadStyleFixtures('default.css'); |
|---|
| 182 | |
|---|
| [2726] | 183 | spyOn(jQuery.pageTabs, 'getLocationHash').and.returnValue('dummy'); |
|---|
| [2348] | 184 | $.pageTabs(); |
|---|
| 185 | expect($('#part-user-options')).toBeVisible(); |
|---|
| 186 | expect($('#part-user-profile')).not.toBeVisible(); |
|---|
| 187 | expect($('#part-user-favorites')).not.toBeVisible(); |
|---|
| [2471] | 188 | }); |
|---|
| [2010] | 189 | }); |
|---|
| [1737] | 190 | |
|---|