diff --git a/backend/src/schema/resolvers/users/location.spec.js b/backend/src/schema/resolvers/users/location.spec.js index 41b784249e7a3937727bca9bd770ace3ccf6a6c6..1ef4270347dbf21f30c432d5770f5b159f1a5f21 100644 --- a/backend/src/schema/resolvers/users/location.spec.js +++ b/backend/src/schema/resolvers/users/location.spec.js @@ -114,10 +114,22 @@ describe('Location Service', () => { const result = await query({ query: queryLocations, variables }) expect(result.data.queryLocations).toEqual([ { id: 'place.14094307404564380', place_name: 'Berlin, Germany' }, - { id: 'place.15095411613564380', place_name: 'Berlin, Maryland, United States' }, - { id: 'place.5225018734564380', place_name: 'Berlin, Connecticut, United States' }, - { id: 'place.16922023226564380', place_name: 'Berlin, New Jersey, United States' }, - { id: 'place.4035845612564380', place_name: 'Berlin Township, New Jersey, United States' }, + { + id: expect.stringMatching(/^place\.[0-9]+$/), + place_name: 'Berlin, Maryland, United States', + }, + { + id: expect.stringMatching(/^place\.[0-9]+$/), + place_name: 'Berlin, Connecticut, United States', + }, + { + id: expect.stringMatching(/^place\.[0-9]+$/), + place_name: 'Berlin, New Jersey, United States', + }, + { + id: expect.stringMatching(/^place\.[0-9]+$/), + place_name: 'Berlin Township, New Jersey, United States', + }, ]) }) @@ -128,11 +140,23 @@ describe('Location Service', () => { } const result = await query({ query: queryLocations, variables }) expect(result.data.queryLocations).toEqual([ - { id: 'place.14094307404564380', place_name: 'Berlin, Deutschland' }, - { id: 'place.15095411613564380', place_name: 'Berlin, Maryland, Vereinigte Staaten' }, - { id: 'place.16922023226564380', place_name: 'Berlin, New Jersey, Vereinigte Staaten' }, - { id: 'place.10735893248465990', place_name: 'Berlin Heights, Ohio, Vereinigte Staaten' }, - { id: 'place.1165756679564380', place_name: 'Berlin, Massachusetts, Vereinigte Staaten' }, + { id: expect.stringMatching(/^place\.[0-9]+$/), place_name: 'Berlin, Deutschland' }, + { + id: expect.stringMatching(/^place\.[0-9]+$/), + place_name: 'Berlin, Maryland, Vereinigte Staaten', + }, + { + id: expect.stringMatching(/^place\.[0-9]+$/), + place_name: 'Berlin, New Jersey, Vereinigte Staaten', + }, + { + id: expect.stringMatching(/^place\.[0-9]+$/), + place_name: 'Berlin Heights, Ohio, Vereinigte Staaten', + }, + { + id: expect.stringMatching(/^place\.[0-9]+$/), + place_name: 'Berlin, Massachusetts, Vereinigte Staaten', + }, ]) }) diff --git a/webapp/components/Editor/Editor.spec.js b/webapp/components/Editor/Editor.spec.js index ee762b33243e74cd3d9a68a05794f990e01ba881..f51c5782f0f87ec4de5f14754109de13e7d5f00d 100644 --- a/webapp/components/Editor/Editor.spec.js +++ b/webapp/components/Editor/Editor.spec.js @@ -99,6 +99,37 @@ describe('Editor.vue', () => { }) }) + it('suggestion list returns results prefixed by query', () => { + const manyUsersList = [] + for (let i = 0; i < 10; i++) { + manyUsersList.push({ id: `user${i}` }) + manyUsersList.push({ id: `admin${i}` }) + manyUsersList.push({ id: `moderator${i}` }) + } + propsData.users = manyUsersList + wrapper = Wrapper() + const suggestionList = wrapper.vm.editor.extensions.options.mention.onFilter( + propsData.users, + 'moderator', + ) + expect(suggestionList).toHaveLength(10) + for (var i = 0; i < suggestionList.length; i++) { + expect(suggestionList[i].id).toMatch(/^moderator.*/) + } + }) + + it('exact match appears at the top of suggestion list', () => { + const manyUsersList = [] + for (let i = 0; i < 25; i++) { + manyUsersList.push({ id: `user${i}` }) + } + propsData.users = manyUsersList + wrapper = Wrapper() + expect( + wrapper.vm.editor.extensions.options.mention.onFilter(propsData.users, 'user7')[0].id, + ).toMatch('user7') + }) + it('sets the Hashtag items to the hashtags', () => { propsData.hashtags = [ { diff --git a/webapp/components/Editor/Editor.vue b/webapp/components/Editor/Editor.vue index 67329a60bcbca11b8a619d945332aec50883786d..cf0fd710b16977d9f6cbf67ca2b34c86868ee0f9 100644 --- a/webapp/components/Editor/Editor.vue +++ b/webapp/components/Editor/Editor.vue @@ -185,6 +185,9 @@ export default { if (this.suggestionType === HASHTAG && this.query !== '') { this.selectItem({ id: this.query }) } + if (this.suggestionType === MENTION && item) { + this.selectItem(item) + } return true default: @@ -199,9 +202,14 @@ export default { const filteredList = items.filter((item) => { const itemString = item.slug || item.id - return itemString.toLowerCase().includes(query.toLowerCase()) + return itemString.toLowerCase().startsWith(query.toLowerCase()) + }) + const sortedList = filteredList.sort((itemA, itemB) => { + const aString = itemA.slug || itemA.id + const bString = itemB.slug || itemB.id + return aString.length - bString.length }) - return filteredList.slice(0, 15) + return sortedList.slice(0, 15) }, sanitizeQuery(query) { if (this.suggestionType === HASHTAG) {