2018-04-25 17:29:34 +00:00
|
|
|
/* global assert: false */
|
2017-02-06 02:59:20 +00:00
|
|
|
|
2018-04-25 17:29:34 +00:00
|
|
|
/* global Whisper: false */
|
2017-02-06 02:59:20 +00:00
|
|
|
|
2018-04-25 17:29:34 +00:00
|
|
|
'use strict';
|
2017-04-18 23:03:23 +00:00
|
|
|
|
2018-04-25 17:29:34 +00:00
|
|
|
describe('AttachmentView', () => {
|
2018-07-09 21:29:13 +00:00
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
2018-04-25 17:29:34 +00:00
|
|
|
describe('with arbitrary files', () => {
|
|
|
|
it('should render a file view', () => {
|
|
|
|
const attachment = {
|
|
|
|
contentType: 'unused',
|
|
|
|
size: 1232,
|
|
|
|
};
|
|
|
|
const view = new Whisper.AttachmentView({ model: attachment }).render();
|
|
|
|
assert.match(view.el.innerHTML, /fileView/);
|
|
|
|
});
|
|
|
|
it('should display the filename if present', () => {
|
|
|
|
const attachment = {
|
|
|
|
fileName: 'foo.txt',
|
|
|
|
contentType: 'unused',
|
|
|
|
size: 1232,
|
|
|
|
};
|
|
|
|
const view = new Whisper.AttachmentView({ model: attachment }).render();
|
|
|
|
assert.match(view.el.innerHTML, /foo.txt/);
|
|
|
|
});
|
|
|
|
it('should render a file size', () => {
|
|
|
|
const attachment = {
|
|
|
|
size: 1232,
|
|
|
|
contentType: 'unused',
|
|
|
|
};
|
|
|
|
const view = new Whisper.AttachmentView({ model: attachment }).render();
|
|
|
|
assert.match(view.el.innerHTML, /1.2 KB/);
|
|
|
|
});
|
2017-04-18 23:03:23 +00:00
|
|
|
});
|
2018-04-25 17:29:34 +00:00
|
|
|
it('should render an image for images', () => {
|
|
|
|
const now = new Date().getTime();
|
|
|
|
const attachment = { contentType: 'image/png', data: 'grumpy cat' };
|
|
|
|
const view = new Whisper.AttachmentView({
|
2017-02-06 02:59:20 +00:00
|
|
|
model: attachment,
|
2018-04-25 17:29:34 +00:00
|
|
|
timestamp: now,
|
|
|
|
}).render();
|
|
|
|
assert.equal(view.el.firstChild.tagName, 'IMG');
|
2017-02-06 02:59:20 +00:00
|
|
|
});
|
|
|
|
});
|