|
1 | 1 | import 'jest-setup';
|
| 2 | +import axios from 'src/layer/__mocks__/axios'; |
2 | 3 |
|
3 | 4 | import { BBox, CRS_EPSG4326, ApiType, MimeTypes, WmsLayer } from 'src';
|
4 | 5 |
|
@@ -36,3 +37,45 @@ test('WmsLayer.getMapUrl returns an URL', () => {
|
36 | 37 | expect(imageUrl).not.toHaveQueryParams(['showlogo']);
|
37 | 38 | expect(imageUrl).not.toHaveQueryParams(['transparent']);
|
38 | 39 | });
|
| 40 | + |
| 41 | +test('WmsLayer.getMap makes an appropriate request', () => { |
| 42 | + const bbox = new BBox(CRS_EPSG4326, 19, 20, 20, 21); |
| 43 | + const layerId = 'PROBAV_S1_TOA_333M'; |
| 44 | + const layer = new WmsLayer( |
| 45 | + 'https://proba-v-mep.esa.int/applications/geo-viewer/app/geoserver/ows', |
| 46 | + layerId, |
| 47 | + ); |
| 48 | + |
| 49 | + const getMapParams = { |
| 50 | + bbox: bbox, |
| 51 | + fromTime: new Date(Date.UTC(2020, 1 - 1, 10, 0, 0, 0)), // 2020-01-10/2020-01-10 |
| 52 | + toTime: new Date(Date.UTC(2020, 1 - 1, 10, 23, 59, 59)), |
| 53 | + width: 512, |
| 54 | + height: 512, |
| 55 | + format: MimeTypes.JPEG, |
| 56 | + }; |
| 57 | + layer.getMap(getMapParams, ApiType.WMS); |
| 58 | + |
| 59 | + expect(axios.get).toHaveBeenCalledTimes(1); |
| 60 | + |
| 61 | + const call: any = axios.get.mock.calls[0]; // cast to `any` so we can access the parameters |
| 62 | + const [url, axiosParams] = call; |
| 63 | + |
| 64 | + expect(url).toHaveOrigin('https://proba-v-mep.esa.int'); |
| 65 | + expect(url).toHaveQueryParamsValues({ |
| 66 | + service: 'WMS', |
| 67 | + version: '1.1.1', |
| 68 | + request: 'GetMap', |
| 69 | + format: 'image/jpeg', |
| 70 | + layers: layerId, |
| 71 | + crs: 'EPSG:4326', |
| 72 | + bbox: '19,20,20,21', |
| 73 | + time: '2020-01-10T00:00:00.000Z/2020-01-10T23:59:59.000Z', |
| 74 | + width: '512', |
| 75 | + height: '512', |
| 76 | + }); |
| 77 | + expect(axiosParams).toEqual({ |
| 78 | + responseType: 'blob', |
| 79 | + useCache: true, |
| 80 | + }); |
| 81 | +}); |
0 commit comments