summaryrefslogtreecommitdiff
path: root/spec/frontend/snippets/components/edit_spec.js
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 21:09:23 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 21:09:23 +0000
commit192bc8bd3109f30e957bf30a0139ae27fefd7936 (patch)
tree61c8c415c765900386ac43ea0a5a8a5ce94366b6 /spec/frontend/snippets/components/edit_spec.js
parentbf213f07c8146b7121240af90a07cb4b2ecc41fa (diff)
downloadgitlab-ce-192bc8bd3109f30e957bf30a0139ae27fefd7936.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.js69
1 files changed, 38 insertions, 31 deletions
diff --git a/spec/frontend/snippets/components/edit_spec.js b/spec/frontend/snippets/components/edit_spec.js
index 6149ecbf00c..0148439d74c 100644
--- a/spec/frontend/snippets/components/edit_spec.js
+++ b/spec/frontend/snippets/components/edit_spec.js
@@ -388,42 +388,49 @@ describe('Snippet Edit app', () => {
returnValueSetter = jest.spyOn(event, 'returnValue', 'set');
};
- it('does not prevent page navigation if there are no blobs', () => {
- 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: {
- foo: {
- ...actionWithContent,
- action: '',
- },
+ const actionsWithoutAction = {
+ blobsActions: {
+ foo: {
+ ...actionWithContent,
+ action: '',
},
- });
- window.dispatchEvent(event);
-
- expect(returnValueSetter).not.toHaveBeenCalled();
- });
-
- it('prevents page navigation if there are some changes in the snippet content', () => {
- bootstrap({
- blobsActions: {
- foo: {
- ...actionWithContent,
- action: 'update',
- },
+ },
+ };
+ const actionsWithUpdate = {
+ 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);
- expect(returnValueSetter).toHaveBeenCalledWith(
- 'Are you sure you want to lose unsaved changes?',
- );
+ if (expectToBePrevented) {
+ expect(returnValueSetter).toHaveBeenCalledWith(
+ 'Are you sure you want to lose unsaved changes?',
+ );
+ } else {
+ expect(returnValueSetter).not.toHaveBeenCalled();
+ }
});
});
});