Skip to content

Commit

Permalink
Refactor publisher mentions backbone view
Browse files Browse the repository at this point in the history
  • Loading branch information
svbergerem committed Feb 12, 2017
1 parent b23debf commit a6e6e6d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 23 deletions.
11 changes: 2 additions & 9 deletions app/assets/javascripts/app/views/publisher/mention_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ app.views.PublisherMention = app.views.SearchBase.extend({

events: {
"keydown #status_message_text": "onInputBoxKeyDown",
"input #status_message_text": "onInputBoxInput",
"input #status_message_text": "updateTypeaheadInput",
"click #status_message_text": "onInputBoxClick",
"blur #status_message_text": "onInputBoxBlur"
},
Expand Down Expand Up @@ -120,13 +120,6 @@ app.views.PublisherMention = app.views.SearchBase.extend({
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) {
// This also matches HOME/END on OSX which is CMD+LEFT, CMD+RIGHT
if(e.which === Keycodes.LEFT || e.which === Keycodes.RIGHT ||
Expand Down Expand Up @@ -169,7 +162,7 @@ app.views.PublisherMention = app.views.SearchBase.extend({

reset: function() {
this.inputBox.val("");
this.onInputBoxInput();
this.updateTypeaheadInput();
},

closeSuggestions: function() {
Expand Down
16 changes: 2 additions & 14 deletions spec/javascripts/app/views/publisher_mention_view_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
beforeEach(function() {
this.view = new app.views.PublisherMention({ el: "#publisher" });
Expand Down Expand Up @@ -402,13 +390,13 @@ describe("app.views.PublisherMention", function() {
describe("reset", function() {
beforeEach(function() {
this.view = new app.views.PublisherMention({ el: "#publisher" });
spyOn(this.view, "onInputBoxInput");
spyOn(this.view, "updateTypeaheadInput");
});

it("resets the mention box", function() {
this.view.reset();
expect(this.view.inputBox.val()).toBe("");
expect(this.view.onInputBoxInput).toHaveBeenCalled();
expect(this.view.updateTypeaheadInput).toHaveBeenCalled();
});
});

Expand Down

0 comments on commit a6e6e6d

Please sign in to comment.