Commit 5b7b4822 authored by Sam Bigelow's avatar Sam Bigelow Committed by Phil Hughes

Resolve "Warn in Web Editor when user navigates away"

parent 1fae9f36
......@@ -16,9 +16,17 @@ export default () => {
const filePath = editBlobForm.data('blobFilename');
const currentAction = $('.js-file-title').data('currentAction');
const projectId = editBlobForm.data('project-id');
const commitButton = $('.js-commit-button');
commitButton.on('click', () => {
window.onbeforeunload = null;
});
new EditBlob(`${urlRoot}${assetsPath}`, filePath, currentAction, projectId);
new NewCommitForm(editBlobForm);
// returning here blocks page navigation
window.onbeforeunload = () => '';
}
if (uploadBlobForm.length) {
......
---
title: Prevent user from navigating away from file edit without commit
merge_request:
author:
type: fixed
import blobBundle from '~/blob_edit/blob_bundle';
import $ from 'jquery';
window.ace = {
config: {
set: () => {},
loadModule: () => {},
},
edit: () => ({ focus: () => {} }),
};
describe('EditBlob', () => {
beforeEach(() => {
setFixtures(`
<div class="js-edit-blob-form">
<button class="js-commit-button"></button>
</div>`);
blobBundle();
});
it('sets the window beforeunload listener to a function returning a string', () => {
expect(window.onbeforeunload()).toBe('');
});
it('removes beforeunload listener if commit button is clicked', () => {
$('.js-commit-button').click();
expect(window.onbeforeunload).toBeNull();
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment