|
1 | | -/*jslint vars: true*/ |
| 1 | +/*jslint vars: true*/ |
2 | 2 | /*global describe, it, expect, waits, waitsFor, runs, afterEach, spyOn, $*/ |
3 | 3 |
|
4 | 4 | describe('Autocomplete Async', function(){ |
@@ -39,7 +39,7 @@ describe('Autocomplete Async', function(){ |
39 | 39 | }); |
40 | 40 | }); |
41 | 41 |
|
42 | | -describe('Autocomplete Async', function() { |
| 42 | +describe('Autocomplete Async', function () { |
43 | 43 | var input = document.createElement('input'), |
44 | 44 | completeQuery, |
45 | 45 | mockupSuggestion = { value: 'A', data: 'A' }, |
@@ -688,3 +688,47 @@ describe('Autocomplete', function () { |
688 | 688 | }); |
689 | 689 |
|
690 | 690 | }); |
| 691 | + |
| 692 | +describe('When options.preserveInput is true', function() { |
| 693 | + var input = $('<input />'), |
| 694 | + instance, |
| 695 | + suggestionData = null; |
| 696 | + |
| 697 | + beforeEach(function() { |
| 698 | + input.autocomplete({ |
| 699 | + lookup: [{ value: 'Jamaica', data: 'J' }, { value: 'Jamaica2', data: 'J' }, { value: 'Jamaica3', data: 'J' }], |
| 700 | + preserveInput: true, |
| 701 | + onSelect: function (suggestion) { |
| 702 | + suggestionData = suggestion.data; |
| 703 | + } |
| 704 | + }); |
| 705 | + |
| 706 | + input.val('J'); |
| 707 | + instance = input.autocomplete(); |
| 708 | + }); |
| 709 | + |
| 710 | + afterEach(function() { |
| 711 | + instance.dispose(); |
| 712 | + }); |
| 713 | + |
| 714 | + it('Should NOT change input value when item is selected', function() { |
| 715 | + instance.onValueChange(); |
| 716 | + instance.select(0); |
| 717 | + |
| 718 | + expect(input.val()).toEqual('J'); |
| 719 | + }); |
| 720 | + |
| 721 | + it('Should NOT change input value when move down', function() { |
| 722 | + instance.onValueChange(); |
| 723 | + instance.moveDown(); |
| 724 | + |
| 725 | + expect(input.val()).toEqual('J'); |
| 726 | + }); |
| 727 | + |
| 728 | + it('Should NOT change input value when move up', function() { |
| 729 | + instance.onValueChange(); |
| 730 | + instance.moveUp(); |
| 731 | + |
| 732 | + expect(input.val()).toEqual('J'); |
| 733 | + }); |
| 734 | +}); |
0 commit comments