Add list view tests
Also, * moved fetch out of the list view * removed unused #last() function * put test setup lines in their own tiny file. * added data-cover to view script tags for code coveage reports.
This commit is contained in:
parent
4ccb2b2f98
commit
db86abdf70
6 changed files with 43 additions and 18 deletions
|
@ -12,6 +12,7 @@ var Whisper = Whisper || {};
|
|||
this.$el.html(Mustache.render(this.template));
|
||||
|
||||
this.view = new Whisper.MessageListView({collection: this.model.messages()});
|
||||
this.model.messages().fetch({reset: true});
|
||||
this.$el.find('.discussion-container').append(this.view.el);
|
||||
},
|
||||
events: {
|
||||
|
|
|
@ -9,12 +9,12 @@ var Whisper = Whisper || {};
|
|||
*/
|
||||
Whisper.ListView = Backbone.View.extend({
|
||||
tagName: 'ul',
|
||||
itemView: Backbone.View,
|
||||
initialize: function() {
|
||||
this.listenTo(this.collection, 'change', this.render); // auto update
|
||||
this.listenTo(this.collection, 'add', this.addOne);
|
||||
this.listenTo(this.collection, 'reset', this.addAll);
|
||||
this.listenTo(this.collection, 'all', this.render);
|
||||
this.collection.fetch({reset: true});
|
||||
},
|
||||
|
||||
addOne: function(model) {
|
||||
|
@ -27,10 +27,6 @@ var Whisper = Whisper || {};
|
|||
addAll: function() {
|
||||
this.$el.html('');
|
||||
this.collection.each(this.addOne, this);
|
||||
},
|
||||
|
||||
last: function() {
|
||||
this.collection.at(this.collection.length - 1);
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue