Fix tests
This commit is contained in:
parent
d1c5b6da7a
commit
bf22da209f
5 changed files with 31 additions and 15 deletions
|
@ -35,7 +35,7 @@
|
||||||
model: Message,
|
model: Message,
|
||||||
database: Whisper.Database,
|
database: Whisper.Database,
|
||||||
storeName: 'messages',
|
storeName: 'messages',
|
||||||
comparator: function(m) { return -m.get('timestamp'); },
|
comparator: 'timestamp',
|
||||||
destroyAll: function () {
|
destroyAll: function () {
|
||||||
return Promise.all(this.models.map(function(m) {
|
return Promise.all(this.models.map(function(m) {
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
|
|
|
@ -14,11 +14,7 @@ var Whisper = Whisper || {};
|
||||||
this.$el.scrollTop(this.el.scrollHeight);
|
this.$el.scrollTop(this.el.scrollHeight);
|
||||||
},
|
},
|
||||||
addAll: function() {
|
addAll: function() {
|
||||||
this.$el.html('');
|
Whisper.ListView.prototype.addAll.apply(this, arguments); // super()
|
||||||
this.collection.each(function(model) {
|
|
||||||
var view = new this.itemView({model: model});
|
|
||||||
this.$el.prepend(view.render().el);
|
|
||||||
}, this);
|
|
||||||
this.scrollToBottom();
|
this.scrollToBottom();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -89,7 +89,7 @@
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
var convo = new Whisper.ConversationCollection().add(attributes);
|
var convo = new Whisper.ConversationCollection().add(attributes);
|
||||||
convo.save().then(function() {
|
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)
|
message.save().then(done)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -97,16 +97,16 @@
|
||||||
|
|
||||||
it('contains its own messages', function (done) {
|
it('contains its own messages', function (done) {
|
||||||
var convo = new Whisper.ConversationCollection().add({id: 'foobar'});
|
var convo = new Whisper.ConversationCollection().add({id: 'foobar'});
|
||||||
convo.fetch().then(function() {
|
convo.fetchMessages().then(function() {
|
||||||
assert.notEqual(convo.messages().length, 0);
|
assert.notEqual(convo.messageCollection.length, 0);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('contains only its own messages', function (done) {
|
it('contains only its own messages', function (done) {
|
||||||
var convo = new Whisper.ConversationCollection().add({id: 'barfoo'});
|
var convo = new Whisper.ConversationCollection().add({id: 'barfoo'});
|
||||||
convo.fetch().then(function() {
|
convo.fetchMessages().then(function() {
|
||||||
assert.strictEqual(convo.messages().length, 0);
|
assert.strictEqual(convo.messageCollection.length, 0);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -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);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -5,7 +5,7 @@ describe('MessageView', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
var convo = conversations.add({id: 'foo'});
|
var convo = conversations.add({id: 'foo'});
|
||||||
var message = convo.messages().add({
|
var message = convo.messageCollection.add({
|
||||||
conversationId: convo.id,
|
conversationId: convo.id,
|
||||||
body: 'hello world',
|
body: 'hello world',
|
||||||
type: 'outgoing',
|
type: 'outgoing',
|
||||||
|
@ -13,12 +13,12 @@ describe('MessageView', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should display the message text', function() {
|
it('should display the message text', function() {
|
||||||
var view = new Whisper.MessageView({model: message});
|
var view = new Whisper.MessageView({model: message}).render();
|
||||||
assert.match(view.render().$el.html(), /hello world/);
|
assert.match(view.$el.text(), /hello world/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should auto-update the message text', function() {
|
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');
|
message.set('body', 'goodbye world');
|
||||||
assert.match(view.$el.html(), /goodbye world/);
|
assert.match(view.$el.html(), /goodbye world/);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue