Commit 5ad67efb authored by Paul Slaughter's avatar Paul Slaughter

Merge branch '229849-page-reload-on-snippet-save' into 'master'

Resolve "Confirmation pops up when saving a snippet"

See merge request gitlab-org/gitlab!37211
parents 97dd1f65 09e69317
...@@ -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