diff --git a/webapp/components/Group/GroupForm.vue b/webapp/components/Group/GroupForm.vue index fbfdd5d27..e43f2fc43 100644 --- a/webapp/components/Group/GroupForm.vue +++ b/webapp/components/Group/GroupForm.vue @@ -110,29 +110,7 @@ - - - - - {{ $t('settings.data.labelCityHint') }} - + @@ -176,11 +154,9 @@ import { } from '~/constants/groups.js' import Editor from '~/components/Editor/Editor' import ActionRadiusSelect from '~/components/Select/ActionRadiusSelect' -import { queryLocations } from '~/graphql/location' +import LocationSelect from '~/components/Select/LocationSelect' import GetCategories from '~/mixins/getCategoriesMixin.js' -let timeout - export default { name: 'GroupForm', mixins: [GetCategories], @@ -188,6 +164,7 @@ export default { CategoriesSelect, Editor, ActionRadiusSelect, + LocationSelect, }, props: { update: { @@ -215,12 +192,6 @@ export default { groupType: groupType || '', about: about || '', description: description || '', - // from database 'locationName' comes as "string | null" - // 'formData.locationName': - // see 'created': tries to set it to a "requestGeoData" object and fills the menu if possible - // if user selects one from menu we get a "requestGeoData" object here - // "requestGeoData" object: "{ id: String, label: String, value: String }" - // otherwise it's a string: empty or none empty locationName: locationName || '', actionRadius: actionRadius || '', categoryIds: categories ? categories.map((category) => category.id) : [], @@ -259,11 +230,6 @@ export default { }, } }, - async created() { - // set to "requestGeoData" object and fill select menu if possible - this.formData.locationName = - (await this.requestGeoData(this.formLocationName)) || this.formLocationName - }, computed: { formLocationName() { const isNestedValue = @@ -276,9 +242,6 @@ export default { ? this.formData.locationName : '' }, - locationNameLabelAddOnOldName() { - return this.formLocationName !== '' ? ' — ' + this.formLocationName : '' - }, descriptionLength() { return this.$filters.removeHtml(this.formData.description).length }, @@ -322,6 +285,9 @@ export default { changeActionRadius(event) { this.$refs.groupForm.update('actionRadius', event.target.value) }, + changeLocation(event) { + this.formData.locationName = event.target.value + }, updateEditorDescription(value) { this.$refs.groupForm.update('description', value) }, @@ -344,47 +310,6 @@ export default { }) : this.$emit('createGroup', variables) }, - handleCityInput(event) { - clearTimeout(timeout) - timeout = setTimeout( - () => this.requestGeoData(event.target ? event.target.value.trim() : ''), - 500, - ) - }, - processLocationsResult(places) { - if (!places.length) { - return [] - } - const result = [] - places.forEach((place) => { - result.push({ - label: place.place_name, - value: place.place_name, - id: place.id, - }) - }) - - return result - }, - async requestGeoData(value) { - if (value === '') { - this.cities = [] - return - } - this.loadingGeo = true - - const place = encodeURIComponent(value) - const lang = this.$i18n.locale() - - const { - data: { queryLocations: result }, - } = await this.$apollo.query({ query: queryLocations(), variables: { place, lang } }) - - this.cities = this.processLocationsResult(result) - this.loadingGeo = false - - return this.cities.find((city) => city.value === value) - }, }, } diff --git a/webapp/components/Select/LocationSelect.spec.js b/webapp/components/Select/LocationSelect.spec.js new file mode 100644 index 000000000..a9af3b32b --- /dev/null +++ b/webapp/components/Select/LocationSelect.spec.js @@ -0,0 +1,52 @@ +import { mount } from '@vue/test-utils' +import LocationSelect from './LocationSelect' + +const localVue = global.localVue +const propsData = { value: 'nowhere' } + +let wrapper + +const mocks = { + $t: jest.fn((string) => string), + $i18n: { + locale: () => 'en', + }, +} + +describe('LocationSelect', () => { + beforeEach(() => {}) + + describe('mount', () => { + const Wrapper = () => { + return mount(LocationSelect, { mocks, localVue, propsData }) + } + + beforeEach(() => { + wrapper = Wrapper() + }) + + it('renders the label', () => { + expect(wrapper.find('label.ds-input-label').exists()).toBe(true) + }) + + it('renders the select', () => { + expect(wrapper.find('.ds-select').exists()).toBe(true) + }) + + it('renders the clearLocationName button', () => { + expect(wrapper.find('.base-button').exists()).toBe(true) + }) + + describe('clearLocationName button click', () => { + beforeEach(() => { + wrapper.find('.base-button').trigger('click') + }) + + it('emits an empty string', () => { + expect(wrapper.emitted().input).toBeTruthy() + expect(wrapper.emitted().input.length).toBe(1) + expect(wrapper.emitted().input[0]).toEqual(['']) + }) + }) + }) +}) diff --git a/webapp/components/Select/LocationSelect.vue b/webapp/components/Select/LocationSelect.vue new file mode 100644 index 000000000..a9f0e75b7 --- /dev/null +++ b/webapp/components/Select/LocationSelect.vue @@ -0,0 +1,118 @@ + + + diff --git a/webapp/pages/settings/index.spec.js b/webapp/pages/settings/index.spec.js index 081234481..fda60e6c5 100644 --- a/webapp/pages/settings/index.spec.js +++ b/webapp/pages/settings/index.spec.js @@ -1,6 +1,7 @@ import { mount } from '@vue/test-utils' import index from './index.vue' import Vuex from 'vuex' +import LocationSelect from '~/components/Select/LocationSelect' const localVue = global.localVue @@ -161,17 +162,7 @@ describe('index.vue', () => { describe('given a new location and hitting submit', () => { it('calls updateUser mutation', async () => { const wrapper = Wrapper() - wrapper.setData({ - cities: [ - { - label: 'Berlin, Germany', - value: 'Berlin, Germany', - id: '1', - }, - ], - }) - await wrapper.vm.$nextTick() - wrapper.find('.ds-select-option').trigger('click') + wrapper.findComponent(LocationSelect).vm.$emit('input', 'Berlin, Germany') wrapper.find('.ds-form').trigger('submit') await expect(mocks.$apollo.mutate).toHaveBeenCalledWith( @@ -204,25 +195,9 @@ describe('index.vue', () => { describe('given new username, slug, location and about then hitting submit', () => { it('calls updateUser mutation', async () => { const wrapper = Wrapper() - - wrapper.setData({ - cities: [ - { - label: 'Berlin, Germany', - value: 'Berlin, Germany', - id: '1', - }, - { - label: 'Hamburg, Germany', - value: 'Hamburg, Germany', - id: '2', - }, - ], - }) - await wrapper.vm.$nextTick() wrapper.find('#name').setValue('Peter') wrapper.find('#slug').setValue('peter-der-lustige') - wrapper.findAll('.ds-select-option').at(1).trigger('click') + await wrapper.findComponent(LocationSelect).vm.$emit('input', 'Hamburg, Germany') wrapper.find('#about').setValue('I am Peter!111elf') wrapper.find('.ds-form').trigger('submit') diff --git a/webapp/pages/settings/index.vue b/webapp/pages/settings/index.vue index 3107e48b1..70bb738fd 100644 --- a/webapp/pages/settings/index.vue +++ b/webapp/pages/settings/index.vue @@ -1,5 +1,5 @@