Cable-Desktop/test/views/message_view_test.js

87 lines
2.9 KiB
JavaScript
Raw Normal View History

2014-09-01 20:52:58 +02:00
describe('MessageView', function() {
var conversations = new Whisper.ConversationCollection();
before(function(done) {
conversations.fetch().then(done);
2015-12-06 04:23:29 +01:00
storage.put('number_id', '+18088888888.1');
});
var convo = conversations.add({id: 'foo'});
2014-11-21 01:30:52 +01:00
var message = convo.messageCollection.add({
conversationId: convo.id,
2014-09-01 20:52:58 +02:00
body: 'hello world',
type: 'outgoing',
2015-09-17 20:40:19 +02:00
source: '+14158675309',
received_at: Date.now()
2014-09-01 20:52:58 +02:00
});
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
it('should have a nice timestamp', function() {
var view = new Whisper.MessageView({model: message});
message.set({'sent_at': Date.now() - 5000});
2015-03-06 01:51:53 +01:00
view.render();
assert.match(view.$el.html(), /now/);
message.set({'sent_at': Date.now() - 60000});
2015-03-06 01:51:53 +01:00
view.render();
assert.match(view.$el.html(), /min/);
message.set({'sent_at': Date.now() - 3600000});
2015-03-06 01:51:53 +01:00
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/);
});
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
});
it('allows links', function() {
var url = 'http://example.com';
message.set('body', url);
var view = new Whisper.MessageView({model: message});
view.render();
2016-09-01 22:31:36 +02:00
var link = view.$el.find('.body a');
assert.strictEqual(link.length, 1);
assert.strictEqual(link.text(), url);
assert.strictEqual(link.attr('href'), url);
});
it('disallows xss', function() {
var xss = '<script>alert("pwnd")</script>';
message.set('body', xss);
var view = new Whisper.MessageView({model: message});
view.render();
assert.include(view.$el.text(), xss); // should appear as escaped text
assert.strictEqual(view.$el.find('script').length, 0); // should not appear as html
});
2016-09-01 22:31:36 +02:00
it('supports emoji', function() {
message.set('body', 'I \u2764\uFE0F emoji!');
var view = new Whisper.MessageView({model: message});
view.render();
var img = view.$el.find('.content img');
assert.strictEqual(img.length, 1);
2016-09-01 22:31:36 +02:00
assert.strictEqual(img.attr('src'), '/images/emoji/apple/2764.png');
assert.strictEqual(img.attr('title'), ':heart:');
assert.strictEqual(img.attr('class'), 'emoji');
});
2014-09-01 20:52:58 +02:00
});