From c1a05bc73ba3a09ef589b2f2b87875e03d440a52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Tue, 26 Aug 2025 10:34:30 +0200 Subject: [PATCH] feat(webapp): add location distance in group profile (#8846) * Add distance to group profile if location is defined * Fix snapshot tests in 'webapp/pages/groups/_id/_slug.spec.js' * Fix prop Vue warning in test 'webapp/pages/groups/_id/_slug.spec.js' * reuse locationFragement for groups * use better order on locationFragement parameters * moved LocationInfo Component to correct place as its used in Group & User related context * use size prop * reduce changeset * update snapshots * remove computed property & simplify component * more tests & updated snapshots --------- Co-authored-by: Ulf Gebhardt --- .../LocationInfo/LocationInfo.spec.js | 45 ++++ .../LocationInfo.vue | 32 ++- .../__snapshots__/LocationInfo.spec.js.snap | 99 +++++++++ .../UserTeaser/LocationInfo.spec.js | 31 --- .../UserTeaser/UserTeaserPopover.vue | 2 +- .../__snapshots__/LocationInfo.spec.js.snap | 51 ----- webapp/graphql/Fragments.js | 6 +- webapp/graphql/PostQuery.js | 8 +- webapp/graphql/User.js | 4 +- webapp/graphql/groups.js | 13 +- .../_id/__snapshots__/_slug.spec.js.snap | 198 ++++++++++++------ webapp/pages/groups/_id/_slug.vue | 11 +- webapp/pages/profile/_id/_slug.vue | 18 +- 13 files changed, 320 insertions(+), 198 deletions(-) create mode 100644 webapp/components/LocationInfo/LocationInfo.spec.js rename webapp/components/{UserTeaser => LocationInfo}/LocationInfo.vue (51%) create mode 100644 webapp/components/LocationInfo/__snapshots__/LocationInfo.spec.js.snap delete mode 100644 webapp/components/UserTeaser/LocationInfo.spec.js delete mode 100644 webapp/components/UserTeaser/__snapshots__/LocationInfo.spec.js.snap diff --git a/webapp/components/LocationInfo/LocationInfo.spec.js b/webapp/components/LocationInfo/LocationInfo.spec.js new file mode 100644 index 000000000..7771da8ce --- /dev/null +++ b/webapp/components/LocationInfo/LocationInfo.spec.js @@ -0,0 +1,45 @@ +import { render } from '@testing-library/vue' +import LocationInfo from './LocationInfo.vue' + +const localVue = global.localVue + +describe('LocationInfo', () => { + const Wrapper = ({ withDistance }) => { + return render(LocationInfo, { + localVue, + propsData: { + locationData: { + name: 'Paris', + distanceToMe: withDistance ? 100 : null, + }, + }, + mocks: { + $t: jest.fn((t) => t), + }, + }) + } + + describe('distance', () => { + it('renders with distance', () => { + const wrapper = Wrapper({ withDistance: true }) + expect(wrapper.container).toMatchSnapshot() + }) + + it('renders without distance', () => { + const wrapper = Wrapper({ withDistance: false }) + expect(wrapper.container).toMatchSnapshot() + }) + }) + + describe('size', () => { + it('renders in base size', () => { + const wrapper = Wrapper({ size: 'base' }) + expect(wrapper.container).toMatchSnapshot() + }) + + it('renders in small size', () => { + const wrapper = Wrapper({ size: 'small' }) + expect(wrapper.container).toMatchSnapshot() + }) + }) +}) diff --git a/webapp/components/UserTeaser/LocationInfo.vue b/webapp/components/LocationInfo/LocationInfo.vue similarity index 51% rename from webapp/components/UserTeaser/LocationInfo.vue rename to webapp/components/LocationInfo/LocationInfo.vue index 67dc46c27..89dbeddf2 100644 --- a/webapp/components/UserTeaser/LocationInfo.vue +++ b/webapp/components/LocationInfo/LocationInfo.vue @@ -1,10 +1,12 @@ @@ -13,12 +15,12 @@ export default { name: 'LocationInfo', props: { locationData: { type: Object, default: null }, - }, - computed: { - distance() { - return this.locationData.distanceToMe === null - ? null - : this.$t('location.distance', { distance: this.locationData.distanceToMe }) + size: { + type: String, + default: 'base', + validator: (value) => { + return value.match(/(small|base)/) + }, }, }, } @@ -36,9 +38,21 @@ export default { align-items: center; justify-content: center; } +} - .distance { +.size-base { + > .distance { margin-top: 8px; } } + +.size-small { + font-size: 0.8rem; + color: #70677e; + margin-bottom: 12px; + + > .distance { + margin-top: 2px; + } +} diff --git a/webapp/components/LocationInfo/__snapshots__/LocationInfo.spec.js.snap b/webapp/components/LocationInfo/__snapshots__/LocationInfo.spec.js.snap new file mode 100644 index 000000000..e8a1e2a44 --- /dev/null +++ b/webapp/components/LocationInfo/__snapshots__/LocationInfo.spec.js.snap @@ -0,0 +1,99 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`LocationInfo distance renders with distance 1`] = ` +
+
+
+ + + + + Paris + +
+ +
+ + location.distance + +
+
+
+`; + +exports[`LocationInfo distance renders without distance 1`] = ` +
+
+
+ + + + + Paris + +
+ + +
+
+`; + +exports[`LocationInfo size renders in base size 1`] = ` +
+
+
+ + + + + Paris + +
+ + +
+
+`; + +exports[`LocationInfo size renders in small size 1`] = ` +
+
+
+ + + + + Paris + +
+ + +
+
+`; diff --git a/webapp/components/UserTeaser/LocationInfo.spec.js b/webapp/components/UserTeaser/LocationInfo.spec.js deleted file mode 100644 index 2b100e66d..000000000 --- a/webapp/components/UserTeaser/LocationInfo.spec.js +++ /dev/null @@ -1,31 +0,0 @@ -import { render } from '@testing-library/vue' -import LocationInfo from './LocationInfo.vue' - -const localVue = global.localVue - -describe('LocationInfo', () => { - const Wrapper = ({ withDistance }) => { - return render(LocationInfo, { - localVue, - propsData: { - locationData: { - name: 'Paris', - distanceToMe: withDistance ? 100 : null, - }, - }, - mocks: { - $t: jest.fn((t) => t), - }, - }) - } - - it('renders with distance', () => { - const wrapper = Wrapper({ withDistance: true }) - expect(wrapper.container).toMatchSnapshot() - }) - - it('renders without distance', () => { - const wrapper = Wrapper({ withDistance: false }) - expect(wrapper.container).toMatchSnapshot() - }) -}) diff --git a/webapp/components/UserTeaser/UserTeaserPopover.vue b/webapp/components/UserTeaser/UserTeaserPopover.vue index 68fffaf90..e1c553cab 100644 --- a/webapp/components/UserTeaser/UserTeaserPopover.vue +++ b/webapp/components/UserTeaser/UserTeaserPopover.vue @@ -30,7 +30,7 @@