Skip to content

Commit 3dd618d

Browse files
committed
Merge branch 'master' into feat/drawing-manager
2 parents fe88a2f + 114c1c7 commit 3dd618d

23 files changed

+250
-77
lines changed

__mocks__/azure-maps-control.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
class DataSource {
2+
add = jest.fn()
3+
clear = jest.fn()
4+
remove = jest.fn()
5+
importDataFromUrl = jest.fn()
6+
setOptions = jest.fn()
7+
}
8+
19
module.exports = {
210
Map: jest.fn(() => ({
311
controls: {
@@ -66,7 +74,9 @@ module.exports = {
6674
CompassControl: jest.fn(() => ({ compassOption: 'option' })),
6775
PitchControl: jest.fn(() => ({ pitchOption: 'option' })),
6876
StyleControl: jest.fn(() => ({ styleOption: 'option' })),
69-
ZoomControl: jest.fn(() => ({ zoomOption: 'option' }))
77+
ZoomControl: jest.fn(() => ({ zoomOption: 'option' })),
78+
TrafficControl: jest.fn(() => ({ trafficOption: 'option' })),
79+
TrafficLegendControl: jest.fn(() => ({ trafficLegendOption: 'option' }))
7080
},
7181
layer: {
7282
ImageLayer: jest.fn((options, id) => ({ layer: 'ImageLayer', options, id })),
@@ -111,13 +121,11 @@ module.exports = {
111121
}))
112122
},
113123
source: {
114-
DataSource: jest.fn(() => ({
115-
add: jest.fn(),
116-
clear: jest.fn(),
117-
remove: jest.fn(),
118-
importDataFromUrl: jest.fn(),
119-
setOptions: jest.fn()
120-
}))
124+
DataSource,
125+
VectorTileSource: jest.fn((id, options) => ({
126+
getId: jest.fn(() => id),
127+
getOptions: jest.fn(() => options)
128+
}))
121129
},
122130
Shape: jest.fn(() => ({
123131
setCoordinates: jest.fn(),

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-azure-maps",
3-
"version": "0.2.1",
3+
"version": "0.3.0",
44
"description": "React Wrapper for Azure Maps",
55
"keywords": [
66
"react",

src/components/AzureMap/AzureMap.test.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import { AzureMapsContext } from '../../contexts/AzureMapContext'
44
import AzureMap from './AzureMap'
55
import { Map } from 'azure-maps-control'
66
import { IAzureMap, IAzureMapsContextProps } from '../../types'
7-
import { useCreateImageSprites } from './useCreateSprites'
8-
import { useCreateMapCustomControls, useCreateMapControls } from './useCreateMapControls'
7+
import { createImageSprites } from './useCreateSprites'
8+
import { createMapCustomControls, createMapControls } from './useCreateMapControls'
99

1010
const LoaderComponent = () => <div>Loader</div>
1111

1212
jest.mock('./useCreateMapControls', () => {
1313
return {
14-
useCreateMapCustomControls: jest.fn(),
15-
useCreateMapControls: jest.fn()
14+
createMapCustomControls: jest.fn(),
15+
createMapControls: jest.fn()
1616
}
1717
})
1818

@@ -108,25 +108,25 @@ describe('AzureMap Component', () => {
108108
expect(mapContextProps.removeMapRef).toHaveBeenCalled()
109109
})
110110

111-
it('should call useCreateImageSprites if imageSprites is not falsy', () => {
111+
it('should call createImageSprites if imageSprites is not falsy', () => {
112112
const mapRef = new Map('fake', {})
113113
render(
114114
wrapWithAzureMapContext(
115115
{ ...mapContextProps, mapRef },
116116
{ imageSprites: [{ id: 'some_fake_id' }] }
117117
)
118118
)
119-
expect(useCreateImageSprites).toHaveBeenCalled()
119+
expect(createImageSprites).toHaveBeenCalled()
120120
})
121121

122-
it('should call useCreateMapControls if controls is not falsy', () => {
122+
it('should call createMapControls if controls is not falsy', () => {
123123
const mapRef = new Map('fake', {})
124124
const fakeControls = [{ controlName: 'fake_control_name' }]
125125
render(wrapWithAzureMapContext({ ...mapContextProps, mapRef }, { controls: fakeControls }))
126-
expect(useCreateMapControls).toHaveBeenCalledWith(expect.any(Object), fakeControls)
126+
expect(createMapControls).toHaveBeenCalledWith(expect.any(Object), fakeControls)
127127
})
128128

129-
it('should call useCreateMapCustomControls if customControls is not falsy', () => {
129+
it('should call createMapCustomControls if customControls is not falsy', () => {
130130
const mapRef = new Map('fake', {})
131131
const customControls = [
132132
{
@@ -142,7 +142,7 @@ describe('AzureMap Component', () => {
142142
}
143143
)
144144
)
145-
expect(useCreateMapCustomControls).toHaveBeenCalledWith(expect.any(Object), customControls)
145+
expect(createMapCustomControls).toHaveBeenCalledWith(expect.any(Object), customControls)
146146
})
147147

148148
it('should setTraffic on initial props', () => {

src/components/AzureMap/AzureMap.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { Guid } from 'guid-typescript'
66
import 'azure-maps-control/dist/atlas.min.css'
77
import 'mapbox-gl/src/css/mapbox-gl.css'
88
import { useCheckRef } from '../../hooks/useCheckRef'
9-
import { useCreateImageSprites } from './useCreateSprites'
10-
import { useCreateMapControls, useCreateMapCustomControls } from './useCreateMapControls'
9+
import { createImageSprites } from './useCreateSprites'
10+
import { createMapControls, createMapCustomControls } from './useCreateMapControls'
1111

1212
const AzureMap = memo(
1313
({
@@ -64,13 +64,13 @@ const AzureMap = memo(
6464
useCheckRef<MapType, MapType>(mapRef, mapRef, mref => {
6565
mref.events.add('ready', () => {
6666
if (imageSprites) {
67-
useCreateImageSprites(mref, imageSprites)
67+
createImageSprites(mref, imageSprites)
6868
}
6969
if (controls) {
70-
useCreateMapControls(mref, controls)
70+
createMapControls(mref, controls)
7171
}
7272
if (customControls) {
73-
useCreateMapCustomControls(mref, customControls)
73+
createMapCustomControls(mref, customControls)
7474
}
7575
if (trafficOptions) {
7676
mref.setTraffic(trafficOptions)

src/components/AzureMap/useCreateMapControl.test.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { renderHook } from '@testing-library/react-hooks'
22
import {
33
createControl,
4-
useCreateMapControls,
5-
useCreateMapCustomControls
4+
createMapControls,
5+
createMapCustomControls
66
} from './useCreateMapControls'
77
import { Map } from 'azure-maps-control'
88
import { IAzureMapControls, IAzureCustomControls } from '../../types'
@@ -34,7 +34,7 @@ describe('Control hooks', () => {
3434
it('should create two map controls and call proper method', () => {
3535
const mockMap = new Map('#fake-container', {})
3636
mockMap.controls.add = jest.fn()
37-
renderHook(() => useCreateMapControls(mockMap, fakeDefaultControls))
37+
renderHook(() => createMapControls(mockMap, fakeDefaultControls))
3838
expect(mockMap.controls.add).toHaveBeenCalledWith(
3939
{ compassOption: 'option' },
4040
fakeDefaultControls[0].options
@@ -46,11 +46,11 @@ describe('Control hooks', () => {
4646
})
4747
})
4848

49-
describe('useCreateMapCustomControls tests', () => {
49+
describe('createMapCustomControls tests', () => {
5050
it('should create custom map controls and call proper method', () => {
5151
const mockMap = new Map('#fake-container', {})
5252
mockMap.controls.add = jest.fn()
53-
renderHook(() => useCreateMapCustomControls(mockMap, fakeCustomControlls))
53+
renderHook(() => createMapCustomControls(mockMap, fakeCustomControlls))
5454
expect(mockMap.controls.add).toHaveBeenCalledTimes(1)
5555
expect(mockMap.controls.add).toHaveBeenCalledWith(
5656
fakeCustomControlls[0].control,
@@ -80,6 +80,16 @@ describe('Control hooks', () => {
8080
expect(createdControl).toEqual({ compassOption: 'option' })
8181
})
8282

83+
it('should return TrafficControl if type equal TrafficControl', () => {
84+
const createdControl = createControl('TrafficControl', {})
85+
expect(createdControl).toEqual({ trafficOption: 'option' })
86+
})
87+
88+
it('should return TrafficLegendControl if type equal TrafficLegendControl', () => {
89+
const createdControl = createControl('TrafficLegendControl', {})
90+
expect(createdControl).toEqual({ trafficLegendOption: 'option' })
91+
})
92+
8393
it('should return undefined if there is no control with type', () => {
8494
const createdControl = createControl('SomeOtherType', {})
8595
expect(createdControl).toEqual(undefined)

src/components/AzureMap/useCreateMapControls.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import atlas, {
44
ControlOptions,
55
PitchControlOptions,
66
StyleControlOptions,
7+
TrafficControlOptions,
78
ZoomControlOptions
89
} from 'azure-maps-control'
910

1011

1112

12-
export const useCreateMapControls = (mapRef: MapType, controls: IAzureMapControls[]) => {
13+
export const createMapControls = (mapRef: MapType, controls: IAzureMapControls[]) => {
1314
controls.forEach((control: IAzureMapControls) => {
1415
const { controlName, options, controlOptions } = control
1516
mapRef.controls.add(
@@ -32,16 +33,21 @@ export const createControl = (
3233
return new atlas.control.StyleControl(options as StyleControlOptions)
3334
case 'ZoomControl':
3435
return new atlas.control.ZoomControl(options as ZoomControlOptions)
36+
case 'TrafficControl':
37+
return new atlas.control.TrafficControl(options as TrafficControlOptions)
38+
case 'TrafficLegendControl':
39+
return new atlas.control.TrafficLegendControl()
3540
default:
3641
console.warn('Check the type and passed props properties or try CustomControl')
3742
}
3843
}
3944

40-
export const useCreateMapCustomControls = (
45+
export const createMapCustomControls = (
4146
mapRef: MapType,
4247
customControls: IAzureCustomControls[]
4348
) => {
4449
customControls.forEach(({ control, controlOptions }: IAzureCustomControls) => {
4550
mapRef.controls.add(control, controlOptions)
4651
})
4752
}
53+

src/components/AzureMap/useCreateSprites.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { renderHook } from '@testing-library/react-hooks'
2-
import { useCreateImageSprites } from './useCreateSprites'
2+
import { createImageSprites } from './useCreateSprites'
33
import { Map } from 'azure-maps-control'
44

5-
describe('useCreateImageSprites tests', () => {
5+
describe('createImageSprites tests', () => {
66
it('should create image sprintes with icon field and call proper methods', async () => {
77
const mockMap = new Map('#fake-container', {})
88
const fakeImageSprite = {
@@ -13,7 +13,7 @@ describe('useCreateImageSprites tests', () => {
1313
secondaryColor: 'color',
1414
scale: 1
1515
}
16-
const { result } = renderHook(() => useCreateImageSprites(mockMap, [fakeImageSprite]))
16+
const { result } = renderHook(() => createImageSprites(mockMap, [fakeImageSprite]))
1717
await result.current
1818
expect(mockMap.imageSprite.add).toHaveBeenCalledWith('id', 'icon')
1919
expect(mockMap.imageSprite.createFromTemplate).toHaveBeenCalledWith(
@@ -34,7 +34,7 @@ describe('useCreateImageSprites tests', () => {
3434
secondaryColor: 'color',
3535
scale: 1
3636
}
37-
const { result } = renderHook(() => useCreateImageSprites(mockMap, [fakeImageSprite]))
37+
const { result } = renderHook(() => createImageSprites(mockMap, [fakeImageSprite]))
3838
await result.current
3939
expect(mockMap.imageSprite.add).not.toHaveBeenCalled()
4040
expect(mockMap.imageSprite.createFromTemplate).toHaveBeenCalledWith(
@@ -54,7 +54,7 @@ describe('useCreateImageSprites tests', () => {
5454
secondaryColor: 'color',
5555
scale: 1
5656
}
57-
const { result } = renderHook(() => useCreateImageSprites(mockMap, [fakeImageSprite]))
57+
const { result } = renderHook(() => createImageSprites(mockMap, [fakeImageSprite]))
5858
await result.current
5959
expect(mockMap.imageSprite.add).not.toHaveBeenCalled()
6060
expect(mockMap.imageSprite.createFromTemplate).toHaveBeenCalledWith(

src/components/AzureMap/useCreateSprites.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { IAzureMapImageSprite, MapType } from '../../types'
22

3-
export const useCreateImageSprites = async (
3+
export const createImageSprites = async (
44
mapRef: MapType,
55
spriteArray: IAzureMapImageSprite[]
66
) => {

src/components/AzureMapFeature/AzureMapFeature.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import atlas from 'azure-maps-control'
99

1010
jest.mock('./useFeature')
1111
jest.mock('./useCreateAzureMapFeature.ts', () => ({
12-
useCreateAzureMapFeature: () => ({})
12+
createAzureMapFeature: () => ({})
1313
}))
1414

1515
const mapRef = new Map('fake', {})

src/components/AzureMapFeature/AzureMapFeature.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import atlas from 'azure-maps-control'
33

44
import { FeatureType, IAzureMapDataSourceProps, IAzureMapFeature, ShapeType } from '../../types'
55
import { AzureMapDataSourceContext } from '../../contexts/AzureMapDataSourceContext'
6-
import { useCreateAzureMapFeature } from './useCreateAzureMapFeature'
6+
import { createAzureMapFeature } from './useCreateAzureMapFeature'
77
import { useFeature } from './useFeature'
88

99
const AzureMapFeature = memo((props: IAzureMapFeature) => {
@@ -15,7 +15,7 @@ const AzureMapFeature = memo((props: IAzureMapFeature) => {
1515
useFeature(props, dataSourceRef, shapeRef, featureRef)
1616

1717
useEffect(() => {
18-
const featureSource: atlas.data.Geometry | undefined = useCreateAzureMapFeature(props)
18+
const featureSource: atlas.data.Geometry | undefined = createAzureMapFeature(props)
1919

2020
if ((!featureRef || !shapeRef) && featureSource) {
2121
switch (variant) {

src/components/AzureMapFeature/useCreateAzureMapFeature.test.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import atlas from 'azure-maps-control'
22
import { IAzureMapFeature } from '../../types'
3-
import { useCreateAzureMapFeature } from './useCreateAzureMapFeature'
3+
import { createAzureMapFeature } from './useCreateAzureMapFeature'
44

55
const fakeCoordinate: atlas.data.Position = new atlas.data.Position(10, 10)
66
const fakeCoordinates: atlas.data.Position[] = [
@@ -20,13 +20,13 @@ const fakeBbox: atlas.data.BoundingBox = new atlas.data.BoundingBox(
2020
)
2121

2222
describe('AzureMapFeature hooks', () => {
23-
describe('useCreateAzureMapFeature tests', () => {
23+
describe('createAzureMapFeature tests', () => {
2424
it('should return Point if type equal Point', () => {
2525
const pointProps: IAzureMapFeature = {
2626
type: 'Point',
2727
coordinate: fakeCoordinate
2828
}
29-
const createPoint = useCreateAzureMapFeature(pointProps)
29+
const createPoint = createAzureMapFeature(pointProps)
3030
expect(createPoint).toEqual({ coords: [10, 10], type: 'Point' })
3131
})
3232
it('should return MultiPoint if type equal MultiPoint', () => {
@@ -35,7 +35,7 @@ describe('AzureMapFeature hooks', () => {
3535
coordinates: fakeCoordinates,
3636
bbox: fakeBbox
3737
}
38-
const createMultiPoint = useCreateAzureMapFeature(multiPointProps)
38+
const createMultiPoint = createAzureMapFeature(multiPointProps)
3939
expect(createMultiPoint).toEqual({
4040
bbox: [
4141
[10, 10],
@@ -54,7 +54,7 @@ describe('AzureMapFeature hooks', () => {
5454
coordinates: fakeCoordinates,
5555
bbox: fakeBbox
5656
}
57-
const createLineString = useCreateAzureMapFeature(lineStringProps)
57+
const createLineString = createAzureMapFeature(lineStringProps)
5858
expect(createLineString).toEqual({
5959
bbox: [
6060
[10, 10],
@@ -73,7 +73,7 @@ describe('AzureMapFeature hooks', () => {
7373
multipleCoordinates: fakeMultipleCoordinates,
7474
bbox: fakeBbox
7575
}
76-
const createMultiLineStringProps = useCreateAzureMapFeature(multiLineStringProps)
76+
const createMultiLineStringProps = createAzureMapFeature(multiLineStringProps)
7777
expect(createMultiLineStringProps).toEqual({
7878
bbox: [
7979
[10, 10],
@@ -89,7 +89,7 @@ describe('AzureMapFeature hooks', () => {
8989
coordinates: fakeCoordinates,
9090
bbox: fakeBbox
9191
}
92-
const createLineString = useCreateAzureMapFeature(lineStringProps)
92+
const createLineString = createAzureMapFeature(lineStringProps)
9393
expect(createLineString).toEqual({
9494
bbox: [
9595
[10, 10],
@@ -108,7 +108,7 @@ describe('AzureMapFeature hooks', () => {
108108
multipleDimensionCoordinates: fakeMultipleDimensionCoordinates,
109109
bbox: fakeBbox
110110
}
111-
const createMultiPolygon = useCreateAzureMapFeature(multiPolygonProps)
111+
const createMultiPolygon = createAzureMapFeature(multiPolygonProps)
112112
expect(createMultiPolygon).toEqual({
113113
bbox: [
114114
[10, 10],

src/components/AzureMapFeature/useCreateAzureMapFeature.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { IAzureMapFeature } from '../../types'
22
import atlas from 'azure-maps-control'
33

4-
export const useCreateAzureMapFeature = ({
4+
export const createAzureMapFeature = ({
55
type,
66
coordinate,
77
coordinates,

0 commit comments

Comments
 (0)