2014-09-01 20:52:58 +02:00
|
|
|
describe('MessageView', function() {
|
2014-11-17 01:01:28 +01:00
|
|
|
var conversations = new Whisper.ConversationCollection();
|
2014-11-13 23:35:37 +01:00
|
|
|
before(function(done) {
|
2014-11-17 01:01:28 +01:00
|
|
|
conversations.fetch().then(done);
|
2014-11-13 23:35:37 +01:00
|
|
|
});
|
|
|
|
|
2014-11-17 01:01:28 +01:00
|
|
|
var convo = conversations.add({id: 'foo'});
|
2014-11-21 01:30:52 +01:00
|
|
|
var message = convo.messageCollection.add({
|
2014-11-13 23:35:37 +01:00
|
|
|
conversationId: convo.id,
|
2014-09-01 20:52:58 +02:00
|
|
|
body: 'hello world',
|
|
|
|
type: 'outgoing',
|
|
|
|
timestamp: new Date().getTime()
|
|
|
|
});
|
|
|
|
|
2014-09-04 09:25:08 +02:00
|
|
|
it('should display the message text', function() {
|
2014-11-21 01:30:52 +01:00
|
|
|
var view = new Whisper.MessageView({model: message}).render();
|
|
|
|
assert.match(view.$el.text(), /hello world/);
|
2014-09-04 09:25:08 +02:00
|
|
|
});
|
2014-09-01 20:52:58 +02:00
|
|
|
|
2014-09-04 09:25:08 +02:00
|
|
|
it('should auto-update the message text', function() {
|
2014-11-21 01:30:52 +01:00
|
|
|
var view = new Whisper.MessageView({model: message}).render();
|
2014-09-04 09:25:08 +02:00
|
|
|
message.set('body', 'goodbye world');
|
|
|
|
assert.match(view.$el.html(), /goodbye world/);
|
|
|
|
});
|
2014-09-01 20:52:58 +02:00
|
|
|
|
2014-11-11 09:35:18 +01:00
|
|
|
it('should have a nice timestamp', function() {
|
|
|
|
var view = new Whisper.MessageView({model: message});
|
|
|
|
message.set({'timestamp': new Date().getTime() - 5000});
|
|
|
|
assert.match(view.$el.html(), /seconds ago/);
|
|
|
|
|
|
|
|
message.set({'timestamp': new Date().getTime() - 60000});
|
|
|
|
assert.match(view.$el.html(), /minute ago/);
|
|
|
|
|
|
|
|
message.set({'timestamp': new Date().getTime() - 3600000});
|
|
|
|
assert.match(view.$el.html(), /hour ago/);
|
|
|
|
});
|
|
|
|
|
2014-09-04 09:25:08 +02:00
|
|
|
it('should go away when the model is destroyed', function() {
|
|
|
|
var view = new Whisper.MessageView({model: message});
|
|
|
|
var div = $('<div>').append(view.$el);
|
|
|
|
message.destroy();
|
|
|
|
assert.strictEqual(div.find(view.$el).length, 0);
|
2014-09-01 20:52:58 +02:00
|
|
|
});
|
|
|
|
});
|