breadcrumbSpec.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. /**
  2. * ownCloud
  3. *
  4. * @author Vincent Petry
  5. * @copyright 2014 Vincent Petry <pvince81@owncloud.com>
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  9. * License as published by the Free Software Foundation; either
  10. * version 3 of the License, or any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public
  18. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. describe('OCA.Files.BreadCrumb tests', function() {
  22. var BreadCrumb = OCA.Files.BreadCrumb;
  23. describe('Rendering', function() {
  24. var bc;
  25. beforeEach(function() {
  26. bc = new BreadCrumb({
  27. getCrumbUrl: function(part, index) {
  28. // for testing purposes
  29. return part.dir + '#' + index;
  30. }
  31. });
  32. });
  33. afterEach(function() {
  34. bc = null;
  35. });
  36. it('Renders its own container', function() {
  37. bc.render();
  38. expect(bc.$el.hasClass('breadcrumb')).toEqual(true);
  39. });
  40. it('Renders root by default', function() {
  41. var $crumbs;
  42. bc.render();
  43. $crumbs = bc.$el.find('.crumb');
  44. // menu and home
  45. expect($crumbs.length).toEqual(2);
  46. expect($crumbs.eq(0).find('a').hasClass('icon-more')).toEqual(true);
  47. expect($crumbs.eq(0).find('div.popovermenu').length).toEqual(1);
  48. expect($crumbs.eq(0).data('dir')).not.toBeDefined();
  49. expect($crumbs.eq(1).find('a').attr('href')).toEqual('/#1');
  50. expect($crumbs.eq(1).find('a').hasClass('icon-home')).toEqual(true);
  51. expect($crumbs.eq(1).data('dir')).toEqual('/');
  52. });
  53. it('Renders root when switching to root', function() {
  54. var $crumbs;
  55. bc.setDirectory('/somedir');
  56. bc.setDirectory('/');
  57. $crumbs = bc.$el.find('.crumb');
  58. expect($crumbs.length).toEqual(2);
  59. expect($crumbs.eq(1).data('dir')).toEqual('/');
  60. });
  61. it('Renders single path section', function() {
  62. var $crumbs;
  63. bc.setDirectory('/somedir');
  64. $crumbs = bc.$el.find('.crumb');
  65. expect($crumbs.length).toEqual(3);
  66. expect($crumbs.eq(0).find('a').hasClass('icon-more')).toEqual(true);
  67. expect($crumbs.eq(0).find('div.popovermenu').length).toEqual(1);
  68. expect($crumbs.eq(0).data('dir')).not.toBeDefined();
  69. expect($crumbs.eq(1).find('a').attr('href')).toEqual('/#1');
  70. expect($crumbs.eq(1).find('a').hasClass('icon-home')).toEqual(true);
  71. expect($crumbs.eq(1).data('dir')).toEqual('/');
  72. expect($crumbs.eq(2).find('a').attr('href')).toEqual('/somedir#2');
  73. expect($crumbs.eq(2).find('img').length).toEqual(0);
  74. expect($crumbs.eq(2).data('dir')).toEqual('/somedir');
  75. });
  76. it('Renders multiple path sections and special chars', function() {
  77. var $crumbs;
  78. bc.setDirectory('/somedir/with space/abc');
  79. $crumbs = bc.$el.find('.crumb');
  80. expect($crumbs.length).toEqual(5);
  81. expect($crumbs.eq(0).find('a').hasClass('icon-more')).toEqual(true);
  82. expect($crumbs.eq(0).find('div.popovermenu').length).toEqual(1);
  83. expect($crumbs.eq(0).data('dir')).not.toBeDefined();
  84. expect($crumbs.eq(1).find('a').attr('href')).toEqual('/#1');
  85. expect($crumbs.eq(1).find('a').hasClass('icon-home')).toEqual(true);
  86. expect($crumbs.eq(1).data('dir')).toEqual('/');
  87. expect($crumbs.eq(2).find('a').attr('href')).toEqual('/somedir#2');
  88. expect($crumbs.eq(2).find('img').length).toEqual(0);
  89. expect($crumbs.eq(2).data('dir')).toEqual('/somedir');
  90. expect($crumbs.eq(3).find('a').attr('href')).toEqual('/somedir/with space#3');
  91. expect($crumbs.eq(3).find('img').length).toEqual(0);
  92. expect($crumbs.eq(3).data('dir')).toEqual('/somedir/with space');
  93. expect($crumbs.eq(4).find('a').attr('href')).toEqual('/somedir/with space/abc#4');
  94. expect($crumbs.eq(4).find('img').length).toEqual(0);
  95. expect($crumbs.eq(4).data('dir')).toEqual('/somedir/with space/abc');
  96. });
  97. it('Renders backslashes as regular directory separator', function() {
  98. var $crumbs;
  99. bc.setDirectory('/somedir\\with/mixed\\separators');
  100. $crumbs = bc.$el.find('.crumb');
  101. expect($crumbs.length).toEqual(6);
  102. expect($crumbs.eq(0).find('a').hasClass('icon-more')).toEqual(true);
  103. expect($crumbs.eq(0).find('div.popovermenu').length).toEqual(1);
  104. expect($crumbs.eq(0).data('dir')).not.toBeDefined();
  105. expect($crumbs.eq(1).find('a').attr('href')).toEqual('/#1');
  106. expect($crumbs.eq(1).find('a').hasClass('icon-home')).toEqual(true);
  107. expect($crumbs.eq(1).data('dir')).toEqual('/');
  108. expect($crumbs.eq(2).find('a').attr('href')).toEqual('/somedir#2');
  109. expect($crumbs.eq(2).find('img').length).toEqual(0);
  110. expect($crumbs.eq(2).data('dir')).toEqual('/somedir');
  111. expect($crumbs.eq(3).find('a').attr('href')).toEqual('/somedir/with#3');
  112. expect($crumbs.eq(3).find('img').length).toEqual(0);
  113. expect($crumbs.eq(3).data('dir')).toEqual('/somedir/with');
  114. expect($crumbs.eq(4).find('a').attr('href')).toEqual('/somedir/with/mixed#4');
  115. expect($crumbs.eq(4).find('img').length).toEqual(0);
  116. expect($crumbs.eq(4).data('dir')).toEqual('/somedir/with/mixed');
  117. expect($crumbs.eq(5).find('a').attr('href')).toEqual('/somedir/with/mixed/separators#5');
  118. expect($crumbs.eq(5).find('img').length).toEqual(0);
  119. expect($crumbs.eq(5).data('dir')).toEqual('/somedir/with/mixed/separators');
  120. });
  121. });
  122. describe('Events', function() {
  123. it('Calls onClick handler when clicking on a crumb', function() {
  124. var handler = sinon.stub();
  125. var bc = new BreadCrumb({
  126. onClick: handler
  127. });
  128. bc.setDirectory('/one/two/three/four');
  129. // Click on crumb does not work, only link
  130. bc.$el.find('.crumb:eq(4)').click();
  131. expect(handler.calledOnce).toEqual(false);
  132. handler.reset();
  133. // Click on crumb link works
  134. bc.$el.find('.crumb:eq(1) a').click();
  135. expect(handler.calledOnce).toEqual(true);
  136. expect(handler.getCall(0).thisValue).toEqual(bc.$el.find('.crumb > a').get(1));
  137. });
  138. it('Calls onDrop handler when dropping on a crumb', function() {
  139. var droppableStub = sinon.stub($.fn, 'droppable');
  140. var handler = sinon.stub();
  141. var bc = new BreadCrumb({
  142. onDrop: handler
  143. });
  144. bc.setDirectory('/one/two/three/four');
  145. expect(droppableStub.calledOnce).toEqual(true);
  146. expect(droppableStub.getCall(0).args[0].drop).toBeDefined();
  147. // simulate drop
  148. droppableStub.getCall(0).args[0].drop({dummy: true});
  149. expect(handler.calledOnce).toEqual(true);
  150. expect(handler.getCall(0).args[0]).toEqual({dummy: true});
  151. droppableStub.restore();
  152. });
  153. });
  154. describe('Menu tests', function() {
  155. var bc, dummyDir, $crumbmenuLink, $popovermenu;
  156. beforeEach(function() {
  157. dummyDir = '/one/two/three/four/five'
  158. bc = new BreadCrumb();
  159. // append dummy navigation and controls
  160. // as they are currently used for measurements
  161. $('#testArea').append(
  162. '<div id="controls"></div>'
  163. );
  164. $('#controls').append(bc.$el);
  165. bc.setDirectory(dummyDir);
  166. $('div.crumb').each(function(index){
  167. $(this).css('width', 50);
  168. $(this).css('padding', 0);
  169. $(this).css('margin', 0);
  170. });
  171. $('div.crumbhome').css('width', 51);
  172. $('div.crumbmenu').css('width', 51);
  173. $('#controls').width(1000);
  174. bc._resize();
  175. // Shrink to show popovermenu
  176. $('#controls').width(300);
  177. bc._resize();
  178. $crumbmenuLink = bc.$el.find('.crumbmenu > a');
  179. $popovermenu = $crumbmenuLink.next('.popovermenu');
  180. });
  181. afterEach(function() {
  182. bc = null;
  183. });
  184. it('Opens and closes the menu on click', function() {
  185. // Menu exists
  186. expect($popovermenu.length).toEqual(1);
  187. // Disable jQuery delay
  188. jQuery.fx.off = true
  189. // Click on menu
  190. $crumbmenuLink.click();
  191. expect($popovermenu.is(':visible')).toEqual(true);
  192. // Click on home
  193. $(document).mouseup();
  194. expect($popovermenu.is(':visible')).toEqual(false);
  195. // Change directory and reset elements
  196. bc.setDirectory('/one/two/three/four/five/six/seven/eight/nine/ten');
  197. $crumbmenuLink = bc.$el.find('.crumbmenu > a');
  198. $popovermenu = $crumbmenuLink.next('.popovermenu');
  199. // Click on menu again
  200. $crumbmenuLink.click();
  201. expect($popovermenu.is(':visible')).toEqual(true);
  202. // Click on home again
  203. $(document).mouseup();
  204. expect($popovermenu.is(':visible')).toEqual(false);
  205. });
  206. it('Shows only items not in the breadcrumb', function() {
  207. var hiddenCrumbs = bc.$el.find('.crumb:not(.crumbmenu).hidden');
  208. expect($popovermenu.find('li:not(.in-breadcrumb)').length).toEqual(hiddenCrumbs.length);
  209. });
  210. });
  211. describe('Resizing', function() {
  212. var bc, dummyDir, widths, paddings, margins;
  213. // cit() will skip tests if running on PhantomJS because it does not
  214. // have proper support for flexboxes.
  215. var cit = window.isPhantom?xit:it;
  216. beforeEach(function() {
  217. dummyDir = '/short name/longer name/looooooooooooonger/' +
  218. 'even longer long long long longer long/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/last one';
  219. bc = new BreadCrumb();
  220. // append dummy navigation and controls
  221. // as they are currently used for measurements
  222. $('#testArea').append(
  223. '<div id="controls"></div>'
  224. );
  225. $('#controls').append(bc.$el);
  226. // triggers resize implicitly
  227. bc.setDirectory(dummyDir);
  228. // using hard-coded widths (pre-measured) to avoid getting different
  229. // results on different browsers due to font engine differences
  230. // 51px is default size for menu and home
  231. widths = [51, 51, 106, 112, 160, 257, 251, 91];
  232. // using hard-coded paddings and margins to avoid depending on the
  233. // current CSS values used in the server
  234. paddings = [0, 0, 0, 0, 0, 0, 0, 0];
  235. margins = [0, 0, 0, 0, 0, 0, 0, 0];
  236. $('div.crumb').each(function(index){
  237. $(this).css('width', widths[index]);
  238. $(this).css('padding', paddings[index]);
  239. $(this).css('margin', margins[index]);
  240. });
  241. });
  242. afterEach(function() {
  243. bc = null;
  244. });
  245. it('Hides breadcrumbs to fit available width', function() {
  246. var $crumbs;
  247. $('#controls').width(500);
  248. bc._resize();
  249. $crumbs = bc.$el.find('.crumb');
  250. // Second, third, fourth and fifth crumb are hidden and everything
  251. // else is visible
  252. expect($crumbs.eq(0).hasClass('hidden')).toEqual(false);
  253. expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);
  254. expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
  255. expect($crumbs.eq(3).hasClass('hidden')).toEqual(true);
  256. expect($crumbs.eq(4).hasClass('hidden')).toEqual(true);
  257. expect($crumbs.eq(5).hasClass('hidden')).toEqual(true);
  258. expect($crumbs.eq(6).hasClass('hidden')).toEqual(true);
  259. expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);
  260. });
  261. it('Hides breadcrumbs to fit available width', function() {
  262. var $crumbs;
  263. $('#controls').width(700);
  264. bc._resize();
  265. $crumbs = bc.$el.find('.crumb');
  266. // Third and fourth crumb are hidden and everything else is visible
  267. expect($crumbs.eq(0).hasClass('hidden')).toEqual(false);
  268. expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);
  269. expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
  270. expect($crumbs.eq(3).hasClass('hidden')).toEqual(false);
  271. expect($crumbs.eq(4).hasClass('hidden')).toEqual(true);
  272. expect($crumbs.eq(5).hasClass('hidden')).toEqual(true);
  273. expect($crumbs.eq(6).hasClass('hidden')).toEqual(false);
  274. expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);
  275. });
  276. it('Hides breadcrumbs to fit available width taking paddings into account', function() {
  277. var $crumbs;
  278. // Each element is 20px wider
  279. paddings = [10, 10, 10, 10, 10, 10, 10, 10];
  280. $('div.crumb').each(function(index){
  281. $(this).css('padding', paddings[index]);
  282. });
  283. $('#controls').width(700);
  284. bc._resize();
  285. $crumbs = bc.$el.find('.crumb');
  286. // Second, third and fourth crumb are hidden and everything else is
  287. // visible
  288. expect($crumbs.eq(0).hasClass('hidden')).toEqual(false);
  289. expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);
  290. expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
  291. expect($crumbs.eq(3).hasClass('hidden')).toEqual(true);
  292. expect($crumbs.eq(4).hasClass('hidden')).toEqual(true);
  293. expect($crumbs.eq(5).hasClass('hidden')).toEqual(true);
  294. expect($crumbs.eq(6).hasClass('hidden')).toEqual(false);
  295. expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);
  296. });
  297. it('Hides breadcrumbs to fit available width taking margins into account', function() {
  298. var $crumbs;
  299. // Each element is 20px wider
  300. margins = [10, 10, 10, 10, 10, 10, 10, 10];
  301. $('div.crumb').each(function(index){
  302. $(this).css('margin', margins[index]);
  303. });
  304. $('#controls').width(700);
  305. bc._resize();
  306. $crumbs = bc.$el.find('.crumb');
  307. // Second, third and fourth crumb are hidden and everything else is
  308. // visible
  309. expect($crumbs.eq(0).hasClass('hidden')).toEqual(false);
  310. expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);
  311. expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
  312. expect($crumbs.eq(3).hasClass('hidden')).toEqual(true);
  313. expect($crumbs.eq(4).hasClass('hidden')).toEqual(true);
  314. expect($crumbs.eq(5).hasClass('hidden')).toEqual(true);
  315. expect($crumbs.eq(6).hasClass('hidden')).toEqual(false);
  316. expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);
  317. });
  318. it('Hides breadcrumbs to fit available width left by siblings', function() {
  319. var $crumbs;
  320. $('#controls').width(700);
  321. bc._resize();
  322. $crumbs = bc.$el.find('.crumb');
  323. // Third and fourth crumb are hidden and everything else is visible
  324. expect($crumbs.eq(0).hasClass('hidden')).toEqual(false);
  325. expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);
  326. expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
  327. expect($crumbs.eq(3).hasClass('hidden')).toEqual(false);
  328. expect($crumbs.eq(4).hasClass('hidden')).toEqual(true);
  329. expect($crumbs.eq(5).hasClass('hidden')).toEqual(true);
  330. expect($crumbs.eq(6).hasClass('hidden')).toEqual(false);
  331. expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);
  332. // Visible sibling widths add up to 200px
  333. var $previousSibling = $('<div class="otherSibling"></div>');
  334. // Set both the width and the min-width to even differences in width
  335. // handling in the browsers used to run the tests.
  336. $previousSibling.css('width', '50px');
  337. $previousSibling.css('min-width', '50px');
  338. $('#controls').prepend($previousSibling);
  339. var $creatableActions = $('<div class="actions creatable"></div>');
  340. // Set both the width and the min-width to even differences in width
  341. // handling in the browsers used to run the tests.
  342. $creatableActions.css('width', '100px');
  343. $creatableActions.css('min-width', '100px');
  344. $('#controls').append($creatableActions);
  345. var $nextHiddenSibling = $('<div class="otherSibling hidden"></div>');
  346. // Set both the width and the min-width to even differences in width
  347. // handling in the browsers used to run the tests.
  348. $nextHiddenSibling.css('width', '200px');
  349. $nextHiddenSibling.css('min-width', '200px');
  350. $('#controls').append($nextHiddenSibling);
  351. var $nextSibling = $('<div class="otherSibling"></div>');
  352. // Set both the width and the min-width to even differences in width
  353. // handling in the browsers used to run the tests.
  354. $nextSibling.css('width', '50px');
  355. $nextSibling.css('min-width', '50px');
  356. $('#controls').append($nextSibling);
  357. bc._resize();
  358. // Second, third, fourth and fifth crumb are hidden and everything
  359. // else is visible
  360. expect($crumbs.eq(0).hasClass('hidden')).toEqual(false);
  361. expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);
  362. expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
  363. expect($crumbs.eq(3).hasClass('hidden')).toEqual(true);
  364. expect($crumbs.eq(4).hasClass('hidden')).toEqual(true);
  365. expect($crumbs.eq(5).hasClass('hidden')).toEqual(true);
  366. expect($crumbs.eq(6).hasClass('hidden')).toEqual(true);
  367. expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);
  368. });
  369. it('Hides breadcrumbs to fit available width left by siblings with paddings and margins', function() {
  370. var $crumbs;
  371. $('#controls').width(700);
  372. bc._resize();
  373. $crumbs = bc.$el.find('.crumb');
  374. // Third and fourth crumb are hidden and everything else is visible
  375. expect($crumbs.eq(0).hasClass('hidden')).toEqual(false);
  376. expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);
  377. expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
  378. expect($crumbs.eq(3).hasClass('hidden')).toEqual(false);
  379. expect($crumbs.eq(4).hasClass('hidden')).toEqual(true);
  380. expect($crumbs.eq(5).hasClass('hidden')).toEqual(true);
  381. expect($crumbs.eq(6).hasClass('hidden')).toEqual(false);
  382. expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);
  383. // Visible sibling widths add up to 200px
  384. var $previousSibling = $('<div class="otherSibling"></div>');
  385. // Set both the width and the min-width to even differences in width
  386. // handling in the browsers used to run the tests.
  387. $previousSibling.css('width', '10px');
  388. $previousSibling.css('min-width', '10px');
  389. $previousSibling.css('margin', '20px');
  390. $('#controls').prepend($previousSibling);
  391. var $creatableActions = $('<div class="actions creatable"></div>');
  392. // Set both the width and the min-width to even differences in width
  393. // handling in the browsers used to run the tests.
  394. $creatableActions.css('width', '20px');
  395. $creatableActions.css('min-width', '20px');
  396. $creatableActions.css('margin-left', '40px');
  397. $creatableActions.css('padding-right', '40px');
  398. $('#controls').append($creatableActions);
  399. var $nextHiddenSibling = $('<div class="otherSibling hidden"></div>');
  400. // Set both the width and the min-width to even differences in width
  401. // handling in the browsers used to run the tests.
  402. $nextHiddenSibling.css('width', '200px');
  403. $nextHiddenSibling.css('min-width', '200px');
  404. $('#controls').append($nextHiddenSibling);
  405. var $nextSibling = $('<div class="otherSibling"></div>');
  406. // Set both the width and the min-width to even differences in width
  407. // handling in the browsers used to run the tests.
  408. $nextSibling.css('width', '10px');
  409. $nextSibling.css('min-width', '10px');
  410. $nextSibling.css('padding', '20px');
  411. $('#controls').append($nextSibling);
  412. bc._resize();
  413. // Second, third, fourth and fifth crumb are hidden and everything
  414. // else is visible
  415. expect($crumbs.eq(0).hasClass('hidden')).toEqual(false);
  416. expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);
  417. expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
  418. expect($crumbs.eq(3).hasClass('hidden')).toEqual(true);
  419. expect($crumbs.eq(4).hasClass('hidden')).toEqual(true);
  420. expect($crumbs.eq(5).hasClass('hidden')).toEqual(true);
  421. expect($crumbs.eq(6).hasClass('hidden')).toEqual(true);
  422. expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);
  423. });
  424. it('Updates the breadcrumbs when reducing available width', function() {
  425. var $crumbs;
  426. // enough space
  427. $('#controls').width(1800);
  428. bc._resize();
  429. $crumbs = bc.$el.find('.crumb');
  430. // Menu is hidden
  431. expect($crumbs.eq(0).hasClass('hidden')).toEqual(true);
  432. // simulate decrease
  433. $('#controls').width(950);
  434. bc._resize();
  435. // Third crumb is hidden and everything else is visible
  436. expect($crumbs.eq(0).hasClass('hidden')).toEqual(false);
  437. expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);
  438. expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
  439. expect($crumbs.eq(3).hasClass('hidden')).toEqual(false);
  440. expect($crumbs.eq(4).hasClass('hidden')).toEqual(true);
  441. expect($crumbs.eq(5).hasClass('hidden')).toEqual(false);
  442. expect($crumbs.eq(6).hasClass('hidden')).toEqual(false);
  443. expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);
  444. });
  445. it('Updates the breadcrumbs when reducing available width taking into account the menu width', function() {
  446. var $crumbs;
  447. // enough space
  448. $('#controls').width(1800);
  449. bc._resize();
  450. $crumbs = bc.$el.find('.crumb');
  451. // Menu is hidden
  452. expect($crumbs.eq(0).hasClass('hidden')).toEqual(true);
  453. expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);
  454. expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
  455. expect($crumbs.eq(3).hasClass('hidden')).toEqual(false);
  456. expect($crumbs.eq(4).hasClass('hidden')).toEqual(false);
  457. expect($crumbs.eq(5).hasClass('hidden')).toEqual(false);
  458. expect($crumbs.eq(6).hasClass('hidden')).toEqual(false);
  459. expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);
  460. // simulate decrease
  461. // 650 is enough for all the crumbs except the third and fourth
  462. // ones, but not enough for the menu and all the crumbs except the
  463. // third and fourth ones; the second one has to be hidden too.
  464. $('#controls').width(650);
  465. bc._resize();
  466. // Second, third and fourth crumb are hidden and everything else is
  467. // visible
  468. expect($crumbs.eq(0).hasClass('hidden')).toEqual(false);
  469. expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);
  470. expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
  471. expect($crumbs.eq(3).hasClass('hidden')).toEqual(true);
  472. expect($crumbs.eq(4).hasClass('hidden')).toEqual(true);
  473. expect($crumbs.eq(5).hasClass('hidden')).toEqual(true);
  474. expect($crumbs.eq(6).hasClass('hidden')).toEqual(false);
  475. expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);
  476. });
  477. it('Updates the breadcrumbs when increasing available width', function() {
  478. var $crumbs;
  479. // limited space
  480. $('#controls').width(850);
  481. bc._resize();
  482. $crumbs = bc.$el.find('.crumb');
  483. // Third and fourth crumb are hidden and everything else is visible
  484. expect($crumbs.eq(0).hasClass('hidden')).toEqual(false);
  485. expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);
  486. expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
  487. expect($crumbs.eq(3).hasClass('hidden')).toEqual(false);
  488. expect($crumbs.eq(4).hasClass('hidden')).toEqual(true);
  489. expect($crumbs.eq(5).hasClass('hidden')).toEqual(true);
  490. expect($crumbs.eq(6).hasClass('hidden')).toEqual(false);
  491. expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);
  492. // simulate increase
  493. $('#controls').width(1000);
  494. bc._resize();
  495. // Third crumb is hidden and everything else is visible
  496. expect($crumbs.eq(0).hasClass('hidden')).toEqual(false);
  497. expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);
  498. expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
  499. expect($crumbs.eq(3).hasClass('hidden')).toEqual(false);
  500. expect($crumbs.eq(4).hasClass('hidden')).toEqual(true);
  501. expect($crumbs.eq(5).hasClass('hidden')).toEqual(false);
  502. expect($crumbs.eq(6).hasClass('hidden')).toEqual(false);
  503. expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);
  504. });
  505. it('Updates the breadcrumbs when increasing available width taking into account the menu width', function() {
  506. var $crumbs;
  507. // limited space
  508. $('#controls').width(850);
  509. bc._resize();
  510. $crumbs = bc.$el.find('.crumb');
  511. // Third and fourth crumb are hidden and everything else is visible
  512. expect($crumbs.eq(0).hasClass('hidden')).toEqual(false);
  513. expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);
  514. expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
  515. expect($crumbs.eq(3).hasClass('hidden')).toEqual(false);
  516. expect($crumbs.eq(4).hasClass('hidden')).toEqual(true);
  517. expect($crumbs.eq(5).hasClass('hidden')).toEqual(true);
  518. expect($crumbs.eq(6).hasClass('hidden')).toEqual(false);
  519. expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);
  520. // simulate increase
  521. // 1030 is enough for all the crumbs if the menu is hidden.
  522. $('#controls').width(1030);
  523. bc._resize();
  524. // Menu is hidden and everything else is visible
  525. expect($crumbs.eq(0).hasClass('hidden')).toEqual(true);
  526. expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);
  527. expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
  528. expect($crumbs.eq(3).hasClass('hidden')).toEqual(false);
  529. expect($crumbs.eq(4).hasClass('hidden')).toEqual(false);
  530. expect($crumbs.eq(5).hasClass('hidden')).toEqual(false);
  531. expect($crumbs.eq(6).hasClass('hidden')).toEqual(false);
  532. expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);
  533. });
  534. cit('Updates the breadcrumbs when increasing available width with an expanding sibling', function() {
  535. var $crumbs;
  536. // The sibling expands to fill all the width left by the breadcrumbs
  537. var $nextSibling = $('<div class="sibling"></div>');
  538. // Set both the width and the min-width to even differences in width
  539. // handling in the browsers used to run the tests.
  540. $nextSibling.css('width', '10px');
  541. $nextSibling.css('min-width', '10px');
  542. $nextSibling.css('display', 'flex');
  543. $nextSibling.css('flex', '1 1');
  544. var $nextSiblingChild = $('<div class="siblingChild"></div>');
  545. $nextSiblingChild.css('margin-left', 'auto');
  546. $nextSibling.append($nextSiblingChild);
  547. $('#controls').append($nextSibling);
  548. // limited space
  549. $('#controls').width(850);
  550. bc._resize();
  551. $crumbs = bc.$el.find('.crumb');
  552. // Third and fourth crumb are hidden and everything else is visible
  553. expect($crumbs.eq(0).hasClass('hidden')).toEqual(false);
  554. expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);
  555. expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
  556. expect($crumbs.eq(3).hasClass('hidden')).toEqual(false);
  557. expect($crumbs.eq(4).hasClass('hidden')).toEqual(true);
  558. expect($crumbs.eq(5).hasClass('hidden')).toEqual(true);
  559. expect($crumbs.eq(6).hasClass('hidden')).toEqual(false);
  560. expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);
  561. // simulate increase
  562. $('#controls').width(1000);
  563. bc._resize();
  564. // Third crumb is hidden and everything else is visible
  565. expect($crumbs.eq(0).hasClass('hidden')).toEqual(false);
  566. expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);
  567. expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
  568. expect($crumbs.eq(3).hasClass('hidden')).toEqual(false);
  569. expect($crumbs.eq(4).hasClass('hidden')).toEqual(true);
  570. expect($crumbs.eq(5).hasClass('hidden')).toEqual(false);
  571. expect($crumbs.eq(6).hasClass('hidden')).toEqual(false);
  572. expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);
  573. });
  574. });
  575. });