-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.test.js
More file actions
150 lines (136 loc) · 3.43 KB
/
map.test.js
File metadata and controls
150 lines (136 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import React from "react"
import renderer from "react-test-renderer"
import mapbox from "mapbox-gl"
import Map from "../map"
import GeoJsonSource from "../map/geojson-source"
import BboxLayer from "../map/bbox-layer"
import { NEGATIVE } from "../../utils/constants"
import { colors } from "../../theme"
let mapWrapper
let container
describe("Map", () => {
beforeEach(() => {
renderer.act(() => {
mapWrapper = renderer.create(
<Map height={200}>
<GeoJsonSource id="test">
<BboxLayer id="test" bbox={[32, 5, 35, 10]} />
</GeoJsonSource>
</Map>,
{
createNodeMock: element => {
container = element
return element
},
}
)
})
})
it("renders correctly", () => {
expect(mapWrapper.toJSON()).toMatchSnapshot()
})
it("adds a map", () => {
expect(mapbox.Map).toHaveBeenCalledWith({
container,
cooperativeGestures: false,
style: `mapbox://styles/covid-nasa/cm7etyf7t003s01qpfq8kec7y`,
zoom: 1,
center: [0, 0],
})
})
})
const sourceId = "test-source"
const layerId = "test-layer"
const geojson = {
type: "FeatureCollection",
features: [],
}
const bbox = [32, 5, 35, 10]
let sourceWrapper, layerWrapper
describe("GeoJsonSource", () => {
it("adds a map source", () => {
renderer.act(() => {
sourceWrapper = renderer.create(
<GeoJsonSource id={sourceId} map={mapbox.Map()} geojson={geojson} />
)
})
expect(sourceWrapper.toTree().props.map.addSource).toHaveBeenCalledWith(
`${sourceId}-source`,
{
type: "geojson",
data: geojson,
}
)
})
})
describe("BboxLayer", () => {
beforeEach(() => {
renderer.act(() => {
layerWrapper = renderer.create(
<BboxLayer
id={layerId}
bbox={bbox}
sourceId={sourceId}
map={mapbox.Map()}
/>
)
})
})
it("adds a map layer", () => {
expect(layerWrapper.toTree().props.map.addLayer).toHaveBeenCalledWith({
id: `${layerId}-layer`,
layout: {},
paint: {
"line-color": colors[NEGATIVE].text,
"line-opacity": 0.8,
"line-width": 2,
},
source: sourceId,
type: "line",
})
})
//ensure switch is working as expected with "campaign", "explore" or "test"
it("does not zoom to the data", () => {
expect(layerWrapper.toTree().props.map.flyTo).not.toHaveBeenCalled()
})
describe("when id is 'campaign'", () => {
it("zooms to the data", () => {
renderer.act(() => {
layerWrapper = renderer.create(
<BboxLayer
id="campaign"
bbox={bbox}
sourceId={sourceId}
map={mapbox.Map()}
/>
)
})
expect(layerWrapper.toTree().props.map.flyTo).toHaveBeenCalledWith({
center: [-73.5804, 45.53483],
pitch: 60,
bearing: -60,
zoom: 10,
})
})
})
describe("when id is 'explore'", () => {
it("zooms to the data", () => {
renderer.act(() => {
layerWrapper = renderer.create(
<BboxLayer
id="explore"
bbox={bbox}
sourceId={sourceId}
map={mapbox.Map()}
/>
)
})
expect(layerWrapper.toTree().props.map.flyTo).toHaveBeenCalledWith({
center: [-73.5804, 45.53483],
pitch: 60,
bearing: -60,
zoom: 10,
})
})
})
})