From 1e498294e0e0eb9c1122836a6cc650b3b16ef5f7 Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Sun, 5 Feb 2017 18:59:20 -0800 Subject: [PATCH] Add attachment_views_test.js tests --- js/views/attachment_view.js | 15 +++++++++------ test/index.html | 1 + test/views/attachment_view.js | 9 --------- test/views/attachment_view_test.js | 27 +++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 15 deletions(-) delete mode 100644 test/views/attachment_view.js create mode 100644 test/views/attachment_view_test.js diff --git a/js/views/attachment_view.js b/js/views/attachment_view.js index 95e39c59..001388f6 100644 --- a/js/views/attachment_view.js +++ b/js/views/attachment_view.js @@ -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; diff --git a/test/index.html b/test/index.html index 6e7d30de..43063883 100644 --- a/test/index.html +++ b/test/index.html @@ -538,6 +538,7 @@ + diff --git a/test/views/attachment_view.js b/test/views/attachment_view.js deleted file mode 100644 index 8c588549..00000000 --- a/test/views/attachment_view.js +++ /dev/null @@ -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./); - }); - -}); diff --git a/test/views/attachment_view_test.js b/test/views/attachment_view_test.js new file mode 100644 index 00000000..dde939f1 --- /dev/null +++ b/test/views/attachment_view_test.js @@ -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'); + }); +});