2014-09-01 18:52:58 +00:00
|
|
|
describe('MessageView', function() {
|
2017-09-07 01:20:42 +00:00
|
|
|
var convo, message;
|
|
|
|
|
2018-04-03 15:41:40 +00:00
|
|
|
before(async (done) => {
|
|
|
|
await clearDatabase();
|
2018-03-27 23:02:00 +00:00
|
|
|
convo = new Whisper.Conversation({id: 'foo'});
|
2017-09-07 01:20:42 +00:00
|
|
|
message = convo.messageCollection.add({
|
|
|
|
conversationId: convo.id,
|
|
|
|
body: 'hello world',
|
|
|
|
type: 'outgoing',
|
|
|
|
source: '+14158675309',
|
2018-04-03 15:41:40 +00:00
|
|
|
received_at: Date.now(),
|
2017-09-07 01:20:42 +00:00
|
|
|
});
|
2014-11-13 22:35:37 +00:00
|
|
|
|
2018-04-03 15:41:40 +00:00
|
|
|
await storage.put('number_id', '+18088888888.1');
|
|
|
|
done();
|
2014-09-01 18:52:58 +00:00
|
|
|
});
|
|
|
|
|
2014-09-04 07:25:08 +00:00
|
|
|
it('should display the message text', function() {
|
2014-11-21 00:30:52 +00:00
|
|
|
var view = new Whisper.MessageView({model: message}).render();
|
|
|
|
assert.match(view.$el.text(), /hello world/);
|
2014-09-04 07:25:08 +00:00
|
|
|
});
|
2014-09-01 18:52:58 +00:00
|
|
|
|
2014-09-04 07:25:08 +00:00
|
|
|
it('should auto-update the message text', function() {
|
2014-11-21 00:30:52 +00:00
|
|
|
var view = new Whisper.MessageView({model: message}).render();
|
2014-09-04 07:25:08 +00:00
|
|
|
message.set('body', 'goodbye world');
|
|
|
|
assert.match(view.$el.html(), /goodbye world/);
|
|
|
|
});
|
2014-09-01 18:52:58 +00:00
|
|
|
|
2014-11-11 08:35:18 +00:00
|
|
|
it('should have a nice timestamp', function() {
|
|
|
|
var view = new Whisper.MessageView({model: message});
|
2015-11-08 08:15:14 +00:00
|
|
|
message.set({'sent_at': Date.now() - 5000});
|
2015-03-06 00:51:53 +00:00
|
|
|
view.render();
|
2016-04-19 02:48:54 +00:00
|
|
|
assert.match(view.$el.html(), /now/);
|
2014-11-11 08:35:18 +00:00
|
|
|
|
2015-11-08 08:15:14 +00:00
|
|
|
message.set({'sent_at': Date.now() - 60000});
|
2015-03-06 00:51:53 +00:00
|
|
|
view.render();
|
2016-04-19 02:48:54 +00:00
|
|
|
assert.match(view.$el.html(), /min/);
|
2014-11-11 08:35:18 +00:00
|
|
|
|
2015-11-08 08:15:14 +00:00
|
|
|
message.set({'sent_at': Date.now() - 3600000});
|
2015-03-06 00:51:53 +00:00
|
|
|
view.render();
|
2016-04-19 02:48:54 +00:00
|
|
|
assert.match(view.$el.html(), /hour/);
|
2014-11-11 08:35:18 +00:00
|
|
|
});
|
2015-11-08 19:01:39 +00:00
|
|
|
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();
|
2016-04-19 02:48:54 +00:00
|
|
|
assert.match(view.$el.html(), /now/);
|
2015-11-08 19:01:39 +00:00
|
|
|
});
|
2014-11-11 08:35:18 +00:00
|
|
|
|
2014-09-04 07:25:08 +00: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 18:52:58 +00:00
|
|
|
});
|
2015-03-07 01:01:04 +00: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 20:31:36 +00:00
|
|
|
var link = view.$el.find('.body a');
|
2015-03-07 01:01:04 +00:00
|
|
|
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
|
|
|
|
});
|
2015-03-10 19:11:32 +00:00
|
|
|
|
2016-09-01 20:31:36 +00:00
|
|
|
it('supports emoji', function() {
|
2015-03-10 19:11:32 +00:00
|
|
|
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);
|
2017-11-27 23:54:59 +00:00
|
|
|
assert.strictEqual(img.attr('src'), 'node_modules/emoji-datasource-apple/img/apple/64/2764-fe0f.png');
|
2016-09-01 20:31:36 +00:00
|
|
|
assert.strictEqual(img.attr('title'), ':heart:');
|
2015-03-10 19:11:32 +00:00
|
|
|
assert.strictEqual(img.attr('class'), 'emoji');
|
|
|
|
});
|
2014-09-01 18:52:58 +00:00
|
|
|
});
|