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();
window.dispatchEvent(event);
expect(returnValueSetter).not.toHaveBeenCalled();
});
it('does not prevent page navigation if there are no changes to the blobs content', () => {
bootstrap({
blobsActions: { blobsActions: {
foo: { foo: {
...actionWithContent, ...actionWithContent,
action: '', action: '',
}, },
}, },
}); };
window.dispatchEvent(event); const actionsWithUpdate = {
expect(returnValueSetter).not.toHaveBeenCalled();
});
it('prevents page navigation if there are some changes in the snippet content', () => {
bootstrap({
blobsActions: { blobsActions: {
foo: { foo: {
...actionWithContent, ...actionWithContent,
action: 'update', 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);
if (expectToBePrevented) {
expect(returnValueSetter).toHaveBeenCalledWith( expect(returnValueSetter).toHaveBeenCalledWith(
'Are you sure you want to lose unsaved changes?', '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