Commit 312cacee authored by Martin Wortschack's avatar Martin Wortschack

Merge branch 'dmishunov-snippet-edit-cancellation' into 'master'

Fixed cancel action on snippet edit form

See merge request gitlab-org/gitlab!29993
parents ff949207 4d899253
......@@ -81,7 +81,10 @@ export default {
return this.isUpdating ? __('Saving') : __('Save changes');
},
cancelButtonHref() {
return this.projectPath ? `/${this.projectPath}/snippets` : `/snippets`;
if (this.newSnippet) {
return this.projectPath ? `/${this.projectPath}/snippets` : `/snippets`;
}
return this.snippet.webUrl;
},
titleFieldId() {
return `${this.isProjectSnippet ? 'project' : 'personal'}_snippet_title`;
......@@ -203,7 +206,9 @@ export default {
>
</template>
<template #append>
<gl-button :href="cancelButtonHref">{{ __('Cancel') }}</gl-button>
<gl-button data-testid="snippet-cancel-btn" :href="cancelButtonHref">{{
__('Cancel')
}}</gl-button>
</template>
</form-footer-actions>
</template>
......
---
title: Fixed Cancel action on Snippet edit for existing snippets
merge_request: 29993
author:
type: fixed
......@@ -100,6 +100,7 @@ describe('Snippet Edit app', () => {
});
const findSubmitButton = () => wrapper.find('[type=submit]');
const findCancellButton = () => wrapper.find('[data-testid="snippet-cancel-btn"]');
describe('rendering', () => {
it('renders loader while the query is in flight', () => {
......@@ -148,6 +149,21 @@ describe('Snippet Edit app', () => {
expect(isBtnDisabled).toBe(expectation);
},
);
it.each`
isNew | status | expectation
${true} | ${`new`} | ${`/snippets`}
${false} | ${`existing`} | ${newlyEditedSnippetUrl}
`('sets correct href for the cancel button on a $status snippet', ({ isNew, expectation }) => {
createComponent({
data: {
snippet: { webUrl: newlyEditedSnippetUrl },
newSnippet: isNew,
},
});
expect(findCancellButton().attributes('href')).toBe(expectation);
});
});
describe('functionality', () => {
......
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