@@ -42,14 +42,10 @@ describe('<DrawButton />', () => {
42
42
43
43
describe ( '#Drawing' , ( ) => {
44
44
xit ( 'draws points' , async ( ) => {
45
- renderInMapContext ( map , < DrawButton drawType = { 'Point' } /> ) ;
46
-
47
- const button = screen . getByRole ( 'button' ) ;
45
+ renderInMapContext ( map , < DrawButton pressed = { true } drawType = { 'Point' } /> ) ;
48
46
49
47
const digitizeLayer = DigitizeUtil . getDigitizeLayer ( map ) ;
50
48
51
- await userEvent . click ( button ) ;
52
-
53
49
clickMap ( map , 100 , 100 ) ;
54
50
55
51
expect ( digitizeLayer . getSource ( ) ?. getFeatures ( ) ) . toHaveLength ( 1 ) ;
@@ -60,14 +56,10 @@ describe('<DrawButton />', () => {
60
56
} ) ;
61
57
62
58
xit ( 'draws lines' , async ( ) => {
63
- renderInMapContext ( map , < DrawButton drawType = { 'LineString' } /> ) ;
64
-
65
- const button = screen . getByRole ( 'button' ) ;
59
+ renderInMapContext ( map , < DrawButton pressed = { true } drawType = { 'LineString' } /> ) ;
66
60
67
61
const digitizeLayer = DigitizeUtil . getDigitizeLayer ( map ) ;
68
62
69
- await userEvent . click ( button ) ;
70
-
71
63
clickMap ( map , 100 , 100 ) ;
72
64
73
65
doubleClickMap ( map , 120 , 100 ) ;
@@ -82,14 +74,10 @@ describe('<DrawButton />', () => {
82
74
} ) ;
83
75
84
76
xit ( 'draws polygons' , async ( ) => {
85
- renderInMapContext ( map , < DrawButton drawType = { 'Polygon' } /> ) ;
86
-
87
- const button = screen . getByRole ( 'button' ) ;
77
+ renderInMapContext ( map , < DrawButton pressed = { true } drawType = { 'Polygon' } /> ) ;
88
78
89
79
const digitizeLayer = DigitizeUtil . getDigitizeLayer ( map ) ;
90
80
91
- await userEvent . click ( button ) ;
92
-
93
81
clickMap ( map , 100 , 100 ) ;
94
82
95
83
clickMap ( map , 120 , 100 ) ;
@@ -111,14 +99,10 @@ describe('<DrawButton />', () => {
111
99
} ) ;
112
100
113
101
xit ( 'draws labels' , async ( ) => {
114
- renderInMapContext ( map , < DrawButton drawType = { 'Text' } /> ) ;
115
-
116
- const button = screen . getByRole ( 'button' ) ;
102
+ renderInMapContext ( map , < DrawButton pressed = { true } drawType = { 'Text' } /> ) ;
117
103
118
104
const digitizeLayer = DigitizeUtil . getDigitizeLayer ( map ) ;
119
105
120
- await userEvent . click ( button ) ;
121
-
122
106
clickMap ( map , 100 , 100 ) ;
123
107
124
108
const dialog = screen . getByRole ( 'dialog' ) ;
@@ -143,14 +127,10 @@ describe('<DrawButton />', () => {
143
127
} ) ;
144
128
145
129
xit ( 'aborts drawing labels' , async ( ) => {
146
- renderInMapContext ( map , < DrawButton drawType = { 'Text' } /> ) ;
147
-
148
- const button = screen . getByRole ( 'button' ) ;
130
+ renderInMapContext ( map , < DrawButton pressed = { true } drawType = { 'Text' } /> ) ;
149
131
150
132
const digitizeLayer = DigitizeUtil . getDigitizeLayer ( map ) ;
151
133
152
- await userEvent . click ( button ) ;
153
-
154
134
clickMap ( map , 100 , 100 ) ;
155
135
156
136
const dialog = screen . getByRole ( 'dialog' ) ;
@@ -170,14 +150,10 @@ describe('<DrawButton />', () => {
170
150
} ) ;
171
151
172
152
xit ( 'draws circles' , async ( ) => {
173
- renderInMapContext ( map , < DrawButton drawType = { 'Circle' } /> ) ;
174
-
175
- const button = screen . getByRole ( 'button' ) ;
153
+ renderInMapContext ( map , < DrawButton pressed = { true } drawType = { 'Circle' } /> ) ;
176
154
177
155
const digitizeLayer = DigitizeUtil . getDigitizeLayer ( map ) ;
178
156
179
- await userEvent . click ( button ) ;
180
-
181
157
clickMap ( map , 100 , 100 ) ;
182
158
183
159
clickMap ( map , 120 , 120 ) ;
@@ -190,14 +166,10 @@ describe('<DrawButton />', () => {
190
166
} ) ;
191
167
192
168
xit ( 'draws rectangles' , async ( ) => {
193
- renderInMapContext ( map , < DrawButton drawType = { 'Rectangle' } /> ) ;
194
-
195
- const button = screen . getByRole ( 'button' ) ;
169
+ renderInMapContext ( map , < DrawButton pressed = { true } drawType = { 'Rectangle' } /> ) ;
196
170
197
171
const digitizeLayer = DigitizeUtil . getDigitizeLayer ( map ) ;
198
172
199
- await userEvent . click ( button ) ;
200
-
201
173
clickMap ( map , 100 , 100 ) ;
202
174
203
175
clickMap ( map , 120 , 120 ) ;
@@ -215,27 +187,25 @@ describe('<DrawButton />', () => {
215
187
} ) ;
216
188
217
189
xit ( 'toggles off' , async ( ) => {
218
- renderInMapContext ( map , < DrawButton drawType = { 'Point' } /> ) ;
219
-
220
- const button = screen . getByRole ( 'button' ) ;
190
+ const { rerenderInMapContext } = renderInMapContext ( map , < DrawButton pressed = { false } drawType = { 'Point' } /> ) ;
221
191
222
192
const digitizeLayer = DigitizeUtil . getDigitizeLayer ( map ) ;
223
193
224
194
expect ( digitizeLayer . getSource ( ) ?. getFeatures ( ) ) . toHaveLength ( 0 ) ;
225
195
226
- await userEvent . click ( button ) ;
196
+ rerenderInMapContext ( < DrawButton pressed = { true } drawType = { 'Point' } /> ) ;
227
197
228
198
clickMap ( map , 100 , 100 ) ;
229
199
230
200
expect ( digitizeLayer . getSource ( ) ?. getFeatures ( ) ) . toHaveLength ( 1 ) ;
231
201
232
- await userEvent . click ( button ) ;
202
+ rerenderInMapContext ( < DrawButton pressed = { false } drawType = { 'Point' } /> ) ;
233
203
234
204
clickMap ( map , 120 , 100 ) ;
235
205
236
206
expect ( digitizeLayer . getSource ( ) ?. getFeatures ( ) ) . toHaveLength ( 1 ) ;
237
207
238
- await userEvent . click ( button ) ;
208
+ rerenderInMapContext ( < DrawButton pressed = { true } drawType = { 'Point' } /> ) ;
239
209
240
210
clickMap ( map , 120 , 100 ) ;
241
211
@@ -246,11 +216,14 @@ describe('<DrawButton />', () => {
246
216
const startSpy = jest . fn ( ) ;
247
217
const endSpy = jest . fn ( ) ;
248
218
249
- renderInMapContext ( map , < DrawButton drawType = { 'Polygon' } onDrawStart = { startSpy } onDrawEnd = { endSpy } /> ) ;
250
-
251
- const button = screen . getByRole ( 'button' ) ;
252
-
253
- await userEvent . click ( button ) ;
219
+ const { rerenderInMapContext } = renderInMapContext ( map , (
220
+ < DrawButton
221
+ pressed = { true }
222
+ drawType = { 'Polygon' }
223
+ onDrawStart = { startSpy }
224
+ onDrawEnd = { endSpy }
225
+ />
226
+ ) ) ;
254
227
255
228
expect ( startSpy ) . not . toBeCalled ( ) ;
256
229
expect ( endSpy ) . not . toBeCalled ( ) ;
@@ -277,22 +250,23 @@ describe('<DrawButton />', () => {
277
250
} ) ;
278
251
279
252
xit ( 'multiple draw buttons use the same digitize layer' , async ( ) => {
280
- renderInMapContext ( map , < >
281
- < DrawButton drawType = { 'Point' } > Point 1</ DrawButton >
282
- < DrawButton drawType = { 'Point' } > Point 2</ DrawButton >
283
- </ > ) ;
284
-
285
- const button1 = screen . getByText ( 'Point 1' ) ;
286
- const button2 = screen . getByText ( 'Point 2' ) ;
253
+ const { rerenderInMapContext } = renderInMapContext ( map , (
254
+ < >
255
+ < DrawButton pressed = { true } drawType = { 'Point' } > Point 1</ DrawButton >
256
+ < DrawButton drawType = { 'Point' } > Point 2</ DrawButton >
257
+ </ >
258
+ ) ) ;
287
259
288
260
const digitizeLayer = DigitizeUtil . getDigitizeLayer ( map ) ;
289
261
290
- await userEvent . click ( button1 ) ;
291
-
292
262
clickMap ( map , 100 , 100 ) ;
293
263
294
- await userEvent . click ( button1 ) ;
295
- await userEvent . click ( button2 ) ;
264
+ rerenderInMapContext (
265
+ < >
266
+ < DrawButton drawType = { 'Point' } > Point 1</ DrawButton >
267
+ < DrawButton pressed = { true } drawType = { 'Point' } > Point 2</ DrawButton >
268
+ </ >
269
+ ) ;
296
270
297
271
clickMap ( map , 120 , 120 ) ;
298
272
@@ -306,11 +280,7 @@ describe('<DrawButton />', () => {
306
280
307
281
map . addLayer ( layer ) ;
308
282
309
- renderInMapContext ( map , < DrawButton drawType = { 'Point' } digitizeLayer = { layer } /> ) ;
310
-
311
- const button = screen . getByRole ( 'button' ) ;
312
-
313
- await userEvent . click ( button ) ;
283
+ renderInMapContext ( map , < DrawButton pressed = { true } drawType = { 'Point' } digitizeLayer = { layer } /> ) ;
314
284
315
285
clickMap ( map , 100 , 100 ) ;
316
286
@@ -322,11 +292,7 @@ describe('<DrawButton />', () => {
322
292
} ) ;
323
293
324
294
xit ( 'can change the type' , async ( ) => {
325
- const { rerenderInMapContext } = renderInMapContext ( map , < DrawButton drawType = { 'Point' } /> ) ;
326
-
327
- const button = screen . getByRole ( 'button' ) ;
328
-
329
- await userEvent . click ( button ) ;
295
+ const { rerenderInMapContext } = renderInMapContext ( map , < DrawButton pressed = { true } drawType = { 'Point' } /> ) ;
330
296
331
297
clickMap ( map , 100 , 100 ) ;
332
298
@@ -335,7 +301,7 @@ describe('<DrawButton />', () => {
335
301
expect ( digitizeLayer . getSource ( ) ?. getFeatures ( ) ) . toHaveLength ( 1 ) ;
336
302
expect ( digitizeLayer . getSource ( ) ?. getFeatures ( ) [ 0 ] . getGeometry ( ) ?. getType ( ) ) . toBe ( 'Point' ) ;
337
303
338
- rerenderInMapContext ( < DrawButton drawType = { 'LineString' } /> ) ;
304
+ rerenderInMapContext ( < DrawButton pressed = { true } drawType = { 'LineString' } /> ) ;
339
305
340
306
clickMap ( map , 120 , 120 ) ;
341
307
doubleClickMap ( map , 140 , 140 ) ;
0 commit comments