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);
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
|
2
test/test.js
Normal file
2
test/test.js
Normal file
|
@ -0,0 +1,2 @@
|
|||
mocha.setup("bdd");
|
||||
window.assert = chai.assert;
|
|
@ -126,26 +126,32 @@
|
|||
<script type="text/javascript" src="../js-deps/mustache.js"></script>
|
||||
<script type="text/javascript" src="../js-deps/libphonenumber_api-compiled.js"></script>
|
||||
|
||||
<script type="text/javascript" src="../js/helpers.js" data-cover></script>
|
||||
<script type="text/javascript" src="../js/helpers.js" ></script>
|
||||
<script type="text/javascript" src="../js/webcrypto.js"></script>
|
||||
<script type="text/javascript" src="../js/crypto.js" data-cover></script>
|
||||
<script type="text/javascript" src="../js/crypto.js" ></script>
|
||||
<script type="text/javascript" src="../js/models/messages.js"></script>
|
||||
<script type="text/javascript" src="../js/models/threads.js"></script>
|
||||
<script type="text/javascript" src="../js/api.js"></script>
|
||||
<script type="text/javascript" src="../js/sendmessage.js" data-cover></script>
|
||||
<script type="text/javascript" src="../js/sendmessage.js" ></script>
|
||||
|
||||
<script type="text/javascript" src="../js/chromium.js"><//script>
|
||||
<script type="text/javascript" src="../js/fake_api.js"></script>
|
||||
|
||||
<script type="text/javascript" src="../js/views/notifications.js"></script>
|
||||
<script type="text/javascript" src="../js/views/list_view.js"></script>
|
||||
<script type="text/javascript" src="../js/views/message_view.js"></script>
|
||||
<script type="text/javascript" src="../js/views/message_list_view.js"></script>
|
||||
<script type="text/javascript" src="../js/views/conversation_list_item_view.js"></script>
|
||||
<script type="text/javascript" src="../js/views/conversation_list_view.js"></script>
|
||||
<script type="text/javascript" src="../js/views/conversation_view.js"></script>
|
||||
<script type="text/javascript" src="../js/views/new_conversation_view.js"></script>
|
||||
<script type="text/javascript" src="../js/views/new_group_view.js"></script>
|
||||
<script type="text/javascript" src="../js/views/list_view.js" data-cover></script>
|
||||
<script type="text/javascript" src="../js/views/message_view.js" data-cover></script>
|
||||
<script type="text/javascript" src="../js/views/message_list_view.js" data-cover></script>
|
||||
<script type="text/javascript" src="../js/views/conversation_list_item_view.js" data-cover></script>
|
||||
<script type="text/javascript" src="../js/views/conversation_list_view.js" data-cover></script>
|
||||
<script type="text/javascript" src="../js/views/conversation_view.js" data-cover></script>
|
||||
<script type="text/javascript" src="../js/views/new_conversation_view.js" data-cover></script>
|
||||
<script type="text/javascript" src="../js/views/new_group_view.js" data-cover></script>
|
||||
|
||||
<script type="text/javascript" src="test.js"></script>
|
||||
<script type="text/javascript" src="views/message_view_test.js"></script>
|
||||
<script type="text/javascript" src="views/list_view_test.js"></script>
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
|
||||
|
|
22
test/views/list_view_test.js
Normal file
22
test/views/list_view_test.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
describe('ListView', function() {
|
||||
var collection;
|
||||
|
||||
beforeEach(function(){
|
||||
collection = new Backbone.Collection();
|
||||
});
|
||||
|
||||
it('should add children to the list element as they are added to the collection', function() {
|
||||
var view = new Whisper.ListView({collection: collection});
|
||||
collection.add('hello');
|
||||
assert.equal(view.$el.children().length, 1);
|
||||
collection.add('world');
|
||||
assert.equal(view.$el.children().length, 2);
|
||||
});
|
||||
|
||||
it('should add all the children to the list element on reset', function() {
|
||||
var view = new Whisper.ListView({collection: collection});
|
||||
collection.reset(['goodbye', 'world']);
|
||||
assert.equal(view.$el.children().length, 2);
|
||||
});
|
||||
|
||||
});
|
|
@ -1,5 +1,3 @@
|
|||
mocha.setup("bdd");
|
||||
window.assert = chai.assert;
|
||||
describe('MessageView', function() {
|
||||
var message = Whisper.Messages.add({
|
||||
threadId: 'test-thread',
|
||||
|
|
Loading…
Reference in a new issue