PasteStatus.js 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. 'use strict';
  2. var common = require('../common');
  3. describe('PasteStatus', function () {
  4. describe('createPasteNotification', function () {
  5. this.timeout(30000);
  6. jsc.property(
  7. 'creates a notification after a successfull paste upload',
  8. common.jscSchemas(),
  9. jsc.nearray(common.jscA2zString()),
  10. jsc.array(common.jscQueryString()),
  11. 'string',
  12. common.jscSchemas(),
  13. jsc.nearray(common.jscA2zString()),
  14. jsc.array(common.jscQueryString()),
  15. function (
  16. schema1, address1, query1, fragment1,
  17. schema2, address2, query2
  18. ) {
  19. var expected1 = schema1 + '://' + address1.join('') + '/?' +
  20. encodeURI(query1.join('').replace(/^&+|&+$/gm,'') + '#' + fragment1),
  21. expected2 = schema2 + '://' + address2.join('') + '/?' +
  22. encodeURI(query2.join('').replace(/^&+|&+$/gm,'')),
  23. clean = jsdom();
  24. $('body').html('<div><div id="deletelink"></div><div id="pastelink"></div></div>');
  25. $.PrivateBin.PasteStatus.init();
  26. $.PrivateBin.PasteStatus.createPasteNotification(expected1, expected2);
  27. var result1 = $('#pasteurl')[0].href,
  28. result2 = $('#deletelink a')[0].href;
  29. clean();
  30. return result1 === expected1 && result2 === expected2;
  31. }
  32. );
  33. });
  34. describe('showRemainingTime', function () {
  35. this.timeout(30000);
  36. jsc.property(
  37. 'shows burn after reading message or remaining time',
  38. 'bool',
  39. 'nat',
  40. jsc.nearray(common.jscA2zString()),
  41. jsc.nearray(common.jscA2zString()),
  42. jsc.nearray(common.jscQueryString()),
  43. 'string',
  44. function (
  45. burnafterreading, remainingTime,
  46. schema, address, query, fragment
  47. ) {
  48. var clean = jsdom('', {
  49. url: schema.join('') + '://' + address.join('') +
  50. '/?' + query.join('') + '#' + fragment
  51. }),
  52. result;
  53. $('body').html('<div id="remainingtime" class="hidden"></div>');
  54. $.PrivateBin.PasteStatus.init();
  55. $.PrivateBin.PasteStatus.showRemainingTime({
  56. 'burnafterreading': burnafterreading,
  57. 'remaining_time': remainingTime,
  58. 'expire_date': remainingTime ? ((new Date()).getTime() / 1000) + remainingTime : 0
  59. });
  60. if (burnafterreading) {
  61. result = $('#remainingtime').hasClass('foryoureyesonly') &&
  62. !$('#remainingtime').hasClass('hidden');
  63. } else if (remainingTime) {
  64. result =!$('#remainingtime').hasClass('foryoureyesonly') &&
  65. !$('#remainingtime').hasClass('hidden');
  66. } else {
  67. result = $('#remainingtime').hasClass('hidden') &&
  68. !$('#remainingtime').hasClass('foryoureyesonly');
  69. }
  70. clean();
  71. return result;
  72. }
  73. );
  74. });
  75. describe('hideMessages', function () {
  76. it(
  77. 'hides all messages',
  78. function() {
  79. $('body').html(
  80. '<div id="remainingtime"></div><div id="pastesuccess"></div>'
  81. );
  82. $.PrivateBin.PasteStatus.init();
  83. $.PrivateBin.PasteStatus.hideMessages();
  84. assert.ok(
  85. $('#remainingtime').hasClass('hidden') &&
  86. $('#pastesuccess').hasClass('hidden')
  87. );
  88. }
  89. );
  90. });
  91. });