UiHelper.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 = globalThis.cleanup('', {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 = globalThis.cleanup('', {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 = globalThis.cleanup('', {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. });