Browse Source

Add attachment_views_test.js tests

Blake Griffith 7 years ago
parent
commit
1e498294e0
4 changed files with 37 additions and 15 deletions
  1. 9 6
      js/views/attachment_view.js
  2. 1 0
      test/index.html
  3. 0 9
      test/views/attachment_view.js
  4. 27 0
      test/views/attachment_view_test.js

+ 9 - 6
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;

+ 1 - 0
test/index.html

@@ -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>

+ 0 - 9
test/views/attachment_view.js

@@ -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./);
-  });
-
-});

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