Commit 8369d39f authored by Andrew Fontaine's avatar Andrew Fontaine

Merge branch 'ss/related-issues-autocomplete' into 'master'

Add ability to enter number in related issues

See merge request gitlab-org/gitlab!48952
parents 757a673e 93bd94b9
...@@ -204,7 +204,16 @@ export default { ...@@ -204,7 +204,16 @@ export default {
onInput({ untouchedRawReferences, touchedReference }) { onInput({ untouchedRawReferences, touchedReference }) {
this.store.addPendingReferences(untouchedRawReferences); this.store.addPendingReferences(untouchedRawReferences);
this.formatInput(touchedReference);
},
formatInput(touchedReference = '') {
const startsWithNumber = String(touchedReference).match(/^[0-9]/) !== null;
if (startsWithNumber) {
this.inputValue = `#${touchedReference}`;
} else {
this.inputValue = `${touchedReference}`; this.inputValue = `${touchedReference}`;
}
}, },
onBlur(newValue) { onBlur(newValue) {
this.processAllReferences(newValue); this.processAllReferences(newValue);
......
---
title: 'Add ability to type a number in related issues and prepend #'
merge_request: 48952
author:
type: changed
...@@ -280,7 +280,7 @@ describe('RelatedIssuesRoot', () => { ...@@ -280,7 +280,7 @@ describe('RelatedIssuesRoot', () => {
const input = 'asdf/qwer#444 #12 '; const input = 'asdf/qwer#444 #12 ';
wrapper.vm.onInput({ wrapper.vm.onInput({
untouchedRawReferences: input.trim().split(/\s/), untouchedRawReferences: input.trim().split(/\s/),
touchedReference: 2, touchedReference: '2',
}); });
expect(wrapper.vm.state.pendingReferences).toHaveLength(2); expect(wrapper.vm.state.pendingReferences).toHaveLength(2);
...@@ -292,13 +292,37 @@ describe('RelatedIssuesRoot', () => { ...@@ -292,13 +292,37 @@ describe('RelatedIssuesRoot', () => {
const input = 'something random '; const input = 'something random ';
wrapper.vm.onInput({ wrapper.vm.onInput({
untouchedRawReferences: input.trim().split(/\s/), untouchedRawReferences: input.trim().split(/\s/),
touchedReference: 2, touchedReference: '2',
}); });
expect(wrapper.vm.state.pendingReferences).toHaveLength(2); expect(wrapper.vm.state.pendingReferences).toHaveLength(2);
expect(wrapper.vm.state.pendingReferences[0]).toEqual('something'); expect(wrapper.vm.state.pendingReferences[0]).toEqual('something');
expect(wrapper.vm.state.pendingReferences[1]).toEqual('random'); expect(wrapper.vm.state.pendingReferences[1]).toEqual('random');
}); });
it('prepends # when user enters a numeric value [0-9]', async () => {
const input = '23';
wrapper.vm.onInput({
untouchedRawReferences: input.trim().split(/\s/),
touchedReference: input,
});
expect(wrapper.vm.inputValue).toBe(`#${input}`);
});
it('prepends # when user enters a number', async () => {
const input = 23;
wrapper.vm.onInput({
untouchedRawReferences: String(input)
.trim()
.split(/\s/),
touchedReference: input,
});
expect(wrapper.vm.inputValue).toBe(`#${input}`);
});
}); });
describe('onBlur', () => { describe('onBlur', () => {
......
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