summaryrefslogtreecommitdiff
path: root/spec/frontend/snippets/components/edit_spec.js
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-06-04 09:08:01 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-04 09:08:01 +0000
commitb3ce1ce45218454cc3f8b719d7748f8a467f36a3 (patch)
tree04deb813c4e1cd72afdf9af5e51c5500e1592f65 /spec/frontend/snippets/components/edit_spec.js
parentc66aadd2eeb98be7cb332cfbf73b31b686692444 (diff)
downloadgitlab-ce-b3ce1ce45218454cc3f8b719d7748f8a467f36a3.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.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/frontend/snippets/components/edit_spec.js b/spec/frontend/snippets/components/edit_spec.js
index aaaa774b7a0..c21aba5e251 100644
--- a/spec/frontend/snippets/components/edit_spec.js
+++ b/spec/frontend/snippets/components/edit_spec.js
@@ -38,6 +38,7 @@ const rawPathMock = '/foo/bar';
const rawProjectPathMock = '/project/path';
const newlyEditedSnippetUrl = 'http://foo.bar';
const apiError = { message: 'Ufff' };
+const mutationError = 'Bummer';
const defaultProps = {
snippetGid: 'gid://gitlab/PersonalSnippet/42',
@@ -60,10 +61,26 @@ describe('Snippet Edit app', () => {
},
});
+ const resolveMutateWithErrors = jest.fn().mockResolvedValue({
+ data: {
+ updateSnippet: {
+ errors: [mutationError],
+ snippet: {
+ webUrl: newlyEditedSnippetUrl,
+ },
+ },
+ createSnippet: {
+ errors: [mutationError],
+ snippet: null,
+ },
+ },
+ });
+
const rejectMutation = jest.fn().mockRejectedValue(apiError);
const mutationTypes = {
RESOLVE: resolveMutate,
+ RESOLVE_WITH_ERRORS: resolveMutateWithErrors,
REJECT: rejectMutation,
};
@@ -284,6 +301,35 @@ describe('Snippet Edit app', () => {
});
});
+ it.each`
+ newSnippet | projectPath | mutationName
+ ${true} | ${rawProjectPathMock} | ${'CreateSnippetMutation with projectPath'}
+ ${true} | ${''} | ${'CreateSnippetMutation without projectPath'}
+ ${false} | ${rawProjectPathMock} | ${'UpdateSnippetMutation with projectPath'}
+ ${false} | ${''} | ${'UpdateSnippetMutation without projectPath'}
+ `(
+ 'does not redirect to snippet view if the seemingly successful' +
+ ' $mutationName response contains errors',
+ ({ newSnippet, projectPath }) => {
+ createComponent({
+ data: {
+ newSnippet,
+ },
+ props: {
+ ...defaultProps,
+ projectPath,
+ },
+ mutationRes: mutationTypes.RESOLVE_WITH_ERRORS,
+ });
+
+ wrapper.vm.handleFormSubmit();
+ return waitForPromises().then(() => {
+ expect(redirectTo).not.toHaveBeenCalled();
+ expect(flashSpy).toHaveBeenCalledWith(mutationError);
+ });
+ },
+ );
+
it('flashes an error if mutation failed', () => {
createComponent({
mutationRes: mutationTypes.REJECT,