Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typeahead:autocompleted #132

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/typeahead_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ var TypeaheadView = (function() {
if (hint !== '' && query !== hint) {
suggestion = this.dropdownView.getFirstSuggestion();
this.inputView.setInputValue(suggestion.value);

this.eventBus.trigger('autocompleted', suggestion.datum);
}
},

Expand Down
1 change: 1 addition & 0 deletions test/playground.html
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
$('input').on([
'typeahead:initialized',
'typeahead:selected',
'typeahead:autocompleted',
'typeahead:opened',
'typeahead:closed'
].join(' '), logToTextarea);
Expand Down
15 changes: 15 additions & 0 deletions test/typeahead_view_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ describe('TypeaheadView', function() {

describe('if hint differs from query', function() {
beforeEach(function() {
this.spyEvent = spyOnEvent(this.$input, 'typeahead:autocompleted');
this.inputView.getQuery.andReturn('app');
this.inputView.getHintValue.andReturn('apple');
this.dropdownView.getFirstSuggestion.andReturn({ value: 'apple' });
Expand All @@ -403,11 +404,16 @@ describe('TypeaheadView', function() {
it('should prevent default browser behavior', function() {
expect(this.$e.preventDefault).toHaveBeenCalled();
});

it('should trigger typeahead:autocompleted on the input', function() {
expect(this.spyEvent).toHaveBeenTriggered();
});
});
});

describe('when inputView triggers leftKeyed', function() {
beforeEach(function() {
this.spyEvent = spyOnEvent(this.$input, 'typeahead:autocompleted');
this.inputView.getQuery.andReturn('app');
this.inputView.getHintValue.andReturn('apple');
this.dropdownView.getFirstSuggestion.andReturn({ value: 'apple' });
Expand Down Expand Up @@ -437,6 +443,10 @@ describe('TypeaheadView', function() {
it('should update value of input', function() {
expect(this.inputView.setInputValue).toHaveBeenCalled();
});

it('should trigger typeahead:autocompleted on the input', function() {
expect(this.spyEvent).toHaveBeenTriggered();
});
});

describe('if cursor is not at then end of the query', function() {
Expand All @@ -454,6 +464,7 @@ describe('TypeaheadView', function() {

describe('when inputView triggers rightKeyed', function() {
beforeEach(function() {
this.spyEvent = spyOnEvent(this.$input, 'typeahead:autocompleted');
this.inputView.getQuery.andReturn('app');
this.inputView.getHintValue.andReturn('apple');
this.dropdownView.getFirstSuggestion.andReturn({ value: 'apple' });
Expand All @@ -471,6 +482,10 @@ describe('TypeaheadView', function() {
it('should update input value', function() {
expect(this.inputView.setInputValue).toHaveBeenCalled();
});

it('should trigger typeahead:autocompleted on the input', function() {
expect(this.spyEvent).toHaveBeenTriggered();
});
});

describe('if being viewed in rtl language', function() {
Expand Down