breadcrumbSpec.js 24 KB

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