Skip to content

Commit ed4db50

Browse files
committed
fix(dropdown): Dedup code and handle differences if dropdown-menu used
1 parent 59736f7 commit ed4db50

File tree

1 file changed

+5
-109
lines changed

1 file changed

+5
-109
lines changed

src/dropdown/test/dropdown.spec.js

+5-109
Original file line numberDiff line numberDiff line change
@@ -483,131 +483,27 @@ describe('dropdownToggle', function() {
483483
triggerKeyDown($document, 40);
484484

485485
expect(element.hasClass(dropdownConfig.openClass)).toBe(true);
486-
var focusEl = element.find('ul').eq(0).find('a').eq(0);
487-
expect(isFocused(focusEl)).toBe(true);
488-
});
489-
490-
it('should not focus first list element when up arrow pressed after dropdown toggled', function() {
491-
$document.find('body').append(element);
492-
clickDropdownToggle();
493-
expect(element.hasClass(dropdownConfig.openClass)).toBe(true);
494-
495-
triggerKeyDown($document, 38);
496-
var focusEl = element.find('ul').eq(0).find('a').eq(0);
497-
expect(isFocused(focusEl)).toBe(false);
486+
var optionEl = element.find('ul').eq(0).find('a').eq(0);
487+
expect(isFocused(optionEl)).toBe(true);
498488
});
499489

500-
it('should not focus any list element when down arrow pressed if closed', function() {
490+
it('should not focus first list element when down arrow pressed if closed', function() {
501491
$document.find('body').append(element);
502492
triggerKeyDown($document, 40);
503493

504494
expect(element.hasClass(dropdownConfig.openClass)).toBe(false);
505-
var focusEl = element.find('ul').eq(0).find('a');
506-
expect(isFocused(focusEl[0])).toBe(false);
507-
expect(isFocused(focusEl[1])).toBe(false);
508-
});
509-
510-
it('should not change focus when other keys are pressed', function() {
511-
$document.find('body').append(element);
512-
clickDropdownToggle();
513-
triggerKeyDown($document, 37);
514-
515-
expect(element.hasClass(dropdownConfig.openClass)).toBe(true);
516-
var focusEl = element.find('ul').eq(0).find('a');
517-
expect(isFocused(focusEl[0])).toBe(false);
518-
expect(isFocused(focusEl[1])).toBe(false);
519-
});
520-
521-
it('should focus second list element when down arrow pressed twice', function() {
522-
$document.find('body').append(element);
523-
clickDropdownToggle();
524-
triggerKeyDown($document, 40);
525-
triggerKeyDown($document, 40);
526-
527-
expect(element.hasClass(dropdownConfig.openClass)).toBe(true);
528-
var focusEl = element.find('ul').eq(0).find('a').eq(1);
529-
expect(isFocused(focusEl)).toBe(true);
530-
});
531-
532-
it('should focus first list element when down arrow pressed 2x and up pressed 1x', function() {
533-
$document.find('body').append(element);
534-
clickDropdownToggle();
535-
triggerKeyDown($document, 40);
536-
triggerKeyDown($document, 40);
537-
538-
triggerKeyDown($document, 38);
539-
540-
expect(element.hasClass(dropdownConfig.openClass)).toBe(true);
541-
var focusEl = element.find('ul').eq(0).find('a').eq(0);
542-
expect(isFocused(focusEl)).toBe(true);
543-
});
544-
545-
it('should stay focused on final list element if down pressed at list end', function() {
546-
$document.find('body').append(element);
547-
clickDropdownToggle();
548-
triggerKeyDown($document, 40);
549-
triggerKeyDown($document, 40);
550-
551-
expect(element.hasClass(dropdownConfig.openClass)).toBe(true);
552-
var focusEl = element.find('ul').eq(0).find('a').eq(1);
553-
expect(isFocused(focusEl)).toBe(true);
554-
555-
triggerKeyDown($document, 40);
556-
expect(isFocused(focusEl)).toBe(true);
557-
});
558-
559-
it('should close if esc is pressed while focused', function() {
560-
element = dropdown('disabled');
561-
$document.find('body').append(element);
562-
clickDropdownToggle();
563-
564-
triggerKeyDown($document, 40);
565-
566-
expect(element.hasClass(dropdownConfig.openClass)).toBe(true);
567495
var focusEl = element.find('ul').eq(0).find('a').eq(0);
568-
expect(isFocused(focusEl)).toBe(true);
569-
570-
triggerKeyDown($document, 27);
571-
expect(element.hasClass(dropdownConfig.openClass)).toBe(false);
572-
});
573-
});
574-
575-
describe('`keyboard-nav` option with `dropdown-append-to-body` option', function() {
576-
function dropdown() {
577-
return $compile('<li dropdown dropdown-append-to-body keyboard-nav><a href dropdown-toggle></a><ul class="dropdown-menu" id="dropdown-menu"><li><a href>Hello On Body</a></li><li><a href>Hello Again</a></li></ul></li>')($rootScope);
578-
}
579-
580-
beforeEach(function() {
581-
element = dropdown();
582-
});
583-
584-
it('should focus first list element when down arrow pressed', function() {
585-
clickDropdownToggle();
586-
587-
triggerKeyDown($document, 40);
588-
589-
expect(element.hasClass(dropdownConfig.openClass)).toBe(true);
590-
var focusEl = $document.find('ul').eq(0).find('a');
591-
expect(isFocused(focusEl)).toBe(true);
592-
});
593-
594-
it('should not focus first list element when down arrow pressed if closed', function() {
595-
triggerKeyDown($document, 40);
596-
597-
expect(element.hasClass(dropdownConfig.openClass)).toBe(false);
598-
var focusEl = $document.find('ul').eq(0).find('a');
599496
expect(isFocused(focusEl)).toBe(false);
600497
});
601498

602499
it('should focus second list element when down arrow pressed twice', function() {
500+
$document.find('body').append(element);
603501
clickDropdownToggle();
604502
triggerKeyDown($document, 40);
605503
triggerKeyDown($document, 40);
606504

607505
expect(element.hasClass(dropdownConfig.openClass)).toBe(true);
608-
var elem1 = $document.find('ul');
609-
var elem2 = elem1.find('a');
610-
var focusEl = $document.find('ul').eq(0).find('a').eq(1);
506+
var focusEl = element.find('ul').eq(0).find('a').eq(1);
611507
expect(isFocused(focusEl)).toBe(true);
612508
});
613509
});

0 commit comments

Comments
 (0)