|
| 1 | +/* |
| 2 | + * Copyright 2014, GeoSolutions Sas. |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * This source code is licensed under the BSD-style license found in the |
| 6 | + * LICENSE file in the root directory of this source tree. |
| 7 | + */ |
| 8 | + |
| 9 | +import expect from 'expect'; |
| 10 | + |
| 11 | +import { addBackgroundProperties, SET_BACKGROUND_MODAL_PARAMS } from '../../actions/backgroundselector'; |
| 12 | +import { testEpic } from './epicTestUtils'; |
| 13 | +import backgroundEpics from '../backgroundselector'; |
| 14 | +import MockAdapter from 'axios-mock-adapter'; |
| 15 | +import axios from '../../libs/ajax'; |
| 16 | +let mockAxios; |
| 17 | + |
| 18 | +describe('addBackgroundPropertiesEpic Epics', () => { |
| 19 | + beforeEach((done) => { |
| 20 | + mockAxios = new MockAdapter(axios); |
| 21 | + setTimeout(done); |
| 22 | + }); |
| 23 | + afterEach((done) => { |
| 24 | + mockAxios.restore(); |
| 25 | + setTimeout(done); |
| 26 | + }); |
| 27 | + const capabilitiesWMSXmlResponse = `<?xml version="1.0" encoding="UTF-8"?> |
| 28 | +<Capabilities xmlns="http://www.opengis.net/wmts/1.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gml="http://www.opengis.net/gml" xsi:schemaLocation="http://www.opengis.net/wmts/1.0 http://schemas.opengis.net/wmts/1.0/wmtsGetCapabilities_response.xsd" version="1.0.0"> |
| 29 | +<Contents> |
| 30 | + <Layer> |
| 31 | + <Title/> |
| 32 | + <Abstract/> |
| 33 | + <!--Limited list of EPSG projections:--> |
| 34 | + <BoundingBox CRS="CRS:84" minx="-124.73142200000001" miny="-43.648056" maxx="148.47914100000003" maxy="49.371735"/> |
| 35 | + <Layer queryable="1" opaque="0"> |
| 36 | + <Name>states_test</Name> |
| 37 | + <Title>states_test</Title> |
| 38 | + <Abstract>states_test</Abstract> |
| 39 | + <KeywordList> |
| 40 | + <Keyword>features</Keyword> |
| 41 | + <Keyword>states</Keyword> |
| 42 | + </KeywordList> |
| 43 | + <CRS>EPSG:4326</CRS> |
| 44 | + <CRS>CRS:84</CRS> |
| 45 | + <EX_GeographicBoundingBox> |
| 46 | + <westBoundLongitude>-124.73142200000001</westBoundLongitude> |
| 47 | + <eastBoundLongitude>-66.969849</eastBoundLongitude> |
| 48 | + <southBoundLatitude>24.955967</southBoundLatitude> |
| 49 | + <northBoundLatitude>49.371735</northBoundLatitude> |
| 50 | + </EX_GeographicBoundingBox> |
| 51 | + <BoundingBox CRS="CRS:84" minx="-124.73142200000001" miny="24.955967" maxx="-66.969849" maxy="49.371735"/> |
| 52 | + <BoundingBox CRS="EPSG:4326" minx="24.955967" miny="-124.73142200000001" maxx="49.371735" maxy="-66.969849"/> |
| 53 | + <Style> |
| 54 | + <Name>polygon</Name> |
| 55 | + <Title>A boring default style</Title> |
| 56 | + <Abstract>A sample style that just prints out a transparent red interior with a red outline</Abstract> |
| 57 | + <LegendURL width="20" height="20"> |
| 58 | + <Format>image/png</Format> |
| 59 | + <OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://gs-stable.geo-solutions.it/geoserver/topp/ows?service=WMS&request=GetLegendGraphic&format=image%2Fpng&width=20&height=20&layer=states_test"/> |
| 60 | + </LegendURL> |
| 61 | + </Style> |
| 62 | + <Format>image/png</Format> |
| 63 | + <Format>image/jpeg</Format> |
| 64 | + <Format>image/png8</Format> |
| 65 | + </Layer> |
| 66 | + </Layer> |
| 67 | +</Contents> |
| 68 | +</Capabilities>`; |
| 69 | + |
| 70 | + const capabilitiesWMTSXmlResponse = `<?xml version="1.0" encoding="UTF-8"?><WMS_Capabilities version="1.3.0" updateSequence="5167" xmlns="http://www.opengis.net/wms" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wms http://gs-stable.geo-solutions.it/geoserver/schemas/wms/1.3.0/capabilities_1_3_0.xsd"> |
| 71 | +<Capability> |
| 72 | + <Layer> |
| 73 | + <Title/> |
| 74 | + <Abstract/> |
| 75 | + <!--Limited list of EPSG projections:--> |
| 76 | + <BoundingBox CRS="CRS:84" minx="-124.73142200000001" miny="-43.648056" maxx="148.47914100000003" maxy="49.371735"/> |
| 77 | + <Layer queryable="1" opaque="0"> |
| 78 | + <Name>states_test</Name> |
| 79 | + <Title>states_test</Title> |
| 80 | + <Abstract>states_test</Abstract> |
| 81 | + <KeywordList> |
| 82 | + <Keyword>features</Keyword> |
| 83 | + <Keyword>states</Keyword> |
| 84 | + </KeywordList> |
| 85 | + <CRS>EPSG:4326</CRS> |
| 86 | + <CRS>CRS:84</CRS> |
| 87 | + <EX_GeographicBoundingBox> |
| 88 | + <westBoundLongitude>-124.73142200000001</westBoundLongitude> |
| 89 | + <eastBoundLongitude>-66.969849</eastBoundLongitude> |
| 90 | + <southBoundLatitude>24.955967</southBoundLatitude> |
| 91 | + <northBoundLatitude>49.371735</northBoundLatitude> |
| 92 | + </EX_GeographicBoundingBox> |
| 93 | + <BoundingBox CRS="CRS:84" minx="-124.73142200000001" miny="24.955967" maxx="-66.969849" maxy="49.371735"/> |
| 94 | + <BoundingBox CRS="EPSG:4326" minx="24.955967" miny="-124.73142200000001" maxx="49.371735" maxy="-66.969849"/> |
| 95 | + <Style> |
| 96 | + <Name>polygon</Name> |
| 97 | + <Title>A boring default style</Title> |
| 98 | + <Abstract>A sample style that just prints out a transparent red interior with a red outline</Abstract> |
| 99 | + <LegendURL width="20" height="20"> |
| 100 | + <Format>image/png</Format> |
| 101 | + <OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://gs-stable.geo-solutions.it/geoserver/topp/ows?service=WMS&request=GetLegendGraphic&format=image%2Fpng&width=20&height=20&layer=states_test"/> |
| 102 | + </LegendURL> |
| 103 | + </Style> |
| 104 | + </Layer> |
| 105 | + </Layer> |
| 106 | +</Capability> |
| 107 | +</WMS_Capabilities>`; |
| 108 | + it('test add normal background layer', (done) => { |
| 109 | + mockAxios.onGet().reply(200, capabilitiesWMSXmlResponse); |
| 110 | + let addBackgroundPropAction = addBackgroundProperties({ |
| 111 | + layer: { |
| 112 | + id: "layer01", allowedSRS: { |
| 113 | + "EPSG:3857": true, |
| 114 | + "EPSG:900913": true, |
| 115 | + "EPSG:4326": true |
| 116 | + }, |
| 117 | + title: "states_test", |
| 118 | + type: 'wms', |
| 119 | + name: "states_test", |
| 120 | + url: ['/geoserver/wms'], |
| 121 | + group: "background" |
| 122 | + }, |
| 123 | + editing: false |
| 124 | + }); |
| 125 | + |
| 126 | + testEpic(backgroundEpics.addBackgroundPropertiesEpic, 2, [addBackgroundPropAction], (res) => { |
| 127 | + const action1 = res[0]; |
| 128 | + const action2 = res[1]; |
| 129 | + expect(action1).toExist(); |
| 130 | + expect(action1.type).toEqual(SET_BACKGROUND_MODAL_PARAMS); |
| 131 | + expect(action1.modalParams.loading).toEqual(true); |
| 132 | + expect(action2).toExist(); |
| 133 | + expect(action2.type).toEqual(SET_BACKGROUND_MODAL_PARAMS); |
| 134 | + expect(action2.modalParams.loading).toEqual(false); |
| 135 | + expect(action2.modalParams.capabilities).toExist(); |
| 136 | + done(); |
| 137 | + }, {}); |
| 138 | + |
| 139 | + }); |
| 140 | + it('test add wms as a background layer without enabling remote custom tile grid', (done) => { |
| 141 | + mockAxios.onGet().reply(200, capabilitiesWMSXmlResponse); |
| 142 | + let addBackgroundPropAction = addBackgroundProperties({ |
| 143 | + layer: { |
| 144 | + id: "layer01", allowedSRS: { |
| 145 | + "EPSG:3857": true, |
| 146 | + "EPSG:900913": true, |
| 147 | + "EPSG:4326": true |
| 148 | + }, |
| 149 | + title: "states_test", |
| 150 | + type: 'wms', |
| 151 | + name: "states_test", |
| 152 | + url: '/geoserver/wms', |
| 153 | + group: "background" |
| 154 | + }, |
| 155 | + editing: false |
| 156 | + }); |
| 157 | + |
| 158 | + testEpic(backgroundEpics.addBackgroundPropertiesEpic, 2, [addBackgroundPropAction], (res) => { |
| 159 | + const action1 = res[0]; |
| 160 | + const action2 = res[1]; |
| 161 | + expect(action1).toExist(); |
| 162 | + expect(action1.type).toEqual(SET_BACKGROUND_MODAL_PARAMS); |
| 163 | + expect(action1.modalParams.loading).toEqual(true); |
| 164 | + expect(action2).toExist(); |
| 165 | + expect(action2.type).toEqual(SET_BACKGROUND_MODAL_PARAMS); |
| 166 | + expect(action2.modalParams.loading).toEqual(false); |
| 167 | + expect(action2.modalParams.capabilities).toExist(); |
| 168 | + done(); |
| 169 | + }, {}); |
| 170 | + }); |
| 171 | + it('test add wms as a background layer with enabling remote custom tile grid', (done) => { |
| 172 | + mockAxios.onGet().replyOnce(200, capabilitiesWMSXmlResponse); |
| 173 | + mockAxios.onGet().replyOnce(200, capabilitiesWMTSXmlResponse); |
| 174 | + let addBackgroundPropAction = addBackgroundProperties({ |
| 175 | + layer: { |
| 176 | + id: "layer01", allowedSRS: { |
| 177 | + "EPSG:3857": true, |
| 178 | + "EPSG:900913": true, |
| 179 | + "EPSG:4326": true |
| 180 | + }, |
| 181 | + title: "states_test", |
| 182 | + type: 'wms', |
| 183 | + name: "states_test", |
| 184 | + url: '/geoserver/wms', |
| 185 | + group: "background", |
| 186 | + remoteTileGrids: true |
| 187 | + }, |
| 188 | + editing: false |
| 189 | + }); |
| 190 | + |
| 191 | + testEpic(backgroundEpics.addBackgroundPropertiesEpic, 2, [addBackgroundPropAction], (res) => { |
| 192 | + const action1 = res[0]; |
| 193 | + const action2 = res[1]; |
| 194 | + expect(action1).toExist(); |
| 195 | + expect(action1.type).toEqual(SET_BACKGROUND_MODAL_PARAMS); |
| 196 | + expect(action1.modalParams.loading).toEqual(true); |
| 197 | + expect(action2).toExist(); |
| 198 | + expect(action2.type).toEqual(SET_BACKGROUND_MODAL_PARAMS); |
| 199 | + expect(action2.modalParams.loading).toEqual(false); |
| 200 | + expect(action2.modalParams.capabilities).toExist(); |
| 201 | + expect(action2.modalParams.layer.tiled).toEqual(true); |
| 202 | + expect(action2.modalParams.layer.tileGridStrategy).toEqual('custom'); |
| 203 | + done(); |
| 204 | + }, {}); |
| 205 | + }); |
| 206 | +}); |
0 commit comments