From c4830044f7dc51d724db63d4adb8917476190eb5 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sun, 28 Jun 2020 13:05:47 +0200 Subject: [PATCH] adding some simple non-stored logic to test the interface --- js/privatebin.js | 17 +++++++++++++++-- js/test/Memory.js | 32 +++++++++++++++++++++++++++++++- tpl/bootstrap.php | 11 ++++++++++- tpl/page.php | 2 +- 4 files changed, 57 insertions(+), 5 deletions(-) diff --git a/js/privatebin.js b/js/privatebin.js index d3977cf1..150a126f 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -4362,9 +4362,11 @@ jQuery.PrivateBin = (function($, RawDeflate) { * @name Memory * @class */ - const Memory = (function () { + const Memory = (function (document) { const me = {}; + let urls = []; + /** * adds a paste URL to the memory * @@ -4375,6 +4377,7 @@ jQuery.PrivateBin = (function($, RawDeflate) { */ me.add = function(pasteUrl) { + urls.push(pasteUrl); return true; }; @@ -4386,6 +4389,15 @@ jQuery.PrivateBin = (function($, RawDeflate) { */ me.refreshList = function() { + const $tbody = $('#sidebar-wrapper table tbody')[0]; + $tbody.textContent = ''; + urls.forEach(function(url) { + const row = document.createElement('tr'), + cell = document.createElement('td'); + cell.textContent = url; + row.appendChild(cell); + $tbody.appendChild(row); + }); }; /** @@ -4398,6 +4410,7 @@ jQuery.PrivateBin = (function($, RawDeflate) { */ me.init = function() { + urls = []; $("#menu-toggle").on('click', function(e) { e.preventDefault(); $("main").toggleClass("toggled"); @@ -4406,7 +4419,7 @@ jQuery.PrivateBin = (function($, RawDeflate) { }; return me; - })(); + })(document); /** * Responsible for AJAX requests, transparently handles encryption… diff --git a/js/test/Memory.js b/js/test/Memory.js index 7a9d036f..deee173c 100644 --- a/js/test/Memory.js +++ b/js/test/Memory.js @@ -1,7 +1,37 @@ 'use strict'; -require('../common'); +const common = require('../common'); describe('Memory', function () { + describe('add & refreshList', function () { + this.timeout(30000); + + jsc.property( + 'allows adding valid paste URLs', + common.jscSchemas(), + jsc.nearray(common.jscA2zString()), + jsc.array(common.jscQueryString()), + 'string', + function (schema, address, query, fragment) { + const expected = schema + '://' + address.join('') + '/?' + + encodeURI( + query.join('').replace(/^&+|&+$/gm,'') + '#' + fragment + ), + clean = jsdom(); + $('body').html( + '
' + ); + // clear cache, then the first cell will match what we add + $.PrivateBin.Memory.init(); + $.PrivateBin.Memory.add(expected); + $.PrivateBin.Memory.refreshList(); + const result = $('#sidebar-wrapper table tbody tr td')[0].textContent; + clean(); + return result === expected; + } + ); + }); + describe('init', function () { it( 'enables toggling the memory sidebar', diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index 976787f4..1816d806 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -72,7 +72,7 @@ endif; ?> - + @@ -450,6 +450,15 @@ endif;
- +