Add tests for message and conversation models

Closes #218
This commit is contained in:
Tara Vancil 2015-03-25 14:17:48 -05:00 committed by lilia
parent 196aa28873
commit d65e0e5eda
2 changed files with 62 additions and 0 deletions

View file

@ -124,6 +124,44 @@
done();
});
});
it('adds conversation to message collection upon leaving group', function() {
var convo = new Whisper.ConversationCollection().add({type: 'group'});
convo.leaveGroup();
assert.notEqual(convo.messageCollection.length, 0);
});
it('has a title', function() {
var convos = new Whisper.ConversationCollection();
var convo = convos.add(attributes);
assert.equal(convo.getTitle(), convo.id);
convo = convos.add({type: ''});
assert.equal(convo.getTitle(), 'Unknown group');
convo = convos.add({name: 'name'});
assert.equal(convo.getTitle(), 'name');
});
it('returns the number', function() {
var convos = new Whisper.ConversationCollection();
var convo = convos.add(attributes);
assert.equal(convo.getNumber(), convo.id);
convo = convos.add({type: ''});
assert.equal(convo.getNumber(), '');
});
it('has an avatar URL', function() {
var convo = new Whisper.ConversationCollection().add(attributes);
assert.equal(convo.getAvatarUrl(), '/images/default.png');
});
it('revokes the avatar URL', function() {
var convo = new Whisper.ConversationCollection().add(attributes);
convo.revokeAvatarUrl();
assert.notOk(convo.avatarUrl);
});
});
})();;

View file

@ -92,5 +92,29 @@
assert(firstTimestamp < secondTimestamp);
});
it('checks if is incoming message', function() {
var messages = new Whisper.MessageCollection();
var message = messages.add(attributes);
assert.notOk(message.isIncoming());
message = messages.add({type: 'incoming'});
assert.ok(message.isIncoming());
});
it('checks if is outgoing message', function() {
var messages = new Whisper.MessageCollection();
var message = messages.add(attributes);
assert.ok(message.isOutgoing());
message = messages.add({type: 'incoming'});
assert.notOk(message.isOutgoing());
});
it('checks if is group update', function() {
var messages = new Whisper.MessageCollection();
var message = messages.add(attributes);
assert.notOk(message.isGroupUpdate());
message = messages.add({group_update: true});
assert.ok(message.isGroupUpdate());
});
});
})();