Commit 09e69317 authored by Denys Mishunov's avatar Denys Mishunov Committed by Paul Slaughter

Do not prevent page re-load on save

When saving a snippet, do not prevent page reload if there were
changes to the blob.
parent 3926bfcc
...@@ -116,7 +116,7 @@ export default { ...@@ -116,7 +116,7 @@ export default {
onBeforeUnload(e = {}) { onBeforeUnload(e = {}) {
const returnValue = __('Are you sure you want to lose unsaved changes?'); const returnValue = __('Are you sure you want to lose unsaved changes?');
if (!this.allBlobChangesRegistered) return undefined; if (!this.allBlobChangesRegistered || this.isUpdating) return undefined;
Object.assign(e, { returnValue }); Object.assign(e, { returnValue });
return returnValue; return returnValue;
......
...@@ -388,42 +388,49 @@ describe('Snippet Edit app', () => { ...@@ -388,42 +388,49 @@ describe('Snippet Edit app', () => {
returnValueSetter = jest.spyOn(event, 'returnValue', 'set'); returnValueSetter = jest.spyOn(event, 'returnValue', 'set');
}; };
it('does not prevent page navigation if there are no blobs', () => { const actionsWithoutAction = {
bootstrap(); blobsActions: {
window.dispatchEvent(event); foo: {
...actionWithContent,
expect(returnValueSetter).not.toHaveBeenCalled(); action: '',
});
it('does not prevent page navigation if there are no changes to the blobs content', () => {
bootstrap({
blobsActions: {
foo: {
...actionWithContent,
action: '',
},
}, },
}); },
window.dispatchEvent(event); };
const actionsWithUpdate = {
expect(returnValueSetter).not.toHaveBeenCalled(); blobsActions: {
}); foo: {
...actionWithContent,
it('prevents page navigation if there are some changes in the snippet content', () => { action: 'update',
bootstrap({
blobsActions: {
foo: {
...actionWithContent,
action: 'update',
},
}, },
}); },
};
const actionsWithUpdateWhileSaving = {
blobsActions: {
foo: {
...actionWithContent,
action: 'update',
},
},
isUpdating: true,
};
it.each`
bool | expectToBePrevented | data | condition
${'does not prevent'} | ${false} | ${undefined} | ${'there are no blobs'}
${'does not prevent'} | ${false} | ${actionsWithoutAction} | ${'there are no changes to the blobs content'}
${'prevents'} | ${true} | ${actionsWithUpdate} | ${'there are changes to the blobs content'}
${'does not prevent'} | ${false} | ${actionsWithUpdateWhileSaving} | ${'the snippet is being saved'}
`('$bool page navigation if $condition', ({ expectToBePrevented, data }) => {
bootstrap(data);
window.dispatchEvent(event); window.dispatchEvent(event);
expect(returnValueSetter).toHaveBeenCalledWith( if (expectToBePrevented) {
'Are you sure you want to lose unsaved changes?', expect(returnValueSetter).toHaveBeenCalledWith(
); 'Are you sure you want to lose unsaved changes?',
);
} else {
expect(returnValueSetter).not.toHaveBeenCalled();
}
}); });
}); });
}); });
......
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