Fix tests

This commit is contained in:
lilia 2014-11-20 16:30:52 -08:00
parent d1c5b6da7a
commit bf22da209f
5 changed files with 31 additions and 15 deletions

View File

@ -35,7 +35,7 @@
model: Message,
database: Whisper.Database,
storeName: 'messages',
comparator: function(m) { return -m.get('timestamp'); },
comparator: 'timestamp',
destroyAll: function () {
return Promise.all(this.models.map(function(m) {
return new Promise(function(resolve, reject) {

View File

@ -14,11 +14,7 @@ var Whisper = Whisper || {};
this.$el.scrollTop(this.el.scrollHeight);
},
addAll: function() {
this.$el.html('');
this.collection.each(function(model) {
var view = new this.itemView({model: model});
this.$el.prepend(view.render().el);
}, this);
Whisper.ListView.prototype.addAll.apply(this, arguments); // super()
this.scrollToBottom();
},
});

View File

@ -89,7 +89,7 @@
before(function(done) {
var convo = new Whisper.ConversationCollection().add(attributes);
convo.save().then(function() {
var message = convo.messages().add({body: 'hello world', conversationId: convo.id});
var message = convo.messageCollection.add({body: 'hello world', conversationId: convo.id});
message.save().then(done)
});
});
@ -97,16 +97,16 @@
it('contains its own messages', function (done) {
var convo = new Whisper.ConversationCollection().add({id: 'foobar'});
convo.fetch().then(function() {
assert.notEqual(convo.messages().length, 0);
convo.fetchMessages().then(function() {
assert.notEqual(convo.messageCollection.length, 0);
done();
});
});
it('contains only its own messages', function (done) {
var convo = new Whisper.ConversationCollection().add({id: 'barfoo'});
convo.fetch().then(function() {
assert.strictEqual(convo.messages().length, 0);
convo.fetchMessages().then(function() {
assert.strictEqual(convo.messageCollection.length, 0);
done();
});
});

View File

@ -72,5 +72,25 @@
});
});
});
it('should be ordered oldest to newest', function() {
var messages = new Whisper.MessageCollection();
// Timestamps
var today = new Date();
var tomorrow = new Date();
tomorrow.setDate(today.getDate()+1);
// Add threads
messages.add({ timestamp: today });
messages.add({ timestamp: tomorrow });
var models = messages.models;
var firstTimestamp = models[0].get('timestamp').getTime();
var secondTimestamp = models[1].get('timestamp').getTime();
// Compare timestamps
assert(firstTimestamp < secondTimestamp);
});
});
})();

View File

@ -5,7 +5,7 @@ describe('MessageView', function() {
});
var convo = conversations.add({id: 'foo'});
var message = convo.messages().add({
var message = convo.messageCollection.add({
conversationId: convo.id,
body: 'hello world',
type: 'outgoing',
@ -13,12 +13,12 @@ describe('MessageView', function() {
});
it('should display the message text', function() {
var view = new Whisper.MessageView({model: message});
assert.match(view.render().$el.html(), /hello world/);
var view = new Whisper.MessageView({model: message}).render();
assert.match(view.$el.text(), /hello world/);
});
it('should auto-update the message text', function() {
var view = new Whisper.MessageView({model: message});
var view = new Whisper.MessageView({model: message}).render();
message.set('body', 'goodbye world');
assert.match(view.$el.html(), /goodbye world/);
});