Explorar o código

style: clarify and fix some style/code cleanup issues

rugk hai 3 meses
pai
achega
8e8dbb2ed5
Modificáronse 2 ficheiros con 17 adicións e 15 borrados
  1. 6 6
      js/privatebin.js
  2. 11 9
      js/test/AttachmentViewer.js

+ 6 - 6
js/privatebin.js

@@ -2424,7 +2424,6 @@ window.PrivateBin = (function () {
          */
         function viewEditor(event) {
             // toggle buttons
-
             messageEdit.classList.add('active');
             messageEditParent.classList.add('active');
             messagePreview.classList.remove('active');
@@ -3076,7 +3075,7 @@ window.PrivateBin = (function () {
          *
          * @name AttachmentViewer.hasAttachmentPreview
          * @function
-         * @return {JQuery}
+         * @return {boolean}
          */
         me.hasAttachmentPreview = function () {
             return attachmentPreview.children.length > 0;
@@ -3228,12 +3227,13 @@ window.PrivateBin = (function () {
          *
          * @name   AttachmentViewer.handleBlobAttachmentPreview
          * @function
-         * @argument {HTMLElement} targetElement element where the preview should be appended
-         * @argument {string} file as a blob URL
-         * @argument {string} mime type
+         * @argument {HTMLElement?} targetElement element where the preview should be appended
+         * @argument {string} blobUrl as a blob URL
+         * @argument {string} mimeType type
          */
         me.handleBlobAttachmentPreview = function (targetElement, blobUrl, mimeType) {
-            if (targetElement === null) {
+            if (!targetElement) {
+                console.log('Attachment preview element not found/disabled, cannot show attachment preview.');
                 return;
             }
 

+ 11 - 9
js/test/AttachmentViewer.js

@@ -2,16 +2,16 @@
 const common = require('../common');
 
 describe('AttachmentViewer', function () {
-    describe('setAttachment, showAttachment, removeAttachment, hideAttachment, hideAttachmentPreview, hasAttachment, getAttachment & moveAttachmentTo', function () {
-        this.timeout(30000);
+    beforeEach(() => {
+        mockCreateObjectUrl();
+    });
 
-        beforeEach(() => {
-            mockCreateObjectUrl();
-        });
+    afterEach(() => {
+        globalThis.cleanup()
+    });
 
-        afterEach(() => {
-            globalThis.cleanup()
-        });
+    describe('whole run (setAttachment, showAttachment, removeAttachment, hideAttachment, hideAttachmentPreview, hasAttachment, getAttachment & moveAttachmentTo)', function () {
+        this.timeout(30000);
 
         jsc.property(
             'displays & hides data as requested',
@@ -155,7 +155,9 @@ describe('AttachmentViewer', function () {
                 }
             }
         );
+    });
 
+    describe('showAttachment()', function () {
         it('displays attachment even when attachmentPreview element is missing',
             function() {
                 document.body.innerHTML = (
@@ -183,7 +185,7 @@ describe('AttachmentViewer', function () {
                 assert.ok(!attachment.classList.contains('hidden'), 'Attachment should be visible');
                 assert.ok(attachment.children.length > 0, 'Attachment should have content');
             }
-        );
+        )
     });
 
     function mockCreateObjectUrl() {