@@ -11,18 +11,24 @@ test.describe('Treeview', () => {
11
11
// Wait for WMS GetCapabilities promise
12
12
let getCapabilitiesWMSPromise = page . waitForRequest ( / S E R V I C E = W M S & R E Q U E S T = G e t C a p a b i l i t i e s / ) ;
13
13
// Wait for WMS GetLegendGraphic promise
14
- const getLegendGraphicPromise = page . waitForRequest ( request => request . method ( ) === 'POST' && request . postData ( ) != null && request . postData ( ) ?. includes ( 'GetLegendGraphic' ) === true ) ;
14
+ const getLegendGraphicPromise = page . waitForRequest (
15
+ request => request . method ( ) === 'POST' &&
16
+ request . postData ( ) != null &&
17
+ request . postData ( ) ?. includes ( 'GetLegendGraphic' ) === true
18
+ ) ;
15
19
await page . goto ( url ) ;
16
20
// Wait for WMS GetCapabilities
17
21
await getCapabilitiesWMSPromise ;
18
22
// Wait for WMS GetLegendGraphic
19
23
let getLegendGraphicRequest = await getLegendGraphicPromise ;
20
24
21
25
// Check WMS GetLegendGraphic postData
22
- const getLegendGraphicRequestPostData = getLegendGraphicRequest . postData ( ) ;
23
- expect ( getLegendGraphicRequestPostData ) . toContain ( 'SERVICE=WMS' )
24
- expect ( getLegendGraphicRequestPostData ) . toContain ( 'REQUEST=GetLegendGraphic' )
25
- expect ( getLegendGraphicRequestPostData ) . toContain ( 'LAYER=sousquartiers%2Cquartiers%2Cshop_bakery_pg%2Ctramway_lines%2Cgroup_as_layer_1%2Cgroup_as_layer_2' )
26
+ const searchParams = new URLSearchParams ( getLegendGraphicRequest . postData ( ) ?? '' ) ;
27
+ expect ( searchParams . get ( 'SERVICE' ) ) . toBe ( 'WMS' ) ;
28
+ expect ( searchParams . get ( 'REQUEST' ) ) . toBe ( 'GetLegendGraphic' ) ;
29
+ expect ( searchParams . get ( 'LAYER' ) ) . toBe (
30
+ 'sousquartiers,quartiers,shop_bakery_pg,tramway_lines,group_as_layer_1,group_as_layer_2'
31
+ ) ;
26
32
27
33
// Check that the map scale is the right one
28
34
await expect ( page . locator ( '#overview-bar .ol-scale-text' ) ) . toHaveText ( '1 : ' + ( 100180 ) . toLocaleString ( locale ) )
@@ -40,8 +46,12 @@ test.describe('Treeview', () => {
40
46
await expect ( page . getByTestId ( 'sub-group1' ) . getByTestId ( 'subdistricts' ) ) . toHaveCount ( 1 )
41
47
await expect ( page . getByTestId ( 'subdistricts' ) ) . toBeVisible ( )
42
48
await expect ( page . getByTestId ( 'group with space in name and shortname defined' ) ) . toHaveCount ( 1 )
43
- await expect ( page . getByTestId ( 'group with space in name and shortname defined' ) . getByTestId ( 'quartiers' ) ) . toHaveCount ( 1 )
44
- await expect ( page . getByTestId ( 'group with space in name and shortname defined' ) . getByTestId ( 'shop_bakery_pg' ) ) . toHaveCount ( 1 )
49
+ await expect (
50
+ page . getByTestId ( 'group with space in name and shortname defined' ) . getByTestId ( 'quartiers' )
51
+ ) . toHaveCount ( 1 )
52
+ await expect (
53
+ page . getByTestId ( 'group with space in name and shortname defined' ) . getByTestId ( 'shop_bakery_pg' )
54
+ ) . toHaveCount ( 1 )
45
55
await expect ( page . getByTestId ( 'tramway_lines' ) ) . toHaveCount ( 1 )
46
56
await expect ( page . getByTestId ( 'tramway_lines' ) ) . toHaveText ( 'Tramway lines' )
47
57
await expect ( page . getByTestId ( 'group-without-children' ) ) . toHaveCount ( 0 )
@@ -169,7 +179,8 @@ test.describe('Treeview', () => {
169
179
} ) ;
170
180
} ) ;
171
181
172
- test . describe ( 'Treeview mocked with "Hide checkboxes for groups" option' , ( ) => {
182
+ test . describe ( 'Treeview mocked' , ( ) => {
183
+
173
184
test ( '"Hide checkboxes for groups" option' , async ( { page } ) => {
174
185
await page . route ( '**/service/getProjectConfig*' , async route => {
175
186
const response = await route . fetch ( ) ;
@@ -183,4 +194,165 @@ test.describe('Treeview mocked with "Hide checkboxes for groups" option', () =>
183
194
184
195
await expect ( page . locator ( 'lizmap-treeview div.group > input' ) ) . toHaveCount ( 0 ) ;
185
196
} ) ;
197
+
198
+ test ( 'Timeout on GetLegendGraphic with multi layers' , async ( { page } ) => {
199
+ const timedOutRequest = [ ] ;
200
+ const GetLegends = [ ] ;
201
+ await page . route ( '**/service*' , async route => {
202
+ const request = await route . request ( ) ;
203
+ if ( request . method ( ) !== 'POST' ) {
204
+ // GetLegendGraphic is a POST request
205
+ // Continue the request for non POST requests
206
+ await route . continue ( ) ;
207
+ return ;
208
+ }
209
+ const searchParams = new URLSearchParams ( request . postData ( ) ?? '' ) ;
210
+ if ( searchParams . get ( 'SERVICE' ) !== 'WMS' ||
211
+ ! searchParams . has ( 'REQUEST' ) ||
212
+ searchParams . get ( 'REQUEST' ) !== 'GetLegendGraphic' ) {
213
+ // Continue the request for non GetLegendGraphic requests
214
+ await route . continue ( ) ;
215
+ return ;
216
+ }
217
+ if ( ! searchParams . has ( 'LAYER' ) ) {
218
+ // Continue the request for GetLegendGraphic without LAYER parameter
219
+ await route . continue ( ) ;
220
+ return ;
221
+ }
222
+ const layers = searchParams . get ( 'LAYER' ) ?. split ( ',' ) ;
223
+ if ( layers ?. length == 1 ) {
224
+ // Continue the request for GetLegendGraphic with one layer
225
+ GetLegends . push ( searchParams ) ;
226
+ await route . continue ( ) ;
227
+ return ;
228
+ }
229
+ timedOutRequest . push ( searchParams ) ;
230
+ // Timeout on GetLegendGraphic with multi layers
231
+ await route . fulfill ( {
232
+ status : 504 ,
233
+ contentType : 'text/plain' ,
234
+ body : 'Timeout' ,
235
+ } ) ;
236
+ } ) ;
237
+ const url = '/index.php/view/map/?repository=testsrepository&project=treeview' ;
238
+ // Wait for WMS GetCapabilities promise
239
+ let getCapabilitiesWMSPromise = page . waitForRequest ( / S E R V I C E = W M S & R E Q U E S T = G e t C a p a b i l i t i e s / ) ;
240
+
241
+ await page . goto ( url ) ;
242
+
243
+ // Wait for WMS GetCapabilities
244
+ await getCapabilitiesWMSPromise ;
245
+
246
+ let timeCount = 0 ;
247
+ while ( GetLegends . length < 6 ) {
248
+ timeCount += 100 ;
249
+ if ( timeCount > 1000 ) {
250
+ break ;
251
+ }
252
+ await page . waitForTimeout ( 100 ) ;
253
+ }
254
+
255
+ await expect ( GetLegends . length ) . toBeGreaterThanOrEqual ( 6 ) ;
256
+ await expect ( timedOutRequest . length ) . toBeGreaterThanOrEqual ( 1 ) ;
257
+
258
+ // Check that the GetLegendGraphic requests are well formed
259
+ GetLegends . forEach ( ( searchParams ) => {
260
+ expect ( searchParams . get ( 'SERVICE' ) ) . toBe ( 'WMS' ) ;
261
+ expect ( searchParams . get ( 'REQUEST' ) ) . toBe ( 'GetLegendGraphic' ) ;
262
+ expect ( searchParams . get ( 'VERSION' ) ) . toBe ( '1.3.0' ) ;
263
+ expect ( searchParams . get ( 'FORMAT' ) ) . toBe ( 'application/json' ) ;
264
+ expect ( searchParams . get ( 'LAYER' ) ) . toBeDefined ( ) ;
265
+ expect ( searchParams . get ( 'LAYER' ) ) . not . toContain ( ',' ) ;
266
+ expect ( searchParams . get ( 'STYLES' ) ) . toBeDefined ( ) ;
267
+ expect ( searchParams . get ( 'STYLES' ) ) . not . toContain ( ',' ) ;
268
+ } ) ;
269
+
270
+ // Check that the timed out GetLegendGraphic requests are well formed
271
+ timedOutRequest . forEach ( ( searchParams ) => {
272
+ expect ( searchParams . get ( 'SERVICE' ) ) . toBe ( 'WMS' ) ;
273
+ expect ( searchParams . get ( 'REQUEST' ) ) . toBe ( 'GetLegendGraphic' ) ;
274
+ expect ( searchParams . get ( 'VERSION' ) ) . toBe ( '1.3.0' ) ;
275
+ expect ( searchParams . get ( 'FORMAT' ) ) . toBe ( 'application/json' ) ;
276
+ expect ( searchParams . get ( 'LAYER' ) ) . toBeDefined ( ) ;
277
+ expect ( searchParams . get ( 'LAYER' ) ) . toContain ( ',' ) ;
278
+ expect ( searchParams . get ( 'STYLES' ) ) . toBeDefined ( ) ;
279
+ expect ( searchParams . get ( 'STYLES' ) ) . toContain ( ',' ) ;
280
+ } ) ;
281
+
282
+ await page . unroute ( '**/service*' ) ;
283
+ } ) ;
284
+
285
+ test ( 'Error on GetLegendGraphic' , async ( { page } ) => {
286
+ const abortedRequest = [ ] ;
287
+ const GetLegends = [ ] ;
288
+ await page . route ( '**/service*' , async route => {
289
+ const request = await route . request ( ) ;
290
+ if ( request . method ( ) !== 'POST' ) {
291
+ // GetLegendGraphic is a POST request
292
+ // Continue the request for non POST requests
293
+ await route . continue ( ) ;
294
+ return ;
295
+ }
296
+ const searchParams = new URLSearchParams ( request . postData ( ) ?? '' ) ;
297
+ if ( searchParams . get ( 'SERVICE' ) !== 'WMS' ||
298
+ ! searchParams . has ( 'REQUEST' ) ||
299
+ searchParams . get ( 'REQUEST' ) !== 'GetLegendGraphic' ) {
300
+ // Continue the request for non GetLegendGraphic requests
301
+ await route . continue ( ) ;
302
+ return ;
303
+ }
304
+ if ( ! searchParams . has ( 'LAYER' ) ) {
305
+ // Continue the request for GetLegendGraphic without LAYER parameter
306
+ await route . continue ( ) ;
307
+ return ;
308
+ }
309
+ const layers = searchParams . get ( 'LAYER' ) ?. split ( ',' ) ;
310
+ if ( layers ?. length == 1 ) {
311
+ // Continue the request for GetLegendGraphic with one layer
312
+ GetLegends . push ( searchParams ) ;
313
+ await route . continue ( ) ;
314
+ return ;
315
+ }
316
+ abortedRequest . push ( searchParams ) ;
317
+ // Abort the request for GetLegendGraphic with multiple layers
318
+ await route . abort ( 'failed' ) ;
319
+ } ) ;
320
+
321
+ const url = '/index.php/view/map/?repository=testsrepository&project=treeview' ;
322
+ // Wait for WMS GetCapabilities promise
323
+ let getCapabilitiesWMSPromise = page . waitForRequest ( / S E R V I C E = W M S & R E Q U E S T = G e t C a p a b i l i t i e s / ) ;
324
+
325
+ await page . goto ( url ) ;
326
+
327
+ // Wait for WMS GetCapabilities
328
+ await getCapabilitiesWMSPromise ;
329
+
330
+ // Wait for WMS GetLegendGraphic
331
+ let timeCount = 0 ;
332
+ while ( GetLegends . length < 6 ) {
333
+ timeCount += 100 ;
334
+ if ( timeCount > 200 ) {
335
+ break ;
336
+ }
337
+ await page . waitForTimeout ( 100 ) ;
338
+ }
339
+
340
+ // Check if the GetLegendGraphic requests were all aborted
341
+ await expect ( GetLegends . length ) . toBe ( 0 ) ;
342
+ await expect ( abortedRequest . length ) . toBe ( 1 ) ;
343
+
344
+ // Check that the aborted GetLegendGraphic requests are well formed
345
+ abortedRequest . forEach ( ( searchParams ) => {
346
+ expect ( searchParams . get ( 'SERVICE' ) ) . toBe ( 'WMS' ) ;
347
+ expect ( searchParams . get ( 'REQUEST' ) ) . toBe ( 'GetLegendGraphic' ) ;
348
+ expect ( searchParams . get ( 'VERSION' ) ) . toBe ( '1.3.0' ) ;
349
+ expect ( searchParams . get ( 'FORMAT' ) ) . toBe ( 'application/json' ) ;
350
+ expect ( searchParams . get ( 'LAYER' ) ) . toBeDefined ( ) ;
351
+ expect ( searchParams . get ( 'LAYER' ) ) . toContain ( ',' ) ;
352
+ expect ( searchParams . get ( 'STYLES' ) ) . toBeDefined ( ) ;
353
+ expect ( searchParams . get ( 'STYLES' ) ) . toContain ( ',' ) ;
354
+ } ) ;
355
+
356
+ await page . unroute ( '**/service*' ) ;
357
+ } ) ;
186
358
} ) ;
0 commit comments