diff --git a/src/components/autocomplete/autocomplete.spec.js b/src/components/autocomplete/autocomplete.spec.js index c97a873b32..f47b1f5038 100644 --- a/src/components/autocomplete/autocomplete.spec.js +++ b/src/components/autocomplete/autocomplete.spec.js @@ -1895,6 +1895,81 @@ describe('', function() { expect(input[0].getAttribute('aria-activedescendant')).toBe('md-option-' + ctrl.id + '-1'); }); + it('should not retain the position of the scroll after panel is reopened', function() { + var template = + '' + + ' {{item.display}}' + + ''; + var items = []; + for (var i = 0; i < 20; i++) { + items.push({ display: 'f' + i}); + } + var scope = createScope(items); + var element = compile(template, scope); + var ctrl = element.controller('mdAutocomplete'); + var input = element.find('input'); + // Run our initial flush + $timeout.flush(); + + // Initial state + expect(ctrl.index).toBe(-1); + expect(ctrl.hidden).toBe(true); + expect(ctrl.activeOption).toBe(null); + + ctrl.focus(); + waitForVirtualRepeat(element); + + // After getting focus + expect(ctrl.hidden).toBe(false); + expect(ctrl.index).toBe(-1); + expect(ctrl.activeOption).toBe(null); + + ctrl.blur(); + + // After loosing focus + expect(ctrl.hidden).toBe(true); + + ctrl.focus(); + waitForVirtualRepeat(); + + // After getting focus again + expect(ctrl.hidden).toBe(false); + expect(ctrl.index).toBe(-1); + expect(ctrl.activeOption).toBe(null); + + for (var j = 0; j < 10; j++){ + ctrl.keydown(keydownEvent($mdConstant.KEY_CODE.DOWN_ARROW)); + } + $material.flushInterimElement(); + + // After highlighting the 10th element + expect(ctrl.hidden).toBe(false); + expect(ctrl.index).toBe(9); + expect(ctrl.activeOption).toBe('md-option-' + ctrl.id + '-9'); + + ctrl.blur(); + + // After loosing focus + expect(ctrl.hidden).toBe(true); + ctrl.focus(); + waitForVirtualRepeat(); + + // After getting focus again + expect(ctrl.hidden).toBe(false); + expect(ctrl.index).toBe(-1); + expect(ctrl.activeOption).toBe(null); + + element.remove(); + }); + it('should set activeOption when autoselect is on', function() { var template = '