forked from bkeepers/monologue
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
47 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// View to manage posting a new status. | ||
// | ||
// Dependencies: | ||
// * el - A form element with a textarea | ||
// * collection - the collection that the status will be created in | ||
Monologue.View.PostStatus = Backbone.View.extend({ | ||
events: { | ||
"submit": "submit" | ||
}, | ||
|
||
submit: function(e) { | ||
e.preventDefault(); | ||
var $input = this.$el.find('textarea'); | ||
this.collection.create({text: $input.val()}); | ||
$input.val(''); | ||
return false; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require('/js/views/post_status.js'); | ||
|
||
describe("Monologue.View.PostStatus", function() { | ||
var view, $el, collection; | ||
|
||
beforeEach(function() { | ||
$el = $("<form><textarea>See, it's not so hard!</textarea></form>"); | ||
collection = new (Backbone.Collection.extend({url: '/mock'})); | ||
// prevent collection from trying to sync with the server | ||
spyOn(collection, 'create'); | ||
|
||
view = new Monologue.View.PostStatus({el: $el, collection: collection}); | ||
}); | ||
|
||
describe("submitting the form", function() { | ||
it("creates status when submitting form", function() { | ||
$el.trigger('submit'); | ||
expect(collection.create).toHaveBeenCalledWith({text: "See, it's not so hard!"}); | ||
}); | ||
|
||
it("clears the textarea", function() { | ||
$el.trigger('submit'); | ||
expect($el.find('textarea').val()).toEqual(''); | ||
}); | ||
}); | ||
}); |