Add attachment_views_test.js tests

This commit is contained in:
Blake Griffith 2017-02-05 18:59:20 -08:00 committed by lilia
parent aa55b6a538
commit 1e498294e0
4 changed files with 37 additions and 15 deletions

View file

@ -90,19 +90,22 @@
this.saveFile();
}
},
saveFile: function() {
var blob = this.blob;
var suggestedName = 'signal';
suggestedName: function() {
var suggestion = 'signal';
if (this.timestamp) {
suggestedName += moment(this.timestamp).format('-YYYY-MM-DD-HHmmss');
suggestion += moment(this.timestamp).format('-YYYY-MM-DD-HHmmss');
}
if (this.fileType) {
suggestedName += '.' + this.fileType;
suggestion += '.' + this.fileType;
}
return suggestion;
},
saveFile: function() {
var blob = this.blob;
var w = extension.windows.getViews()[0];
if (w && w.chrome && w.chrome.fileSystem) {
w.chrome.fileSystem.chooseEntry({
type: 'saveFile', suggestedName: suggestedName
type: 'saveFile', suggestedName: this.suggestedName()
}, function(entry) {
if (!entry) {
return;

View file

@ -538,6 +538,7 @@
<script type="text/javascript" src="views/whisper_view_test.js"></script>
<script type="text/javascript" src="views/group_update_view_test.js"></script>
<script type="text/javascript" src="views/message_view_test.js"></script>
<script type="text/javascript" src="views/attachment_view_test.js"></script>
<script type="text/javascript" src="views/timestamp_view_test.js"></script>
<script type="text/javascript" src="views/list_view_test.js"></script>
<script type="text/javascript" src="views/conversation_search_view_test.js"></script>

View file

@ -1,9 +0,0 @@
describe('AttachmentView', function() {
it('should display an error for an unsupported type', function() {
var attachment = { contentType: 'html/text' };
var view = new Whisper.AttachmentView({model: attachment}).render();
assert.match(view.$el.text(), /Sorry, your attachment has a type, html, that is not currently supported./);
});
});

View file

@ -0,0 +1,27 @@
describe('AttachmentView', function() {
it('should render a data url for arbitrary content', function() {
var attachment = { contentType: 'arbitrary/content' };
var view = new Whisper.AttachmentView({model: attachment}).render();
assert.equal(view.el.firstChild.tagName, "A");
});
it('should render an image for images', function() {
var now = new Date().getTime();
var attachment = { contentType: 'image/png', data: 'grumpy cat' };
var view = new Whisper.AttachmentView({model: attachment, timestamp: now}).render();
assert.equal(view.el.firstChild.tagName, "IMG");
});
it('shoud have correct filename format', function() {
var epoch = new Date((new Date(0)).getTimezoneOffset() * 60 * 1000);
var attachment = { contentType: 'image/png', data: 'grumpy cat' };
var result = new Whisper.AttachmentView({
model: attachment,
timestamp: epoch
}).suggestedName();
var expected = '1970-01-01-000000';
assert(result === 'signal-' + expected + '.png');
});
});