summaryrefslogtreecommitdiff
path: root/spec/frontend/snippets/components/edit_spec.js
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-06-17 15:08:36 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-17 15:08:36 +0000
commitc61d90dbfa0a7cb58b758ed07a9d0b5406beb61e (patch)
tree5c29d476a605417c370997caf3dabe8e8270b8be /spec/frontend/snippets/components/edit_spec.js
parenta89912871cb169249d3ddc2ed59326d47ecdae82 (diff)
downloadgitlab-ce-c61d90dbfa0a7cb58b758ed07a9d0b5406beb61e.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/snippets/components/edit_spec.js')
-rw-r--r--spec/frontend/snippets/components/edit_spec.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/spec/frontend/snippets/components/edit_spec.js b/spec/frontend/snippets/components/edit_spec.js
index 83f46dd347f..664fc3733d4 100644
--- a/spec/frontend/snippets/components/edit_spec.js
+++ b/spec/frontend/snippets/components/edit_spec.js
@@ -307,6 +307,16 @@ describe('Snippet Edit app', () => {
});
});
+ it('makes sure there are no unsaved changes in the snippet', () => {
+ createComponent();
+ clickSubmitBtn();
+
+ return waitForPromises().then(() => {
+ expect(wrapper.vm.originalContent).toBe(wrapper.vm.content);
+ expect(wrapper.vm.hasChanges()).toBe(false);
+ });
+ });
+
it.each`
newSnippet | projectPath | mutationName
${true} | ${rawProjectPathMock} | ${'CreateSnippetMutation with projectPath'}
@@ -419,5 +429,33 @@ describe('Snippet Edit app', () => {
expect(resolveMutate).toHaveBeenCalledWith(updateMutationPayload());
});
});
+
+ describe('on before unload', () => {
+ let event;
+ let returnValueSetter;
+
+ beforeEach(() => {
+ createComponent();
+
+ event = new Event('beforeunload');
+ returnValueSetter = jest.spyOn(event, 'returnValue', 'set');
+ });
+
+ it('does not prevent page navigation if there are no changes to the snippet content', () => {
+ window.dispatchEvent(event);
+
+ expect(returnValueSetter).not.toHaveBeenCalled();
+ });
+
+ it('prevents page navigation if there are some changes in the snippet content', () => {
+ wrapper.setData({ content: 'new content' });
+
+ window.dispatchEvent(event);
+
+ expect(returnValueSetter).toHaveBeenCalledWith(
+ 'Are you sure you want to lose unsaved changes?',
+ );
+ });
+ });
});
});