Commit 36ecfa9f authored by Scott Stern's avatar Scott Stern Committed by Vitaly Slobodin

Guard create issue button in boards against submitting spaces

Changelog: fixed
MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/78505
parent 5a5cc407
...@@ -43,6 +43,12 @@ export default { ...@@ -43,6 +43,12 @@ export default {
// eslint-disable-next-line @gitlab/require-i18n-strings // eslint-disable-next-line @gitlab/require-i18n-strings
return `${this.list.id}-title`; return `${this.list.id}-title`;
}, },
isIssueTitleEmpty() {
return this.title.trim() === '';
},
isCreatingIssueDisabled() {
return this.isIssueTitleEmpty || this.disableSubmit;
},
}, },
methods: { methods: {
handleFormCancel() { handleFormCancel() {
...@@ -54,7 +60,7 @@ export default { ...@@ -54,7 +60,7 @@ export default {
eventHub.$emit(`scroll-board-list-${this.list.id}`); eventHub.$emit(`scroll-board-list-${this.list.id}`);
this.$emit('form-submit', { this.$emit('form-submit', {
title, title: title.trim(),
list, list,
}); });
}, },
...@@ -69,7 +75,7 @@ export default { ...@@ -69,7 +75,7 @@ export default {
<label :for="inputFieldId" class="gl-font-weight-bold">{{ __('Title') }}</label> <label :for="inputFieldId" class="gl-font-weight-bold">{{ __('Title') }}</label>
<gl-form-input <gl-form-input
:id="inputFieldId" :id="inputFieldId"
v-model.trim="title" v-model="title"
:autofocus="true" :autofocus="true"
autocomplete="off" autocomplete="off"
type="text" type="text"
...@@ -78,7 +84,8 @@ export default { ...@@ -78,7 +84,8 @@ export default {
<slot></slot> <slot></slot>
<div class="gl-clearfix gl-mt-4"> <div class="gl-clearfix gl-mt-4">
<gl-button <gl-button
:disabled="!title || disableSubmit" data-testid="create-button"
:disabled="isCreatingIssueDisabled"
class="gl-float-left js-no-auto-disable" class="gl-float-left js-no-auto-disable"
variant="confirm" variant="confirm"
type="submit" type="submit"
......
...@@ -39,6 +39,27 @@ describe('BoardNewItem', () => { ...@@ -39,6 +39,27 @@ describe('BoardNewItem', () => {
}); });
describe('template', () => { describe('template', () => {
describe('when the user provides a valid input', () => {
it('finds an enabled create button', async () => {
expect(wrapper.findByTestId('create-button').props('disabled')).toBe(true);
wrapper.find(GlFormInput).vm.$emit('input', 'hello');
await wrapper.vm.$nextTick();
expect(wrapper.findByTestId('create-button').props('disabled')).toBe(false);
});
});
describe('when the user types in a string with only spaces', () => {
it('disables the Create Issue button', async () => {
wrapper.find(GlFormInput).vm.$emit('input', ' ');
await wrapper.vm.$nextTick();
expect(wrapper.findByTestId('create-button').props('disabled')).toBe(true);
});
});
it('renders gl-form component', () => { it('renders gl-form component', () => {
expect(wrapper.findComponent(GlForm).exists()).toBe(true); expect(wrapper.findComponent(GlForm).exists()).toBe(true);
}); });
...@@ -80,6 +101,19 @@ describe('BoardNewItem', () => { ...@@ -80,6 +101,19 @@ describe('BoardNewItem', () => {
]); ]);
}); });
it('emits `form-submit` event with trimmed title', async () => {
titleInput().setValue(' Foo ');
await glForm().trigger('submit');
expect(wrapper.emitted('form-submit')[0]).toEqual([
{
title: 'Foo',
list: mockList,
},
]);
});
it('emits `scroll-board-list-` event with list.id on eventHub when `submit` is triggered on gl-form', async () => { it('emits `scroll-board-list-` event with list.id on eventHub when `submit` is triggered on gl-form', async () => {
jest.spyOn(eventHub, '$emit').mockImplementation(); jest.spyOn(eventHub, '$emit').mockImplementation();
await glForm().trigger('submit'); await glForm().trigger('submit');
......
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