describe('MessageView', function() { var convo, message; before(async () => { await clearDatabase(); convo = new Whisper.Conversation({ id: 'foo' }); message = convo.messageCollection.add({ conversationId: convo.id, body: 'hello world', type: 'outgoing', source: '+14158675309', received_at: Date.now(), }); await storage.put('number_id', '+18088888888.1'); }); it('should display the message text', function() { 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 }).render(); message.set('body', 'goodbye world'); assert.match(view.$el.html(), /goodbye world/); }); it('should have a nice timestamp', function() { var view = new Whisper.MessageView({ model: message }); message.set({ sent_at: Date.now() - 5000 }); view.render(); assert.match(view.$el.html(), /now/); message.set({ sent_at: Date.now() - 60000 }); view.render(); assert.match(view.$el.html(), /min/); message.set({ sent_at: Date.now() - 3600000 }); view.render(); assert.match(view.$el.html(), /hour/); }); it('should not imply messages are from the future', function() { var view = new Whisper.MessageView({ model: message }); message.set({ sent_at: Date.now() + 60000 }); view.render(); assert.match(view.$el.html(), /now/); }); it('should go away when the model is destroyed', function() { var view = new Whisper.MessageView({ model: message }); var div = $('