adding some simple non-stored logic to test the interface

This commit is contained in:
El RIDO 2020-06-28 13:05:47 +02:00
parent daae0d0dca
commit c4830044f7
No known key found for this signature in database
GPG key ID: 0F5C940A6BD81F92
4 changed files with 57 additions and 5 deletions

View file

@ -4362,9 +4362,11 @@ jQuery.PrivateBin = (function($, RawDeflate) {
* @name Memory * @name Memory
* @class * @class
*/ */
const Memory = (function () { const Memory = (function (document) {
const me = {}; const me = {};
let urls = [];
/** /**
* adds a paste URL to the memory * adds a paste URL to the memory
* *
@ -4375,6 +4377,7 @@ jQuery.PrivateBin = (function($, RawDeflate) {
*/ */
me.add = function(pasteUrl) me.add = function(pasteUrl)
{ {
urls.push(pasteUrl);
return true; return true;
}; };
@ -4386,6 +4389,15 @@ jQuery.PrivateBin = (function($, RawDeflate) {
*/ */
me.refreshList = function() 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() me.init = function()
{ {
urls = [];
$("#menu-toggle").on('click', function(e) { $("#menu-toggle").on('click', function(e) {
e.preventDefault(); e.preventDefault();
$("main").toggleClass("toggled"); $("main").toggleClass("toggled");
@ -4406,7 +4419,7 @@ jQuery.PrivateBin = (function($, RawDeflate) {
}; };
return me; return me;
})(); })(document);
/** /**
* Responsible for AJAX requests, transparently handles encryption * Responsible for AJAX requests, transparently handles encryption

View file

@ -1,7 +1,37 @@
'use strict'; 'use strict';
require('../common'); const common = require('../common');
describe('Memory', function () { 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(
'<main><div id="sidebar-wrapper"><table><tbody>' +
'</tbody></table></div></main>'
);
// 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 () { describe('init', function () {
it( it(
'enables toggling the memory sidebar', 'enables toggling the memory sidebar',

View file

@ -72,7 +72,7 @@ endif;
?> ?>
<script type="text/javascript" data-cfasync="false" src="js/purify-2.0.8.js" integrity="sha512-QwcEKGuEmKtMguCO9pqNtUtZqq9b/tJ8gNr5qhY8hykq3zKTlDOvpZAmf6Rs8yH35Bz1ZdctUjj2qEWxT5aXCg==" crossorigin="anonymous"></script> <script type="text/javascript" data-cfasync="false" src="js/purify-2.0.8.js" integrity="sha512-QwcEKGuEmKtMguCO9pqNtUtZqq9b/tJ8gNr5qhY8hykq3zKTlDOvpZAmf6Rs8yH35Bz1ZdctUjj2qEWxT5aXCg==" crossorigin="anonymous"></script>
<script type="text/javascript" data-cfasync="false" src="js/legacy.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-LYos+qXHIRqFf5ZPNphvtTB0cgzHUizu2wwcOwcwz/VIpRv9lpcBgPYz4uq6jx0INwCAj6Fbnl5HoKiLufS2jg==" crossorigin="anonymous"></script> <script type="text/javascript" data-cfasync="false" src="js/legacy.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-LYos+qXHIRqFf5ZPNphvtTB0cgzHUizu2wwcOwcwz/VIpRv9lpcBgPYz4uq6jx0INwCAj6Fbnl5HoKiLufS2jg==" crossorigin="anonymous"></script>
<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-0dH2jwB9G3WPKEuSqYz5//MbCKQObNZx+rmQwmH3PKnVsTFrUG8EqV88U2iy0qj2rlNBNiytbJZ1CmRGJJ6YbQ==" crossorigin="anonymous"></script> <script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-Ney+hSdITdWT9OPVLg0O3HLbaHKVO64fV/M+cUmKBOsMibv9Dsrug5jQRk17lebetk3jOPL0LyvBy+nAkAcFbw==" crossorigin="anonymous"></script>
<!-- icon --> <!-- icon -->
<link rel="apple-touch-icon" href="img/apple-touch-icon.png?<?php echo rawurlencode($VERSION); ?>" sizes="180x180" /> <link rel="apple-touch-icon" href="img/apple-touch-icon.png?<?php echo rawurlencode($VERSION); ?>" sizes="180x180" />
<link rel="icon" type="image/png" href="img/favicon-32x32.png?<?php echo rawurlencode($VERSION); ?>" sizes="32x32" /> <link rel="icon" type="image/png" href="img/favicon-32x32.png?<?php echo rawurlencode($VERSION); ?>" sizes="32x32" />
@ -450,6 +450,15 @@ endif;
<div id="sidebar-wrapper"> <div id="sidebar-wrapper">
<h4><?php echo I18n::_('Memory'); ?></h4> <h4><?php echo I18n::_('Memory'); ?></h4>
<p><?php echo I18n::_('The memory lets you remember different paste links. The memory is unique to each website and device.'); ?></p> <p><?php echo I18n::_('The memory lets you remember different paste links. The memory is unique to each website and device.'); ?></p>
<table>
<thead>
<tr>
<th>URL</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div> </div>
<section class="container"> <section class="container">
<?php <?php

View file

@ -50,7 +50,7 @@ endif;
?> ?>
<script type="text/javascript" data-cfasync="false" src="js/purify-2.0.8.js" integrity="sha512-QwcEKGuEmKtMguCO9pqNtUtZqq9b/tJ8gNr5qhY8hykq3zKTlDOvpZAmf6Rs8yH35Bz1ZdctUjj2qEWxT5aXCg==" crossorigin="anonymous"></script> <script type="text/javascript" data-cfasync="false" src="js/purify-2.0.8.js" integrity="sha512-QwcEKGuEmKtMguCO9pqNtUtZqq9b/tJ8gNr5qhY8hykq3zKTlDOvpZAmf6Rs8yH35Bz1ZdctUjj2qEWxT5aXCg==" crossorigin="anonymous"></script>
<script type="text/javascript" data-cfasync="false" src="js/legacy.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-LYos+qXHIRqFf5ZPNphvtTB0cgzHUizu2wwcOwcwz/VIpRv9lpcBgPYz4uq6jx0INwCAj6Fbnl5HoKiLufS2jg==" crossorigin="anonymous"></script> <script type="text/javascript" data-cfasync="false" src="js/legacy.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-LYos+qXHIRqFf5ZPNphvtTB0cgzHUizu2wwcOwcwz/VIpRv9lpcBgPYz4uq6jx0INwCAj6Fbnl5HoKiLufS2jg==" crossorigin="anonymous"></script>
<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-0dH2jwB9G3WPKEuSqYz5//MbCKQObNZx+rmQwmH3PKnVsTFrUG8EqV88U2iy0qj2rlNBNiytbJZ1CmRGJJ6YbQ==" crossorigin="anonymous"></script> <script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-Ney+hSdITdWT9OPVLg0O3HLbaHKVO64fV/M+cUmKBOsMibv9Dsrug5jQRk17lebetk3jOPL0LyvBy+nAkAcFbw==" crossorigin="anonymous"></script>
<!-- icon --> <!-- icon -->
<link rel="apple-touch-icon" href="img/apple-touch-icon.png?<?php echo rawurlencode($VERSION); ?>" sizes="180x180" /> <link rel="apple-touch-icon" href="img/apple-touch-icon.png?<?php echo rawurlencode($VERSION); ?>" sizes="180x180" />
<link rel="icon" type="image/png" href="img/favicon-32x32.png?<?php echo rawurlencode($VERSION); ?>" sizes="32x32" /> <link rel="icon" type="image/png" href="img/favicon-32x32.png?<?php echo rawurlencode($VERSION); ?>" sizes="32x32" />