PasteStatus.js 3.8 KB

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