Commit 4693aa9c authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'issue-edit-inline-title-validation' into 'issue-edit-inline'

Disable inline submit button when title is blank

See merge request !11409
parents 4fcff0bf e713c68a
...@@ -7,6 +7,10 @@ ...@@ -7,6 +7,10 @@
type: Boolean, type: Boolean,
required: true, required: true,
}, },
formState: {
type: Object,
required: true,
},
}, },
data() { data() {
return { return {
...@@ -14,6 +18,11 @@ ...@@ -14,6 +18,11 @@
updateLoading: false, updateLoading: false,
}; };
}, },
computed: {
isSubmitEnabled() {
return this.formState.title.trim() !== '';
},
},
methods: { methods: {
updateIssuable() { updateIssuable() {
this.updateLoading = true; this.updateLoading = true;
...@@ -38,9 +47,9 @@ ...@@ -38,9 +47,9 @@
<div class="prepend-top-default append-bottom-default clearfix"> <div class="prepend-top-default append-bottom-default clearfix">
<button <button
class="btn btn-save pull-left" class="btn btn-save pull-left"
:class="{ disabled: updateLoading }" :class="{ disabled: updateLoading || !isSubmitEnabled }"
type="submit" type="submit"
:disabled="updateLoading" :disabled="updateLoading || !isSubmitEnabled"
@click="updateIssuable"> @click="updateIssuable">
Save changes Save changes
<i <i
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
:markdown-preview-url="markdownPreviewUrl" :markdown-preview-url="markdownPreviewUrl"
:markdown-docs="markdownDocs" /> :markdown-docs="markdownDocs" />
<edit-actions <edit-actions
:form-state="formState"
:can-destroy="canDestroy" /> :can-destroy="canDestroy" />
</form> </form>
</template> </template>
import Vue from 'vue'; import Vue from 'vue';
import editActions from '~/issue_show/components/edit_actions.vue'; import editActions from '~/issue_show/components/edit_actions.vue';
import eventHub from '~/issue_show/event_hub'; import eventHub from '~/issue_show/event_hub';
import Store from '~/issue_show/stores';
describe('Edit Actions components', () => { describe('Edit Actions components', () => {
let vm; let vm;
beforeEach((done) => { beforeEach((done) => {
const Component = Vue.extend(editActions); const Component = Vue.extend(editActions);
const store = new Store({
titleHtml: '',
descriptionHtml: '',
issuableRef: '',
});
store.formState.title = 'test';
spyOn(eventHub, '$emit'); spyOn(eventHub, '$emit');
vm = new Component({ vm = new Component({
propsData: { propsData: {
canDestroy: true, canDestroy: true,
formState: store.formState,
}, },
}).$mount(); }).$mount();
...@@ -41,6 +49,18 @@ describe('Edit Actions components', () => { ...@@ -41,6 +49,18 @@ describe('Edit Actions components', () => {
}); });
}); });
it('disables submit button when title is blank', (done) => {
vm.formState.title = '';
Vue.nextTick(() => {
expect(
vm.$el.querySelector('.btn-save').getAttribute('disabled'),
).toBe('disabled');
done();
});
});
describe('updateIssuable', () => { describe('updateIssuable', () => {
it('sends update.issauble event when clicking save button', () => { it('sends update.issauble event when clicking save button', () => {
vm.$el.querySelector('.btn-save').click(); vm.$el.querySelector('.btn-save').click();
......
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