Skip to content

Commit

Permalink
add more tests + refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Zedwag committed Oct 10, 2024
1 parent 2c552af commit afb7ef9
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ const window = getWindow();

declare let atlas: any;

const AZURE_LINK = 'https://atlas.microsoft.com/';
let AZURE_JS_URL = `${AZURE_LINK}sdk/javascript/mapcontrol/3/atlas.min.js`;
let AZURE_CSS_URL = `${AZURE_LINK}/sdk/javascript/mapcontrol/3/atlas.min.css`;
const AZURE_BASE_LINK = 'https://atlas.microsoft.com/';
let AZURE_JS_URL = `${AZURE_BASE_LINK}sdk/javascript/mapcontrol/3/atlas.min.js`;
let AZURE_CSS_URL = `${AZURE_BASE_LINK}/sdk/javascript/mapcontrol/3/atlas.min.css`;
let CUSTOM_URL;

const MAP_MARKER_TOOLTIP_CLASS = 'dx-map-marker-tooltip';

const CAMERA_PADDING = 50;

const azureMapsLoaded = function () {
// @ts-expect-error
return window.atlas && window.atlas.Map;
Expand Down Expand Up @@ -66,7 +68,7 @@ const AzureProvider = DynamicProvider.inherit({
return;
}

const searchURL = `${AZURE_LINK}geocode?subscription-key=${this._keyOption('azure')}&api-version=2023-06-01&query=${location}&limit=1`;
const searchURL = `${AZURE_BASE_LINK}geocode?subscription-key=${this._keyOption('azure')}&api-version=2023-06-01&query=${location}&limit=1`;

ajax.sendRequest({
url: CUSTOM_URL ?? searchURL,
Expand Down Expand Up @@ -361,8 +363,7 @@ const AzureProvider = DynamicProvider.inherit({
const queryCoordinates = locations.map((location) => `${location[1]},${location[0]}`);
const query = queryCoordinates.join(':');
const routeType = this._movementMode(options.mode);
const isWalkingType = routeType === this._movementMode('walking');
const searchUrl = `${AZURE_LINK}route/directions/json?subscription-key=${this._keyOption('azure')}&api-version=1.0&query=${query}&travelMode=${routeType}`;
const searchUrl = `${AZURE_BASE_LINK}route/directions/json?subscription-key=${this._keyOption('azure')}&api-version=1.0&query=${query}&travelMode=${routeType}`;

ajax.sendRequest({
url: CUSTOM_URL ?? searchUrl,
Expand All @@ -376,22 +377,11 @@ const AzureProvider = DynamicProvider.inherit({

dataSource.add(new atlas.data.Feature(new atlas.data.LineString(routeCoordinates), {}));

const lineLayerConfig: {
strokeColor: string;
strokeOpacity: number;
strokeWidth: number;
strokeDashArray?: number[];
} = {
const lineLayer = new atlas.layer.LineLayer(dataSource, null, {
strokeColor: routeColor,
strokeOpacity: routeOpacity,
strokeWidth: options.weight || this._defaultRouteWeight(),
};

if (isWalkingType) {
lineLayerConfig.strokeDashArray = [1, 1];
}

const lineLayer = new atlas.layer.LineLayer(dataSource, null, lineLayerConfig);
});

this._map.sources.add(dataSource);
this._map.layers.add(lineLayer);
Expand Down Expand Up @@ -438,7 +428,7 @@ const AzureProvider = DynamicProvider.inherit({

this._map.setCamera({
bounds: this._bounds,
padding: 50,
padding: CAMERA_PADDING,
});

const zoomAfterFitting = this._map.getCamera().zoom;
Expand Down
23 changes: 14 additions & 9 deletions packages/devextreme/testing/helpers/forMap/azureMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@
}

this.events = {
add: (eventName, _, callback) => {
atlas.addedEvents = atlas.addedEvents || {};
atlas.addedEvents[eventName] = callback;
add: (eventName, targetOrCallback, callback) => {
atlas.addedEvents = atlas.addedEvents || [];
const callbackFun = callback ?? targetOrCallback;
atlas.addedEvents.push(eventName);

if(eventName === 'click') {
atlas.clickActionCallback = callback;
atlas.clickActionCallback = callbackFun;
}

if(eventName === 'move') {
atlas.moveActionCallback = callbackFun;
}
},
remove: (eventName) => {
atlas.removedEvents = atlas.removedEvents || {};
atlas.removedEvents[eventName] = true;
atlas.removedEvents = atlas.removedEvents || [];
atlas.removedEvents.push(eventName);
},
addOnce: () => {},
};
Expand All @@ -41,9 +46,9 @@
};
this.getCamera = () => {
return {
bounds: [0, 0, 1, 1],
center: [0, 0],
zoom: 10
bounds: [55, 5, 5, 55],
center: [5, 5],
zoom: 5
};
};
this.controls = {
Expand Down
Loading

0 comments on commit afb7ef9

Please sign in to comment.