From 76debde85b5041aed6317979536d7094046bb65b Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sat, 3 Mar 2018 07:55:27 +0100 Subject: [PATCH] found and fixed a bug in TopNav.collapseBar() while writing test for it --- js/privatebin.js | 8 +++----- js/test/TopNav.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ tpl/bootstrap.php | 2 +- tpl/page.php | 2 +- 4 files changed, 50 insertions(+), 7 deletions(-) diff --git a/js/privatebin.js b/js/privatebin.js index 395ac0e..a7c2207 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -2557,6 +2557,7 @@ jQuery.PrivateBin = (function($, sjcl, Base64, RawDeflate) { * Shows the QR code of the current paste (URL). * * @name TopNav.displayQrCode + * @private * @function */ function displayQrCode() @@ -2736,12 +2737,9 @@ jQuery.PrivateBin = (function($, sjcl, Base64, RawDeflate) { */ me.collapseBar = function() { - var $bar = $('.navbar-toggle'); - - // check if bar is expanded - if ($bar.hasClass('collapse in')) { + if ($('#navbar').attr('aria-expanded')) { // if so, toggle it - $bar.click(); + $('.navbar-toggle').click(); } }; diff --git a/js/test/TopNav.js b/js/test/TopNav.js index ba7ffad..5068376 100644 --- a/js/test/TopNav.js +++ b/js/test/TopNav.js @@ -271,5 +271,50 @@ describe('TopNav', function () { } ); }); + + 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)); + } + ); + }); }); diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index ee078fa..19f9e27 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -75,7 +75,7 @@ if ($MARKDOWN): - + diff --git a/tpl/page.php b/tpl/page.php index ac94a65..356c82a 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -54,7 +54,7 @@ if ($QRCODE): - +