From 1535ff0d6cad54c579159502de55e1610d8a059d Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Mon, 23 May 2022 12:19:59 +0200 Subject: [PATCH] Move map attribution to top right (#8621) Signed-off-by: Michael Weimann Co-authored-by: Michael Telatynski <7t3chguy@gmail.com> --- src/utils/location/map.ts | 2 ++ .../views/beacon/BeaconViewDialog-test.tsx | 4 +++ .../location/LocationViewDialog-test.tsx | 5 ++++ test/components/views/location/Map-test.tsx | 4 +++ .../LocationViewDialog-test.tsx.snap | 30 +++++++++++++++++-- .../views/messages/MBeaconBody-test.tsx | 5 ++++ .../views/messages/MLocationBody-test.tsx | 9 ++++++ .../__snapshots__/MLocationBody-test.tsx.snap | 25 +++++++++------- 8 files changed, 71 insertions(+), 13 deletions(-) diff --git a/src/utils/location/map.ts b/src/utils/location/map.ts index b3b74d1449..331fce4aee 100644 --- a/src/utils/location/map.ts +++ b/src/utils/location/map.ts @@ -36,7 +36,9 @@ export const createMap = ( style: styleUrl, zoom: 15, interactive, + attributionControl: false, }); + map.addControl(new maplibregl.AttributionControl(), 'top-right'); map.on('error', (e) => { logger.error( diff --git a/test/components/views/beacon/BeaconViewDialog-test.tsx b/test/components/views/beacon/BeaconViewDialog-test.tsx index 8d0fb30e30..12b4093939 100644 --- a/test/components/views/beacon/BeaconViewDialog-test.tsx +++ b/test/components/views/beacon/BeaconViewDialog-test.tsx @@ -89,6 +89,10 @@ describe('', () => { const getComponent = (props = {}) => mount(); + beforeAll(() => { + maplibregl.AttributionControl = jest.fn(); + }); + beforeEach(() => { jest.spyOn(OwnBeaconStore.instance, 'getLiveBeaconIds').mockRestore(); diff --git a/test/components/views/location/LocationViewDialog-test.tsx b/test/components/views/location/LocationViewDialog-test.tsx index fa23192bbf..af270c5f97 100644 --- a/test/components/views/location/LocationViewDialog-test.tsx +++ b/test/components/views/location/LocationViewDialog-test.tsx @@ -18,6 +18,7 @@ import React from 'react'; import { mount } from 'enzyme'; import { RoomMember } from 'matrix-js-sdk/src/matrix'; import { LocationAssetType } from 'matrix-js-sdk/src/@types/location'; +import maplibregl from 'maplibre-gl'; import LocationViewDialog from '../../../../src/components/views/location/LocationViewDialog'; import { TILE_SERVER_WK_KEY } from '../../../../src/utils/WellKnownUtils'; @@ -41,6 +42,10 @@ describe('', () => { const getComponent = (props = {}) => mount(); + beforeAll(() => { + maplibregl.AttributionControl = jest.fn(); + }); + it('renders map correctly', () => { const component = getComponent(); expect(component.find('Map')).toMatchSnapshot(); diff --git a/test/components/views/location/Map-test.tsx b/test/components/views/location/Map-test.tsx index 12915c192e..dc349793c6 100644 --- a/test/components/views/location/Map-test.tsx +++ b/test/components/views/location/Map-test.tsx @@ -44,6 +44,10 @@ describe('', () => { wrappingComponentProps: { value: matrixClient }, }); + beforeAll(() => { + maplibregl.AttributionControl = jest.fn(); + }); + beforeEach(() => { jest.clearAllMocks(); matrixClient.getClientWellKnown.mockReturnValue({ diff --git a/test/components/views/location/__snapshots__/LocationViewDialog-test.tsx.snap b/test/components/views/location/__snapshots__/LocationViewDialog-test.tsx.snap index a9f7a03f07..6104f0dad0 100644 --- a/test/components/views/location/__snapshots__/LocationViewDialog-test.tsx.snap +++ b/test/components/views/location/__snapshots__/LocationViewDialog-test.tsx.snap @@ -23,7 +23,20 @@ exports[` renders map correctly 1`] = ` }, "_eventsCount": 1, "_maxListeners": undefined, - "addControl": [MockFunction], + "addControl": [MockFunction] { + "calls": Array [ + Array [ + mockConstructor {}, + "top-right", + ], + ], + "results": Array [ + Object { + "type": "return", + "value": undefined, + }, + ], + }, "fitBounds": [MockFunction], "removeControl": [MockFunction], "setCenter": [MockFunction] { @@ -78,7 +91,20 @@ exports[` renders map correctly 1`] = ` }, "_eventsCount": 1, "_maxListeners": undefined, - "addControl": [MockFunction], + "addControl": [MockFunction] { + "calls": Array [ + Array [ + mockConstructor {}, + "top-right", + ], + ], + "results": Array [ + Object { + "type": "return", + "value": undefined, + }, + ], + }, "fitBounds": [MockFunction], "removeControl": [MockFunction], "setCenter": [MockFunction] { diff --git a/test/components/views/messages/MBeaconBody-test.tsx b/test/components/views/messages/MBeaconBody-test.tsx index 8719df567d..e9cb719f7f 100644 --- a/test/components/views/messages/MBeaconBody-test.tsx +++ b/test/components/views/messages/MBeaconBody-test.tsx @@ -79,6 +79,11 @@ describe('', () => { }); const modalSpy = jest.spyOn(Modal, 'createTrackedDialog').mockReturnValue(undefined); + + beforeAll(() => { + maplibregl.AttributionControl = jest.fn(); + }); + beforeEach(() => { jest.clearAllMocks(); }); diff --git a/test/components/views/messages/MLocationBody-test.tsx b/test/components/views/messages/MLocationBody-test.tsx index cc5a6105e5..ec2270f635 100644 --- a/test/components/views/messages/MLocationBody-test.tsx +++ b/test/components/views/messages/MLocationBody-test.tsx @@ -56,6 +56,15 @@ describe("MLocationBody", () => { wrappingComponent: MatrixClientContext.Provider, wrappingComponentProps: { value: mockClient }, }); + + beforeAll(() => { + maplibregl.AttributionControl = jest.fn(); + }); + + beforeEach(() => { + jest.clearAllMocks(); + }); + describe('with error', () => { let sdkConfigSpy; diff --git a/test/components/views/messages/__snapshots__/MLocationBody-test.tsx.snap b/test/components/views/messages/__snapshots__/MLocationBody-test.tsx.snap index f4914b510d..97ab9e0ac1 100644 --- a/test/components/views/messages/__snapshots__/MLocationBody-test.tsx.snap +++ b/test/components/views/messages/__snapshots__/MLocationBody-test.tsx.snap @@ -124,7 +124,20 @@ exports[`MLocationBody without error renders map correctly 1`] = }, "_eventsCount": 1, "_maxListeners": undefined, - "addControl": [MockFunction], + "addControl": [MockFunction] { + "calls": Array [ + Array [ + mockConstructor {}, + "top-right", + ], + ], + "results": Array [ + Object { + "type": "return", + "value": undefined, + }, + ], + }, "fitBounds": [MockFunction], "removeControl": [MockFunction], "setCenter": [MockFunction] { @@ -135,22 +148,12 @@ exports[`MLocationBody without error renders map correctly 1`] = "lon": -0.1276, }, ], - Array [ - Object { - "lat": 51.5076, - "lon": -0.1276, - }, - ], ], "results": Array [ Object { "type": "return", "value": undefined, }, - Object { - "type": "return", - "value": undefined, - }, ], }, "setStyle": [MockFunction],