'use strict'; var common = require('../common'); describe('TopNav', function () { describe('showViewButtons & hideViewButtons', function () { before(function () { cleanup(); }); it( 'displays & hides navigation elements for viewing an existing paste', function () { var results = []; $('body').html( '' ); $.PrivateBin.TopNav.init(); results.push( $('#newbutton').hasClass('hidden') && $('#clonebutton').hasClass('hidden') && $('#rawtextbutton').hasClass('hidden') && $('#qrcodelink').hasClass('hidden') ); $.PrivateBin.TopNav.showViewButtons(); results.push( !$('#newbutton').hasClass('hidden') && !$('#clonebutton').hasClass('hidden') && !$('#rawtextbutton').hasClass('hidden') && !$('#qrcodelink').hasClass('hidden') ); $.PrivateBin.TopNav.hideViewButtons(); results.push( $('#newbutton').hasClass('hidden') && $('#clonebutton').hasClass('hidden') && $('#rawtextbutton').hasClass('hidden') && $('#qrcodelink').hasClass('hidden') ); cleanup(); assert.ok(results.every(element => element)); } ); }); describe('showCreateButtons & hideCreateButtons', function () { before(function () { cleanup(); }); it( 'displays & hides navigation elements for creating a paste', function () { var results = []; $('body').html( '' ); $.PrivateBin.TopNav.init(); results.push( $('#sendbutton').hasClass('hidden') && $('#expiration').hasClass('hidden') && $('#formatter').hasClass('hidden') && $('#burnafterreadingoption').hasClass('hidden') && $('#opendiscussionoption').hasClass('hidden') && $('#newbutton').hasClass('hidden') && $('#password').hasClass('hidden') && $('#attach').hasClass('hidden') ); $.PrivateBin.TopNav.showCreateButtons(); results.push( !$('#sendbutton').hasClass('hidden') && !$('#expiration').hasClass('hidden') && !$('#formatter').hasClass('hidden') && !$('#burnafterreadingoption').hasClass('hidden') && !$('#opendiscussionoption').hasClass('hidden') && !$('#newbutton').hasClass('hidden') && !$('#password').hasClass('hidden') && !$('#attach').hasClass('hidden') ); $.PrivateBin.TopNav.hideCreateButtons(); results.push( $('#sendbutton').hasClass('hidden') && $('#expiration').hasClass('hidden') && $('#formatter').hasClass('hidden') && $('#burnafterreadingoption').hasClass('hidden') && $('#opendiscussionoption').hasClass('hidden') && $('#newbutton').hasClass('hidden') && $('#password').hasClass('hidden') && $('#attach').hasClass('hidden') ); cleanup(); assert.ok(results.every(element => element)); } ); }); describe('showNewPasteButton', function () { before(function () { cleanup(); }); it( 'displays the button for creating a paste', function () { var results = []; $('body').html( '' ); $.PrivateBin.TopNav.init(); results.push( $('#newbutton').hasClass('hidden') ); $.PrivateBin.TopNav.showNewPasteButton(); results.push( !$('#newbutton').hasClass('hidden') ); cleanup(); assert.ok(results.every(element => element)); } ); }); describe('hideCloneButton', function () { before(function () { cleanup(); }); it( 'hides the button for cloning a paste', function () { var results = []; $('body').html( '' ); $.PrivateBin.TopNav.init(); results.push( !$('#clonebutton').hasClass('hidden') ); $.PrivateBin.TopNav.hideCloneButton(); results.push( $('#clonebutton').hasClass('hidden') ); cleanup(); assert.ok(results.every(element => element)); } ); }); describe('hideRawButton', function () { before(function () { cleanup(); }); it( 'hides the raw text button', function () { var results = []; $('body').html( '' ); $.PrivateBin.TopNav.init(); results.push( !$('#rawtextbutton').hasClass('hidden') ); $.PrivateBin.TopNav.hideRawButton(); results.push( $('#rawtextbutton').hasClass('hidden') ); cleanup(); assert.ok(results.every(element => element)); } ); }); describe('hideFileSelector', function () { before(function () { cleanup(); }); it( 'hides the file attachment selection button', function () { var results = []; $('body').html( '' ); $.PrivateBin.TopNav.init(); results.push( !$('#filewrap').hasClass('hidden') ); $.PrivateBin.TopNav.hideFileSelector(); results.push( $('#filewrap').hasClass('hidden') ); cleanup(); assert.ok(results.every(element => element)); } ); }); describe('showCustomAttachment', function () { before(function () { cleanup(); }); it( 'display the custom file attachment', function () { var results = []; $('body').html( '' ); $.PrivateBin.TopNav.init(); results.push( $('#customattachment').hasClass('hidden') ); $.PrivateBin.TopNav.showCustomAttachment(); results.push( !$('#customattachment').hasClass('hidden') ); cleanup(); assert.ok(results.every(element => element)); } ); }); describe('collapseBar', function () { before(function () { cleanup(); }); it( 'collapses the navigation when displayed on a small screen', function () { var results = []; $('body').html( '' ); $.PrivateBin.TopNav.init(); results.push( $('.navbar-toggle').hasClass('collapsed') && $('#navbar').attr('aria-expanded') != 'true' ); $.PrivateBin.TopNav.collapseBar(); results.push( $('.navbar-toggle').hasClass('collapsed') && $('#navbar').attr('aria-expanded') != 'true' ); $('.navbar-toggle').click(); results.push( !$('.navbar-toggle').hasClass('collapsed') && $('#navbar').attr('aria-expanded') == 'true' ); $.PrivateBin.TopNav.collapseBar(); results.push( $('.navbar-toggle').hasClass('collapsed') && $('#navbar').attr('aria-expanded') == 'false' ); cleanup(); assert.ok(results.every(element => element)); } ); }); describe('getExpiration', function () { before(function () { cleanup(); }); it( 'returns the currently selected expiration date', function () { $.PrivateBin.TopNav.init(); assert.ok($.PrivateBin.TopNav.getExpiration() === '1week'); } ); }); describe('getFileList', function () { before(function () { cleanup(); }); var File = window.File, FileList = window.FileList, path = require('path'), mime = require('mime-types'); // mocking file input as per https://github.com/jsdom/jsdom/issues/1272 function createFile(file_path) { var file = fs.statSync(file_path), lastModified = file.mtimeMs, size = file.size; return new File( [new fs.readFileSync(file_path)], path.basename(file_path), { lastModified, type: mime.lookup(file_path) || '', } ) } function addFileList(input, file_paths) { if (typeof file_paths === 'string') file_paths = [file_paths] else if (!Array.isArray(file_paths)) { throw new Error('file_paths needs to be a file path string or an Array of file path strings') } const file_list = file_paths.map(fp => createFile(fp)) file_list.__proto__ = Object.create(FileList.prototype) Object.defineProperty(input, 'files', { value: file_list, writeable: false, }) return input } it( 'returns the selected files', function () { var results = []; $('body').html( '' ); $.PrivateBin.TopNav.init(); results.push( $.PrivateBin.TopNav.getFileList() === null ); addFileList($('#file')[0], [ '../img/logo.svg', '../img/busy.gif' ]); var files = $.PrivateBin.TopNav.getFileList(); results.push( files[0].name === 'logo.svg' && files[1].name === 'busy.gif' ); cleanup(); assert.ok(results.every(element => element)); } ); }); });