Welcome to mirror list, hosted at ThFree Co, Russian Federation.

breadcrumbSpec.js « js « tests « files « apps - github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b83ec78be7b3f9c72ceed7311d4ffc15bcca4dd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
/**
* @copyright 2014 Vincent Petry <pvince81@owncloud.com>
 *
 * @author Daniel Calviño Sánchez <danxuliu@gmail.com>
 * @author John Molakvoæ <skjnldsv@protonmail.com>
 * @author Lukas Reschke <lukas@statuscode.ch>
 * @author Vincent Petry <vincent@nextcloud.com>
 *
 * @license AGPL-3.0-or-later
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */

describe('OCA.Files.BreadCrumb tests', function() {
	var BreadCrumb = OCA.Files.BreadCrumb;

	describe('Rendering', function() {
		var bc;
		beforeEach(function() {
			bc = new BreadCrumb({
				getCrumbUrl: function(part, index) {
					// for testing purposes
					return part.dir + '#' + index;
				}
			});
		});
		afterEach(function() {
			bc = null;
		});
		it('Renders its own container', function() {
			bc.render();
			expect(bc.$el.hasClass('breadcrumb')).toEqual(true);
		});
		it('Renders root by default', function() {
			var $crumbs;
			bc.render();
			$crumbs = bc.$el.find('.crumb');
			// menu and home
			expect($crumbs.length).toEqual(2);
			expect($crumbs.eq(0).find('a').hasClass('icon-more')).toEqual(true);
			expect($crumbs.eq(0).find('div.popovermenu').length).toEqual(1);
			expect($crumbs.eq(0).data('dir')).not.toBeDefined();
			expect($crumbs.eq(1).find('a').attr('href')).toEqual('/#1');
			expect($crumbs.eq(1).find('a').hasClass('icon-home')).toEqual(true);
			expect($crumbs.eq(1).data('dir')).toEqual('/');
		});
		it('Renders complete directory when switching to root', function() {
			var $crumbs;
			bc.setDirectory('/somedir');
			bc.setDirectory('/');
			$crumbs = bc.$el.find('.crumb');
			expect($crumbs.length).toEqual(3);
			expect($crumbs.eq(1).data('dir')).toEqual('/');
			expect($crumbs.eq(2).data('dir')).toEqual('/somedir');
			expect($crumbs.eq(2).attr('class').includes("active")).toEqual(false);
		});
		it('Renders single path section', function() {
			var $crumbs;
			bc.setDirectory('/somedir');
			$crumbs = bc.$el.find('.crumb');
			expect($crumbs.length).toEqual(3);
			expect($crumbs.eq(0).find('a').hasClass('icon-more')).toEqual(true);
			expect($crumbs.eq(0).find('div.popovermenu').length).toEqual(1);
			expect($crumbs.eq(0).data('dir')).not.toBeDefined();

			expect($crumbs.eq(1).find('a').attr('href')).toEqual('/#1');
			expect($crumbs.eq(1).find('a').hasClass('icon-home')).toEqual(true);
			expect($crumbs.eq(1).data('dir')).toEqual('/');

			expect($crumbs.eq(2).find('a').attr('href')).toEqual('/somedir#2');
			expect($crumbs.eq(2).find('img').length).toEqual(0);
			expect($crumbs.eq(2).data('dir')).toEqual('/somedir');
		});
		it('Renders multiple path sections and special chars', function() {
			var $crumbs;
			bc.setDirectory('/somedir/with space/abc');
			$crumbs = bc.$el.find('.crumb');
			expect($crumbs.length).toEqual(5);
			expect($crumbs.eq(0).find('a').hasClass('icon-more')).toEqual(true);
			expect($crumbs.eq(0).find('div.popovermenu').length).toEqual(1);
			expect($crumbs.eq(0).data('dir')).not.toBeDefined();

			expect($crumbs.eq(1).find('a').attr('href')).toEqual('/#1');
			expect($crumbs.eq(1).find('a').hasClass('icon-home')).toEqual(true);
			expect($crumbs.eq(1).data('dir')).toEqual('/');

			expect($crumbs.eq(2).find('a').attr('href')).toEqual('/somedir#2');
			expect($crumbs.eq(2).find('img').length).toEqual(0);
			expect($crumbs.eq(2).data('dir')).toEqual('/somedir');

			expect($crumbs.eq(3).find('a').attr('href')).toEqual('/somedir/with space#3');
			expect($crumbs.eq(3).find('img').length).toEqual(0);
			expect($crumbs.eq(3).data('dir')).toEqual('/somedir/with space');

			expect($crumbs.eq(4).find('a').attr('href')).toEqual('/somedir/with space/abc#4');
			expect($crumbs.eq(4).find('img').length).toEqual(0);
			expect($crumbs.eq(4).data('dir')).toEqual('/somedir/with space/abc');
		});
		it('Renders backslashes as regular directory separator', function() {
			var $crumbs;
			bc.setDirectory('/somedir\\with/mixed\\separators');
			$crumbs = bc.$el.find('.crumb');
			expect($crumbs.length).toEqual(6);
			expect($crumbs.eq(0).find('a').hasClass('icon-more')).toEqual(true);
			expect($crumbs.eq(0).find('div.popovermenu').length).toEqual(1);
			expect($crumbs.eq(0).data('dir')).not.toBeDefined();

			expect($crumbs.eq(1).find('a').attr('href')).toEqual('/#1');
			expect($crumbs.eq(1).find('a').hasClass('icon-home')).toEqual(true);
			expect($crumbs.eq(1).data('dir')).toEqual('/');

			expect($crumbs.eq(2).find('a').attr('href')).toEqual('/somedir#2');
			expect($crumbs.eq(2).find('img').length).toEqual(0);
			expect($crumbs.eq(2).data('dir')).toEqual('/somedir');

			expect($crumbs.eq(3).find('a').attr('href')).toEqual('/somedir/with#3');
			expect($crumbs.eq(3).find('img').length).toEqual(0);
			expect($crumbs.eq(3).data('dir')).toEqual('/somedir/with');

			expect($crumbs.eq(4).find('a').attr('href')).toEqual('/somedir/with/mixed#4');
			expect($crumbs.eq(4).find('img').length).toEqual(0);
			expect($crumbs.eq(4).data('dir')).toEqual('/somedir/with/mixed');

			expect($crumbs.eq(5).find('a').attr('href')).toEqual('/somedir/with/mixed/separators#5');
			expect($crumbs.eq(5).find('img').length).toEqual(0);
			expect($crumbs.eq(5).data('dir')).toEqual('/somedir/with/mixed/separators');
		});
	});
	describe('Events', function() {
		it('Calls onClick handler when clicking on a crumb', function() {
			var handler = sinon.stub();
			var bc = new BreadCrumb({
				onClick: handler
			});
			bc.setDirectory('/one/two/three/four');
			// Click on crumb does not work, only link
			bc.$el.find('.crumb:eq(4)').click();
			expect(handler.calledOnce).toEqual(false);

			handler.reset();
			// Click on crumb link works
			bc.$el.find('.crumb:eq(1) a').click();
			expect(handler.calledOnce).toEqual(true);
			expect(handler.getCall(0).thisValue).toEqual(bc.$el.find('.crumb > a').get(1));
		});
		it('Calls onDrop handler when dropping on a crumb', function() {
			var droppableStub = sinon.stub($.fn, 'droppable');
			var handler = sinon.stub();
			var bc = new BreadCrumb({
				onDrop: handler
			});
			bc.setDirectory('/one/two/three/four');
			expect(droppableStub.calledOnce).toEqual(true);

			expect(droppableStub.getCall(0).args[0].drop).toBeDefined();
			// simulate drop
			droppableStub.getCall(0).args[0].drop({dummy: true});

			expect(handler.calledOnce).toEqual(true);
			expect(handler.getCall(0).args[0]).toEqual({dummy: true});

			droppableStub.restore();
		});
	});

	describe('Menu tests', function() {
		var bc, dummyDir, $crumbmenuLink, $popovermenu;

		beforeEach(function() {
			dummyDir = '/one/two/three/four/five'

			bc = new BreadCrumb();
			// append dummy navigation and controls
			// as they are currently used for measurements
			$('#testArea').append(
				'<div id="controls"></div>'
			);
			$('#controls').append(bc.$el);

			bc.setDirectory(dummyDir);

			$('div.crumb').each(function(index){
				$(this).css('width', 50);
				$(this).css('padding', 0);
				$(this).css('margin', 0);
			});
			$('div.crumbhome').css('width', 51);
			$('div.crumbmenu').css('width', 51);

			$('#controls').width(1000);
			bc._resize();

			// Shrink to show popovermenu
			$('#controls').width(300);
			bc._resize();

			$crumbmenuLink = bc.$el.find('.crumbmenu > a');
			$popovermenu = $crumbmenuLink.next('.popovermenu');
		});
		afterEach(function() {
			bc = null;
		});

		it('Shows only items not in the breadcrumb', function() {
			var hiddenCrumbs = bc.$el.find('.crumb:not(.crumbmenu).hidden');
			expect($popovermenu.find('li:not(.in-breadcrumb)').length).toEqual(hiddenCrumbs.length);
		});
	});

	describe('Resizing', function() {
		var bc, dummyDir, widths, paddings, margins;

		// cit() will skip tests if running on PhantomJS because it does not
		// have proper support for flexboxes.
		var cit = window.isPhantom?xit:it;

		beforeEach(function() {
			dummyDir = '/short name/longer name/looooooooooooonger/' +
				'even longer long long long longer long/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/last one';

			bc = new BreadCrumb();
			// append dummy navigation and controls
			// as they are currently used for measurements
			$('#testArea').append(
				'<div id="controls"></div>'
			);
			$('#controls').append(bc.$el);

			// triggers resize implicitly
			bc.setDirectory(dummyDir);

			// using hard-coded widths (pre-measured) to avoid getting different
			// results on different browsers due to font engine differences
			// 51px is default size for menu and home
			widths = [51, 51, 106, 112, 160, 257, 251, 91];
			// using hard-coded paddings and margins to avoid depending on the
			// current CSS values used in the server
			paddings = [0, 0, 0, 0, 0, 0, 0, 0];
			margins = [0, 0, 0, 0, 0, 0, 0, 0];

			$('div.crumb').each(function(index){
				$(this).css('width', widths[index]);
				$(this).css('padding', paddings[index]);
				$(this).css('margin', margins[index]);
			});
		});
		afterEach(function() {
			bc = null;
		});
		it('Hides breadcrumbs to fit available width', function() {
			var $crumbs;

			$('#controls').width(500);
			bc._resize();

			$crumbs = bc.$el.find('.crumb');

			// Second, third, fourth and fifth crumb are hidden and everything
			// else is visible
			expect($crumbs.eq(0).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);

			expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(3).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(4).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(5).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(6).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);
		});
		it('Hides breadcrumbs to fit available width', function() {
			var $crumbs;

			$('#controls').width(700);
			bc._resize();

			$crumbs = bc.$el.find('.crumb');

			// Third and fourth crumb are hidden and everything else is visible
			expect($crumbs.eq(0).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);

			expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(3).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(4).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(5).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(6).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);
		});
		it('Hides breadcrumbs to fit available width taking paddings into account', function() {
			var $crumbs;

			// Each element is 20px wider
			paddings = [10, 10, 10, 10, 10, 10, 10, 10];

			$('div.crumb').each(function(index){
				$(this).css('padding', paddings[index]);
			});

			$('#controls').width(700);
			bc._resize();

			$crumbs = bc.$el.find('.crumb');

			// Second, third and fourth crumb are hidden and everything else is
			// visible
			expect($crumbs.eq(0).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);

			expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(3).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(4).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(5).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(6).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);
		});
		it('Hides breadcrumbs to fit available width taking margins into account', function() {
			var $crumbs;

			// Each element is 20px wider
			margins = [10, 10, 10, 10, 10, 10, 10, 10];

			$('div.crumb').each(function(index){
				$(this).css('margin', margins[index]);
			});

			$('#controls').width(700);
			bc._resize();

			$crumbs = bc.$el.find('.crumb');

			// Second, third and fourth crumb are hidden and everything else is
			// visible
			expect($crumbs.eq(0).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);

			expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(3).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(4).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(5).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(6).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);
		});
		it('Hides breadcrumbs to fit available width left by siblings', function() {
			var $crumbs;

			$('#controls').width(700);
			bc._resize();

			$crumbs = bc.$el.find('.crumb');

			// Third and fourth crumb are hidden and everything else is visible
			expect($crumbs.eq(0).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);

			expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(3).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(4).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(5).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(6).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);

			// Visible sibling widths add up to 200px
			var $previousSibling = $('<div class="otherSibling"></div>');
			// Set both the width and the min-width to even differences in width
			// handling in the browsers used to run the tests.
			$previousSibling.css('width', '50px');
			$previousSibling.css('min-width', '50px');
			$('#controls').prepend($previousSibling);

			var $creatableActions = $('<div class="actions creatable"></div>');
			// Set both the width and the min-width to even differences in width
			// handling in the browsers used to run the tests.
			$creatableActions.css('width', '100px');
			$creatableActions.css('min-width', '100px');
			$('#controls').append($creatableActions);

			var $nextHiddenSibling = $('<div class="otherSibling hidden"></div>');
			// Set both the width and the min-width to even differences in width
			// handling in the browsers used to run the tests.
			$nextHiddenSibling.css('width', '200px');
			$nextHiddenSibling.css('min-width', '200px');
			$('#controls').append($nextHiddenSibling);

			var $nextSibling = $('<div class="otherSibling"></div>');
			// Set both the width and the min-width to even differences in width
			// handling in the browsers used to run the tests.
			$nextSibling.css('width', '50px');
			$nextSibling.css('min-width', '50px');
			$('#controls').append($nextSibling);

			bc._resize();

			// Second, third, fourth and fifth crumb are hidden and everything
			// else is visible
			expect($crumbs.eq(0).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);

			expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(3).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(4).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(5).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(6).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);
		});
		it('Hides breadcrumbs to fit available width left by siblings with paddings and margins', function() {
			var $crumbs;

			$('#controls').width(700);
			bc._resize();

			$crumbs = bc.$el.find('.crumb');

			// Third and fourth crumb are hidden and everything else is visible
			expect($crumbs.eq(0).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);

			expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(3).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(4).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(5).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(6).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);

			// Visible sibling widths add up to 200px
			var $previousSibling = $('<div class="otherSibling"></div>');
			// Set both the width and the min-width to even differences in width
			// handling in the browsers used to run the tests.
			$previousSibling.css('width', '10px');
			$previousSibling.css('min-width', '10px');
			$previousSibling.css('margin', '20px');
			$('#controls').prepend($previousSibling);

			var $creatableActions = $('<div class="actions creatable"></div>');
			// Set both the width and the min-width to even differences in width
			// handling in the browsers used to run the tests.
			$creatableActions.css('width', '20px');
			$creatableActions.css('min-width', '20px');
			$creatableActions.css('margin-left', '40px');
			$creatableActions.css('padding-right', '40px');
			$('#controls').append($creatableActions);

			var $nextHiddenSibling = $('<div class="otherSibling hidden"></div>');
			// Set both the width and the min-width to even differences in width
			// handling in the browsers used to run the tests.
			$nextHiddenSibling.css('width', '200px');
			$nextHiddenSibling.css('min-width', '200px');
			$('#controls').append($nextHiddenSibling);

			var $nextSibling = $('<div class="otherSibling"></div>');
			// Set both the width and the min-width to even differences in width
			// handling in the browsers used to run the tests.
			$nextSibling.css('width', '10px');
			$nextSibling.css('min-width', '10px');
			$nextSibling.css('padding', '20px');
			$('#controls').append($nextSibling);

			bc._resize();

			// Second, third, fourth and fifth crumb are hidden and everything
			// else is visible
			expect($crumbs.eq(0).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);

			expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(3).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(4).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(5).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(6).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);
		});
		it('Updates the breadcrumbs when reducing available width', function() {
			var $crumbs;

			// enough space
			$('#controls').width(1800);
			bc._resize();

			$crumbs = bc.$el.find('.crumb');

			// Menu is hidden
			expect($crumbs.eq(0).hasClass('hidden')).toEqual(true);

			// simulate decrease
			$('#controls').width(950);
			bc._resize();

			// Third crumb is hidden and everything else is visible
			expect($crumbs.eq(0).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);

			expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(3).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(4).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(5).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(6).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);
		});
		it('Updates the breadcrumbs when reducing available width taking into account the menu width', function() {
			var $crumbs;

			// enough space
			$('#controls').width(1800);
			bc._resize();

			$crumbs = bc.$el.find('.crumb');

			// Menu is hidden
			expect($crumbs.eq(0).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);

			expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(3).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(4).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(5).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(6).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);

			// simulate decrease
			// 650 is enough for all the crumbs except the third and fourth
			// ones, but not enough for the menu and all the crumbs except the
			// third and fourth ones; the second one has to be hidden too.
			$('#controls').width(650);
			bc._resize();

			// Second, third and fourth crumb are hidden and everything else is
			// visible
			expect($crumbs.eq(0).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);

			expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(3).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(4).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(5).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(6).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);
		});
		it('Updates the breadcrumbs when increasing available width', function() {
			var $crumbs;

			// limited space
			$('#controls').width(850);
			bc._resize();

			$crumbs = bc.$el.find('.crumb');

			// Third and fourth crumb are hidden and everything else is visible
			expect($crumbs.eq(0).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);

			expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(3).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(4).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(5).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(6).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);

			// simulate increase
			$('#controls').width(1000);
			bc._resize();

			// Third crumb is hidden and everything else is visible
			expect($crumbs.eq(0).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);

			expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(3).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(4).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(5).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(6).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);
		});
		it('Updates the breadcrumbs when increasing available width taking into account the menu width', function() {
			var $crumbs;

			// limited space
			$('#controls').width(850);
			bc._resize();

			$crumbs = bc.$el.find('.crumb');

			// Third and fourth crumb are hidden and everything else is visible
			expect($crumbs.eq(0).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);

			expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(3).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(4).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(5).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(6).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);

			// simulate increase
			// 1030 is enough for all the crumbs if the menu is hidden.
			$('#controls').width(1030);
			bc._resize();

			// Menu is hidden and everything else is visible
			expect($crumbs.eq(0).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);

			expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(3).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(4).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(5).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(6).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);
		});
		cit('Updates the breadcrumbs when increasing available width with an expanding sibling', function() {
			var $crumbs;

			// The sibling expands to fill all the width left by the breadcrumbs
			var $nextSibling = $('<div class="sibling"></div>');
			// Set both the width and the min-width to even differences in width
			// handling in the browsers used to run the tests.
			$nextSibling.css('width', '10px');
			$nextSibling.css('min-width', '10px');
			$nextSibling.css('display', 'flex');
			$nextSibling.css('flex', '1 1');
			var $nextSiblingChild = $('<div class="siblingChild"></div>');
			$nextSiblingChild.css('margin-left', 'auto');
			$nextSibling.append($nextSiblingChild);
			$('#controls').append($nextSibling);

			// limited space
			$('#controls').width(850);
			bc._resize();

			$crumbs = bc.$el.find('.crumb');

			// Third and fourth crumb are hidden and everything else is visible
			expect($crumbs.eq(0).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);

			expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(3).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(4).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(5).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(6).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);

			// simulate increase
			$('#controls').width(1000);
			bc._resize();

			// Third crumb is hidden and everything else is visible
			expect($crumbs.eq(0).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(1).hasClass('hidden')).toEqual(false);

			expect($crumbs.eq(2).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(3).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(4).hasClass('hidden')).toEqual(true);
			expect($crumbs.eq(5).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(6).hasClass('hidden')).toEqual(false);
			expect($crumbs.eq(7).hasClass('hidden')).toEqual(false);
		});
	});
});