1
0

UiHelper.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. 'use strict';
  2. const common = require('../common');
  3. const fc = require('fast-check');
  4. describe('UiHelper', function () {
  5. // TODO: As per https://github.com/tmpvar/jsdom/issues/1565 there is no navigation support in jsdom, yet.
  6. // for now we use a mock function to trigger the event
  7. describe('historyChange', function () {
  8. this.timeout(30000);
  9. beforeEach(function () {
  10. PrivateBin.Helper.reset();
  11. cleanup();
  12. });
  13. it('redirects to home, when the state is null', () => {
  14. fc.assert(fc.property(
  15. common.fcUrl(false, false),
  16. function (url) {
  17. const expected = common.urlToString(url),
  18. clean = globalThis.cleanup('', {url: expected});
  19. PrivateBin.UiHelper.mockHistoryChange();
  20. PrivateBin.Helper.reset();
  21. var result = window.location.href;
  22. clean();
  23. return expected === result;
  24. }
  25. ));
  26. });
  27. it('does not redirect to home, when a new document is created', () => {
  28. fc.assert(fc.property(
  29. common.fcUrl(false),
  30. fc.array(common.fcBase64String(), {minLength: 1}),
  31. function (url, fragment) {
  32. url.fragment = fragment.join('');
  33. const expected = common.urlToString(url),
  34. clean = globalThis.cleanup('', {url: expected});
  35. PrivateBin.UiHelper.mockHistoryChange([
  36. {type: 'newpaste'}, '', expected
  37. ]);
  38. PrivateBin.Helper.reset();
  39. var result = window.location.href;
  40. clean();
  41. return expected === result;
  42. }
  43. ));
  44. });
  45. });
  46. describe('reloadHome', function () {
  47. // TODO triggers error messages in jsDOM since version 11
  48. /*
  49. this.timeout(30000);
  50. before(function () {
  51. PrivateBin.Helper.reset();
  52. });
  53. it('redirects to home', () => {
  54. fc.assert(fc.property(
  55. common.fcUrl(),
  56. function (url) {
  57. const clean = globalThis.cleanup('', {url: common.urlToString(url)});
  58. delete(url.query);
  59. delete(url.fragment);
  60. const expected = common.urlToString(url);
  61. PrivateBin.UiHelper.reloadHome();
  62. PrivateBin.Helper.reset();
  63. var result = window.location.href;
  64. clean();
  65. return expected === result;
  66. }
  67. ));
  68. });
  69. */
  70. });
  71. });