|
|
@@ -3,8 +3,6 @@ const common = require('../common');
|
|
|
const fc = require('fast-check');
|
|
|
|
|
|
describe('UiHelper', function () {
|
|
|
- // TODO: As per https://github.com/tmpvar/jsdom/issues/1565 there is no navigation support in jsdom, yet.
|
|
|
- // for now we use a mock function to trigger the event
|
|
|
describe('historyChange', function () {
|
|
|
this.timeout(30000);
|
|
|
beforeEach(function () {
|
|
|
@@ -12,6 +10,19 @@ describe('UiHelper', function () {
|
|
|
cleanup();
|
|
|
});
|
|
|
|
|
|
+ function dispatchPopState(state = null) {
|
|
|
+ let eventError = null;
|
|
|
+ const captureError = event => {
|
|
|
+ eventError = event.error;
|
|
|
+ event.preventDefault();
|
|
|
+ };
|
|
|
+ window.addEventListener('error', captureError);
|
|
|
+ PrivateBin.UiHelper.init();
|
|
|
+ window.dispatchEvent(new window.PopStateEvent('popstate', {state: state}));
|
|
|
+ window.removeEventListener('error', captureError);
|
|
|
+ assert.strictEqual(eventError, null);
|
|
|
+ }
|
|
|
+
|
|
|
it('redirects to home, when the state is null', () => {
|
|
|
fc.assert(fc.property(
|
|
|
common.fcUrl(false, false),
|
|
|
@@ -19,7 +30,7 @@ describe('UiHelper', function () {
|
|
|
const expected = common.urlToString(url),
|
|
|
clean = globalThis.cleanup('', {url: expected});
|
|
|
|
|
|
- PrivateBin.UiHelper.mockHistoryChange();
|
|
|
+ dispatchPopState();
|
|
|
PrivateBin.Helper.reset();
|
|
|
var result = window.location.href;
|
|
|
clean();
|
|
|
@@ -37,7 +48,7 @@ describe('UiHelper', function () {
|
|
|
const expected = common.urlToString(url),
|
|
|
clean = globalThis.cleanup('', {url: expected});
|
|
|
|
|
|
- PrivateBin.UiHelper.mockHistoryChange([
|
|
|
+ dispatchPopState([
|
|
|
{type: 'newpaste'}, '', expected
|
|
|
]);
|
|
|
PrivateBin.Helper.reset();
|
|
|
@@ -77,4 +88,3 @@ describe('UiHelper', function () {
|
|
|
*/
|
|
|
});
|
|
|
});
|
|
|
-
|