Refactor publisher mentions backbone view

This commit is contained in:
Steffen van Bergerem 2017-01-30 14:09:55 +01:00
parent b23debf0b6
commit a6e6e6de91
No known key found for this signature in database
GPG key ID: 315C9787D548DC6B
2 changed files with 4 additions and 23 deletions

View file

@ -7,7 +7,7 @@ app.views.PublisherMention = app.views.SearchBase.extend({
events: { events: {
"keydown #status_message_text": "onInputBoxKeyDown", "keydown #status_message_text": "onInputBoxKeyDown",
"input #status_message_text": "onInputBoxInput", "input #status_message_text": "updateTypeaheadInput",
"click #status_message_text": "onInputBoxClick", "click #status_message_text": "onInputBoxClick",
"blur #status_message_text": "onInputBoxBlur" "blur #status_message_text": "onInputBoxBlur"
}, },
@ -120,13 +120,6 @@ app.views.PublisherMention = app.views.SearchBase.extend({
this.typeaheadInput.trigger($.Event("keydown", {keyCode: e.keyCode, which: e.which})); this.typeaheadInput.trigger($.Event("keydown", {keyCode: e.keyCode, which: e.which}));
}, },
/**
* Listens for user input and opens results dropdown when input contains the trigger char
*/
onInputBoxInput: function() {
this.updateTypeaheadInput();
},
onInputBoxKeyDown: function(e) { onInputBoxKeyDown: function(e) {
// This also matches HOME/END on OSX which is CMD+LEFT, CMD+RIGHT // This also matches HOME/END on OSX which is CMD+LEFT, CMD+RIGHT
if(e.which === Keycodes.LEFT || e.which === Keycodes.RIGHT || if(e.which === Keycodes.LEFT || e.which === Keycodes.RIGHT ||
@ -169,7 +162,7 @@ app.views.PublisherMention = app.views.SearchBase.extend({
reset: function() { reset: function() {
this.inputBox.val(""); this.inputBox.val("");
this.onInputBoxInput(); this.updateTypeaheadInput();
}, },
closeSuggestions: function() { closeSuggestions: function() {

View file

@ -363,18 +363,6 @@ describe("app.views.PublisherMention", function() {
}); });
}); });
describe("onInputBoxInput", function() {
beforeEach(function() {
this.view = new app.views.PublisherMention({ el: "#publisher" });
});
it("calls 'updateTypeaheadInput'", function() {
spyOn(this.view, "updateTypeaheadInput");
this.view.onInputBoxInput();
expect(this.view.updateTypeaheadInput).toHaveBeenCalled();
});
});
describe("onInputBoxClick", function() { describe("onInputBoxClick", function() {
beforeEach(function() { beforeEach(function() {
this.view = new app.views.PublisherMention({ el: "#publisher" }); this.view = new app.views.PublisherMention({ el: "#publisher" });
@ -402,13 +390,13 @@ describe("app.views.PublisherMention", function() {
describe("reset", function() { describe("reset", function() {
beforeEach(function() { beforeEach(function() {
this.view = new app.views.PublisherMention({ el: "#publisher" }); this.view = new app.views.PublisherMention({ el: "#publisher" });
spyOn(this.view, "onInputBoxInput"); spyOn(this.view, "updateTypeaheadInput");
}); });
it("resets the mention box", function() { it("resets the mention box", function() {
this.view.reset(); this.view.reset();
expect(this.view.inputBox.val()).toBe(""); expect(this.view.inputBox.val()).toBe("");
expect(this.view.onInputBoxInput).toHaveBeenCalled(); expect(this.view.updateTypeaheadInput).toHaveBeenCalled();
}); });
}); });