'use strict'; var common = require('../common'); describe('AttachmentViewer', function () { describe('setAttachment, showAttachment, removeAttachment, hideAttachment, hideAttachmentPreview, hasAttachment, getAttachment & moveAttachmentTo', function () { this.timeout(30000); jsc.property( 'displays & hides data as requested', common.jscMimeTypes(), 'string', 'string', 'string', 'string', function (mimeType, rawdata, filename, prefix, postfix) { let clean = jsdom(), data = 'data:' + mimeType + ';base64,' + btoa(rawdata), previewSupported = ( mimeType.substring(0, 6) === 'image/' || mimeType.substring(0, 6) === 'audio/' || mimeType.substring(0, 6) === 'video/' || mimeType.match(/\/pdf/i) ), results = [], result = ''; prefix = prefix.replace(/%(s|d)/g, '%%'); postfix = postfix.replace(/%(s|d)/g, '%%'); $('body').html( '
' ); $.PrivateBin.AttachmentViewer.init(); results.push( !$.PrivateBin.AttachmentViewer.hasAttachment() && $('#attachment').hasClass('hidden') && $('#attachmentPreview').hasClass('hidden') ); if (filename.length) { $.PrivateBin.AttachmentViewer.setAttachment(data, filename); } else { $.PrivateBin.AttachmentViewer.setAttachment(data); } const attachment = $.PrivateBin.AttachmentViewer.getAttachment(); results.push( $.PrivateBin.AttachmentViewer.hasAttachment() && $('#attachment').hasClass('hidden') && $('#attachmentPreview').hasClass('hidden') && attachment[0] === data && attachment[1] === filename ); $.PrivateBin.AttachmentViewer.showAttachment(); results.push( !$('#attachment').hasClass('hidden') && (previewSupported ? !$('#attachmentPreview').hasClass('hidden') : $('#attachmentPreview').hasClass('hidden')) ); $.PrivateBin.AttachmentViewer.hideAttachment(); results.push( $('#attachment').hasClass('hidden') && (previewSupported ? !$('#attachmentPreview').hasClass('hidden') : $('#attachmentPreview').hasClass('hidden')) ); if (previewSupported) { $.PrivateBin.AttachmentViewer.hideAttachmentPreview(); results.push($('#attachmentPreview').hasClass('hidden')); } $.PrivateBin.AttachmentViewer.showAttachment(); results.push( !$('#attachment').hasClass('hidden') && (previewSupported ? !$('#attachmentPreview').hasClass('hidden') : $('#attachmentPreview').hasClass('hidden')) ); let element = $('