From d6e6eaabe7910b4ebe28057eae5046d70090f9b4 Mon Sep 17 00:00:00 2001 From: ashleysylvialee Date: Sun, 14 Mar 2021 23:20:17 -1000 Subject: [PATCH 1/5] Fix suggestion list filter --- webapp/components/Editor/Editor.vue | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/webapp/components/Editor/Editor.vue b/webapp/components/Editor/Editor.vue index 67329a60bc..5a612b1045 100644 --- a/webapp/components/Editor/Editor.vue +++ b/webapp/components/Editor/Editor.vue @@ -199,9 +199,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()) }) - return filteredList.slice(0, 15) + const sortedList = filteredList.sort((itemA, itemB) => { + const aString = itemA.slug || itemA.id + const bString = itemB.slug || itemB.id + return aString.length - bString.length + }) + return sortedList.slice(0, 15) }, sanitizeQuery(query) { if (this.suggestionType === HASHTAG) { From ead097eb3a50ea5adf4eca47f261c8739f6d37b9 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 16 Mar 2021 11:11:54 +0100 Subject: [PATCH 2/5] fix tests after MAPBOX changed their IDs again --- .../schema/resolvers/users/location.spec.js | 42 +++++++++++++++---- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/backend/src/schema/resolvers/users/location.spec.js b/backend/src/schema/resolvers/users/location.spec.js index 41b784249e..1ef4270347 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', + }, ]) }) From b6aa878a9d287cbab4e627a82379b5a39f320d9e Mon Sep 17 00:00:00 2001 From: ashleysylvialee Date: Tue, 16 Mar 2021 19:17:49 -1000 Subject: [PATCH 3/5] Add spacebar selection functionality for mentions --- webapp/components/Editor/Editor.vue | 3 +++ 1 file changed, 3 insertions(+) diff --git a/webapp/components/Editor/Editor.vue b/webapp/components/Editor/Editor.vue index 5a612b1045..cf0fd710b1 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: From 1477a0364a2337c719ba5f26226bae98166ef356 Mon Sep 17 00:00:00 2001 From: ashleysylvialee Date: Tue, 16 Mar 2021 19:18:17 -1000 Subject: [PATCH 4/5] Add tests --- webapp/components/Editor/Editor.spec.js | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/webapp/components/Editor/Editor.spec.js b/webapp/components/Editor/Editor.spec.js index ee762b3324..2331d10c29 100644 --- a/webapp/components/Editor/Editor.spec.js +++ b/webapp/components/Editor/Editor.spec.js @@ -99,6 +99,34 @@ 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 = [ { From 51e7649a67d43d9708125d106ea57f07bc3bb5b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Fri, 19 Mar 2021 07:48:53 +0100 Subject: [PATCH 5/5] Fix linting --- webapp/components/Editor/Editor.spec.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/webapp/components/Editor/Editor.spec.js b/webapp/components/Editor/Editor.spec.js index 2331d10c29..f51c5782f0 100644 --- a/webapp/components/Editor/Editor.spec.js +++ b/webapp/components/Editor/Editor.spec.js @@ -108,7 +108,10 @@ describe('Editor.vue', () => { } propsData.users = manyUsersList wrapper = Wrapper() - const suggestionList = wrapper.vm.editor.extensions.options.mention.onFilter(propsData.users, 'moderator') + 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.*/) @@ -123,7 +126,7 @@ describe('Editor.vue', () => { propsData.users = manyUsersList wrapper = Wrapper() expect( - wrapper.vm.editor.extensions.options.mention.onFilter(propsData.users, 'user7')[0].id + wrapper.vm.editor.extensions.options.mention.onFilter(propsData.users, 'user7')[0].id, ).toMatch('user7') })