Skip to content

Commit

Permalink
Merge pull request #2565 from ldbv-by/dev_v4.2_add-parcel-2-contextMenu
Browse files Browse the repository at this point in the history
v4.2: ContextMenu - display parcel number when available
  • Loading branch information
taulinger authored Sep 10, 2024
2 parents 237d30a + 7a0cae9 commit a0fea4d
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class MapContextMenuContent extends MvuElement {
const {
coordinate,
elevation,
administration: { community, district }
administration: { community, district, parcel }
} = model;
const translate = (key) => this._translationService.translate(key);

Expand Down Expand Up @@ -148,6 +148,11 @@ export class MapContextMenuContent extends MvuElement {
<li>
<span class="label">${translate('map_contextMenuContent_district_label')}</span><span class="coordinate">${district || '-'}</span>
</li>
${parcel
? html`<li>
<span class="label">${translate('map_contextMenuContent_parcel_label')}</span><span class="coordinate">${parcel || '-'}</span>
</li>`
: nothing}
${stringifiedCoords.map((strCoord) => html`<li>${strCoord}</li>`)}
<li>
<span class="label">${translate('map_contextMenuContent_elevation_label')}</span><span class="coordinate">${elevation || '-'}</span>
Expand Down
2 changes: 2 additions & 0 deletions src/modules/map/i18n/contextMenu.provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const provide = (lang) => {
map_contextMenuContent_elevation_label: 'Elev.',
map_contextMenuContent_community_label: 'Community',
map_contextMenuContent_district_label: 'District',
map_contextMenuContent_parcel_label: 'Parcel',
map_contextMenuContent_copy_icon: 'Copy to clipboard',
map_contextMenuContent_clipboard_error: '"Copy to clipboard" is not available',
map_contextMenuContent_clipboard_success: 'was copied to clipboard'
Expand All @@ -21,6 +22,7 @@ export const provide = (lang) => {
map_contextMenuContent_elevation_label: 'Höhe',
map_contextMenuContent_community_label: 'Gemeinde',
map_contextMenuContent_district_label: 'Gemarkung',
map_contextMenuContent_parcel_label: 'Flurstück',
map_contextMenuContent_copy_icon: 'In die Zwischenablage kopieren',
map_contextMenuContent_clipboard_error: '"In die Zwischenablage kopieren" steht nicht zur Verfügung',
map_contextMenuContent_clipboard_success: 'wurde in die Zwischenablage kopiert'
Expand Down
1 change: 1 addition & 0 deletions src/services/AdministrationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { isCoordinate } from '../utils/checks';
* @typedef {Object} Administration
* @property {string} community The community at the delivered coordinate.
* @property {string} district The district at the delivered coordinate.
* @property {string|null} parcel The parcel number at the delivered coordinate.
*/

/**
Expand Down
5 changes: 3 additions & 2 deletions src/services/provider/administration.provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ export const loadBvvAdministration = async (coordinate3857) => {

switch (result.status) {
case 200: {
const { gemeinde: community, gemarkung: district } = await result.json();
const { gemeinde: community, gemarkung: district, flstBezeichnung: parcel } = await result.json();
return {
community,
district
district,
parcel
};
}
case 404: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('OlMapContextMenuContent', () => {
});

describe('when screen coordinate available', () => {
it('renders the content', async () => {
it('renders the content when parcel is not available', async () => {
const coordinateMock = [1000, 2000];
const stringifiedCoord = 'stringified coordinate';
const getCoordinateRepresentationsMock = spyOn(mapServiceMock, 'getCoordinateRepresentations').and.returnValue([
Expand All @@ -70,24 +70,24 @@ describe('OlMapContextMenuContent', () => {
const elevationMock = spyOn(elevationServiceMock, 'getElevation').withArgs(coordinateMock).and.returnValue(42);
const administrationMock = spyOn(administrationServiceMock, 'getAdministration')
.withArgs(coordinateMock)
.and.returnValue({ community: 'LDBV', district: 'Ref42' });
.and.returnValue({ community: 'LDBV', district: 'Ref42', parcel: null });
const element = await setup();

element.coordinate = coordinateMock;

await TestUtils.timeout();
expect(element.shadowRoot.querySelector('.container')).toBeTruthy();
expect(element.shadowRoot.querySelector('.content')).toBeTruthy();
expect(element.shadowRoot.querySelectorAll('.label')).toHaveSize(4);
expect(element.shadowRoot.querySelectorAll('.label')[0].innerText).toBe('map_contextMenuContent_community_label');
expect(element.shadowRoot.querySelectorAll('.label')[1].innerText).toBe('map_contextMenuContent_district_label');
expect(element.shadowRoot.querySelectorAll('.label')[2].innerText).toBe(GlobalCoordinateRepresentations.WGS84.label);
expect(element.shadowRoot.querySelectorAll('.label')[3].innerText).toBe('map_contextMenuContent_elevation_label');

window.requestAnimationFrame(() => {
expect(element.shadowRoot.querySelectorAll('.coordinate')[0].innerText).toEqual('LDBV');
expect(element.shadowRoot.querySelectorAll('.coordinate')[1].innerText).toEqual('Ref42');
expect(element.shadowRoot.querySelectorAll('.coordinate')[2].innerText).toBe(stringifiedCoord);
expect(element.shadowRoot.querySelectorAll('.coordinate')[3].innerText).toEqual('42 (m)');
});
expect(element.shadowRoot.querySelectorAll('.coordinate')[0].innerText).toEqual('LDBV');
expect(element.shadowRoot.querySelectorAll('.coordinate')[1].innerText).toEqual('Ref42');
expect(element.shadowRoot.querySelectorAll('.coordinate')[2].innerText).toBe(stringifiedCoord);
expect(element.shadowRoot.querySelectorAll('.coordinate')[3].innerText).toEqual('42 (m)');

const copyIcon = element.shadowRoot.querySelector(Icon.tag);
expect(copyIcon).toBeTruthy();
Expand All @@ -108,6 +108,37 @@ describe('OlMapContextMenuContent', () => {
expect(element.shadowRoot.querySelectorAll('ba-routing-chip')[0].coordinate).toBe(coordinateMock);
});

it('renders the content when parcel is available', async () => {
const coordinateMock = [1000, 2000];
const stringifiedCoord = 'stringified coordinate';
spyOn(mapServiceMock, 'getCoordinateRepresentations').and.returnValue([GlobalCoordinateRepresentations.WGS84]);
spyOn(mapServiceMock, 'getSrid').and.returnValue(3857);
spyOn(coordinateServiceMock, 'stringify').and.returnValue(stringifiedCoord);
spyOn(elevationServiceMock, 'getElevation').withArgs(coordinateMock).and.returnValue(42);
spyOn(administrationServiceMock, 'getAdministration')
.withArgs(coordinateMock)
.and.returnValue({ community: 'LDBV', district: 'Ref42', parcel: '12345' });
const element = await setup();

element.coordinate = coordinateMock;

await TestUtils.timeout();
expect(element.shadowRoot.querySelector('.container')).toBeTruthy();
expect(element.shadowRoot.querySelector('.content')).toBeTruthy();
expect(element.shadowRoot.querySelectorAll('.label')).toHaveSize(5);
expect(element.shadowRoot.querySelectorAll('.label')[0].innerText).toBe('map_contextMenuContent_community_label');
expect(element.shadowRoot.querySelectorAll('.label')[1].innerText).toBe('map_contextMenuContent_district_label');
expect(element.shadowRoot.querySelectorAll('.label')[2].innerText).toBe('map_contextMenuContent_parcel_label');
expect(element.shadowRoot.querySelectorAll('.label')[3].innerText).toBe(GlobalCoordinateRepresentations.WGS84.label);
expect(element.shadowRoot.querySelectorAll('.label')[4].innerText).toBe('map_contextMenuContent_elevation_label');

expect(element.shadowRoot.querySelectorAll('.coordinate')[0].innerText).toEqual('LDBV');
expect(element.shadowRoot.querySelectorAll('.coordinate')[1].innerText).toEqual('Ref42');
expect(element.shadowRoot.querySelectorAll('.coordinate')[2].innerText).toEqual('12345');
expect(element.shadowRoot.querySelectorAll('.coordinate')[3].innerText).toBe(stringifiedCoord);
expect(element.shadowRoot.querySelectorAll('.coordinate')[4].innerText).toEqual('42 (m)');
});

it('renders the content when AdministrationService returns null', async () => {
spyOn(mapServiceMock, 'getCoordinateRepresentations').and.returnValue([{ label: 'code42', code: 42 }]);
spyOn(administrationServiceMock, 'getAdministration').and.resolveTo(null);
Expand Down
6 changes: 4 additions & 2 deletions test/modules/map/i18n/contextMenu.provider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('i18n for context menu', () => {
expect(map.map_contextMenuContent_elevation_label).toBe('Elev.');
expect(map.map_contextMenuContent_community_label).toBe('Community');
expect(map.map_contextMenuContent_district_label).toBe('District');
expect(map.map_contextMenuContent_parcel_label).toBe('Parcel');
expect(map.map_contextMenuContent_copy_icon).toBe('Copy to clipboard');
expect(map.map_contextMenuContent_clipboard_error).toBe('"Copy to clipboard" is not available');
expect(map.map_contextMenuContent_clipboard_success).toBe('was copied to clipboard');
Expand All @@ -22,13 +23,14 @@ describe('i18n for context menu', () => {
expect(map.map_contextMenuContent_elevation_label).toBe('Höhe');
expect(map.map_contextMenuContent_community_label).toBe('Gemeinde');
expect(map.map_contextMenuContent_district_label).toBe('Gemarkung');
expect(map.map_contextMenuContent_parcel_label).toBe('Flurstück');
expect(map.map_contextMenuContent_copy_icon).toBe('In die Zwischenablage kopieren');
expect(map.map_contextMenuContent_clipboard_error).toBe('"In die Zwischenablage kopieren" steht nicht zur Verfügung');
expect(map.map_contextMenuContent_clipboard_success).toBe('wurde in die Zwischenablage kopiert');
});

it('have the expected amount of translations', () => {
const expectedSize = 8;
it('contains the expected amount of entries', () => {
const expectedSize = 9;
const deMap = provide('de');
const enMap = provide('en');

Expand Down
25 changes: 21 additions & 4 deletions test/service/provider/administration.provider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,36 @@ describe('Administration provider', () => {

const coordinateMock = [21, 42];

it('loads an Administration object', async () => {
it('loads an Administration object without a parcel', async () => {
const backendUrl = 'https://backend.url';
const administrationMock = { gemeinde: 'gemeinde', gemarkung: 'gemarkung' };
const administrationMock = { gemeinde: 'gemeinde', gemarkung: 'gemarkung', flstBezeichnung: null };
const configServiceSpy = spyOn(configService, 'getValueAsPath').withArgs('BACKEND_URL').and.returnValue(backendUrl);
const httpServiceSpy = spyOn(httpService, 'get').and.returnValue(Promise.resolve(new Response(JSON.stringify(administrationMock))));

const administration = await loadBvvAdministration(coordinateMock);

expect(configServiceSpy).toHaveBeenCalled();
expect(httpServiceSpy).toHaveBeenCalled();
expect(administration.community).toEqual(administrationMock.gemeinde);
expect(administration.district).toEqual(administrationMock.gemarkung);
expect(administration.community).toBe(administrationMock.gemeinde);
expect(administration.district).toBe(administrationMock.gemarkung);
expect(administration.parcel).toBeNull();
});

it('loads an Administration object containing a parcel', async () => {
const backendUrl = 'https://backend.url';
const administrationMock = { gemeinde: 'gemeinde', gemarkung: 'gemarkung', flstBezeichnung: '12345' };
const configServiceSpy = spyOn(configService, 'getValueAsPath').withArgs('BACKEND_URL').and.returnValue(backendUrl);
const httpServiceSpy = spyOn(httpService, 'get').and.returnValue(Promise.resolve(new Response(JSON.stringify(administrationMock))));

const administration = await loadBvvAdministration(coordinateMock);

expect(configServiceSpy).toHaveBeenCalled();
expect(httpServiceSpy).toHaveBeenCalled();
expect(administration.community).toBe(administrationMock.gemeinde);
expect(administration.district).toBe(administrationMock.gemarkung);
expect(administration.parcel).toBe(administrationMock.flstBezeichnung);
});

it('return null when for status 404', async () => {
const backendUrl = 'https://backend.url';
const configServiceSpy = spyOn(configService, 'getValueAsPath').withArgs('BACKEND_URL').and.returnValue(backendUrl);
Expand Down

0 comments on commit a0fea4d

Please sign in to comment.