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');
+ });
+});