UiHelper.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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.jscSchemas(),
  15. jsc.nearray(common.jscA2zString()),
  16. function (schema, address) {
  17. var expected = schema + '://' + address.join('') + '/',
  18. clean = jsdom('', {url: expected});
  19. // make window.location.href writable
  20. Object.defineProperty(window.location, 'href', {
  21. writable: true,
  22. value: window.location.href
  23. });
  24. $.PrivateBin.UiHelper.mockHistoryChange();
  25. $.PrivateBin.Helper.reset();
  26. var result = window.location.href;
  27. clean();
  28. return expected === result;
  29. }
  30. );
  31. jsc.property(
  32. 'does not redirect to home, when a new paste is created',
  33. common.jscSchemas(),
  34. jsc.nearray(common.jscA2zString()),
  35. jsc.array(common.jscQueryString()),
  36. jsc.nearray(common.jscBase64String()),
  37. function (schema, address, query, fragment) {
  38. var expected = schema + '://' + address.join('') + '/?' +
  39. query.join('') + '#' + fragment.join(''),
  40. clean = jsdom('', {url: expected});
  41. // make window.location.href writable
  42. Object.defineProperty(window.location, 'href', {
  43. writable: true,
  44. value: window.location.href
  45. });
  46. $.PrivateBin.UiHelper.mockHistoryChange([
  47. {type: 'newpaste'}, '', expected
  48. ]);
  49. $.PrivateBin.Helper.reset();
  50. var result = window.location.href;
  51. clean();
  52. return expected === result;
  53. }
  54. );
  55. });
  56. describe('reloadHome', function () {
  57. this.timeout(30000);
  58. before(function () {
  59. $.PrivateBin.Helper.reset();
  60. });
  61. jsc.property(
  62. 'redirects to home',
  63. common.jscSchemas(),
  64. jsc.nearray(common.jscA2zString()),
  65. jsc.array(common.jscQueryString()),
  66. jsc.nearray(common.jscBase64String()),
  67. function (schema, address, query, fragment) {
  68. var expected = schema + '://' + address.join('') + '/',
  69. clean = jsdom('', {
  70. url: expected + '?' + query.join('') + '#' + fragment.join('')
  71. });
  72. // make window.location.href writable
  73. Object.defineProperty(window.location, 'href', {
  74. writable: true,
  75. value: window.location.href
  76. });
  77. $.PrivateBin.UiHelper.reloadHome();
  78. $.PrivateBin.Helper.reset();
  79. var result = window.location.href;
  80. clean();
  81. return expected === result;
  82. }
  83. );
  84. });
  85. describe('isVisible', function () {
  86. // TODO As per https://github.com/tmpvar/jsdom/issues/1048 there is no layout support in jsdom, yet.
  87. // once it is supported or a workaround is found, uncomment the section below
  88. /*
  89. before(function () {
  90. $.PrivateBin.Helper.reset();
  91. });
  92. jsc.property(
  93. 'detect visible elements',
  94. jsc.nearray(common.jscAlnumString()),
  95. jsc.nearray(common.jscA2zString()),
  96. function (id, element) {
  97. id = id.join('');
  98. element = element.join('');
  99. var clean = jsdom(
  100. '<' + element + ' id="' + id + '"></' + element + '>'
  101. );
  102. var result = $.PrivateBin.UiHelper.isVisible($('#' + id));
  103. clean();
  104. return result;
  105. }
  106. );
  107. */
  108. });
  109. describe('scrollTo', function () {
  110. // TODO Did not find a way to test that, see isVisible test above
  111. });
  112. });