Memory.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. 'use strict';
  2. const common = require('../common');
  3. describe('Memory', function () {
  4. describe('add & refreshList', function () {
  5. this.timeout(30000);
  6. jsc.property(
  7. 'allows adding valid paste URLs',
  8. common.jscSchemas(),
  9. jsc.nearray(common.jscA2zString()),
  10. jsc.array(common.jscQueryString()),
  11. 'string',
  12. function (schema, address, query, fragment) {
  13. const expected = schema + '://' + address.join('') + '/?' +
  14. encodeURI(
  15. query.join('').replace(/^&+|&+$/gm,'') + '#' + fragment
  16. ),
  17. clean = jsdom();
  18. $('body').html(
  19. '<main><div id="sidebar-wrapper"><table><tbody>' +
  20. '</tbody></table></div></main>'
  21. );
  22. // clear cache, then the first cell will match what we add
  23. $.PrivateBin.Memory.init();
  24. $.PrivateBin.Memory.add(expected);
  25. $.PrivateBin.Memory.refreshList();
  26. const result = $('#sidebar-wrapper table tbody tr td')[0].textContent;
  27. clean();
  28. return result === expected;
  29. }
  30. );
  31. });
  32. describe('init', function () {
  33. it(
  34. 'enables toggling the memory sidebar',
  35. function() {
  36. $('body').html(
  37. '<main><div id="sidebar-wrapper"></div>' +
  38. '<button id="menu-toggle"></button></main>'
  39. );
  40. assert.ok(!$('main').hasClass('toggled'));
  41. $('#menu-toggle').click();
  42. assert.ok(!$('main').hasClass('toggled'));
  43. $.PrivateBin.Memory.init();
  44. assert.ok(!$('main').hasClass('toggled'));
  45. $('#menu-toggle').click();
  46. assert.ok($('main').hasClass('toggled'));
  47. $('#menu-toggle').click();
  48. assert.ok(!$('main').hasClass('toggled'));
  49. }
  50. );
  51. });
  52. });