UiHelper.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. 'use strict';
  2. var common = require('../common');
  3. describe('UiHelper', function () {
  4. // TODO: As per https://github.com/tmpvar/jsdom/issues/1565 there is no navigation support in jsdom, yet.
  5. // for now we use a mock function to trigger the event
  6. describe('historyChange', function () {
  7. this.timeout(30000);
  8. beforeEach(function () {
  9. $.PrivateBin.Helper.reset();
  10. cleanup();
  11. });
  12. jsc.property(
  13. 'redirects to home, when the state is null',
  14. common.jscUrl(false, false),
  15. function (url) {
  16. const expected = common.urlToString(url),
  17. clean = jsdom('', {url: expected});
  18. $.PrivateBin.UiHelper.mockHistoryChange();
  19. $.PrivateBin.Helper.reset();
  20. var result = window.location.href;
  21. clean();
  22. return expected === result;
  23. }
  24. );
  25. jsc.property(
  26. 'does not redirect to home, when a new document is created',
  27. common.jscUrl(false),
  28. jsc.nearray(common.jscBase64String()),
  29. function (url, fragment) {
  30. url.fragment = fragment.join('');
  31. const expected = common.urlToString(url),
  32. clean = jsdom('', {url: expected});
  33. $.PrivateBin.UiHelper.mockHistoryChange([
  34. {type: 'newpaste'}, '', expected
  35. ]);
  36. $.PrivateBin.Helper.reset();
  37. var result = window.location.href;
  38. clean();
  39. return expected === result;
  40. }
  41. );
  42. });
  43. describe('reloadHome', function () {
  44. // TODO triggers error messages in jsDOM since version 11
  45. /*
  46. this.timeout(30000);
  47. before(function () {
  48. $.PrivateBin.Helper.reset();
  49. });
  50. jsc.property(
  51. 'redirects to home',
  52. common.jscUrl(),
  53. function (url) {
  54. const clean = jsdom('', {url: common.urlToString(url)});
  55. delete(url.query);
  56. delete(url.fragment);
  57. const expected = common.urlToString(url);
  58. $.PrivateBin.UiHelper.reloadHome();
  59. $.PrivateBin.Helper.reset();
  60. var result = window.location.href;
  61. clean();
  62. return expected === result;
  63. }
  64. );
  65. */
  66. });
  67. describe('isVisible', function () {
  68. // TODO As per https://github.com/tmpvar/jsdom/issues/1048 there is no layout support in jsdom, yet.
  69. // once it is supported or a workaround is found, uncomment the section below
  70. /*
  71. before(function () {
  72. $.PrivateBin.Helper.reset();
  73. });
  74. jsc.property(
  75. 'detect visible elements',
  76. jsc.nearray(common.jscAlnumString()),
  77. jsc.nearray(common.jscA2zString()),
  78. function (id, element) {
  79. id = id.join('');
  80. element = element.join('');
  81. var clean = jsdom(
  82. '<' + element + ' id="' + id + '"></' + element + '>'
  83. );
  84. var result = $.PrivateBin.UiHelper.isVisible($('#' + id));
  85. clean();
  86. return result;
  87. }
  88. );
  89. */
  90. });
  91. describe('scrollTo', function () {
  92. // TODO Did not find a way to test that, see isVisible test above
  93. });
  94. });