|
| 1 | +require('../../../src/openlayers/control/ChangeTileVersion'); |
| 2 | + |
| 3 | +describe('openlayers_testChangeTileVersion', function () { |
| 4 | + var map, baseLayer; |
| 5 | + var tileVersions = [ |
| 6 | + { |
| 7 | + desc: "V1", |
| 8 | + name: "63477488-e91e-41a1-b029-c1c7b476a64d", |
| 9 | + parent: null, |
| 10 | + timestamp: 1503472107342, |
| 11 | + update: { |
| 12 | + bounds: { |
| 13 | + bottom: 3.853726078199864, |
| 14 | + left: 73.45169014635671, |
| 15 | + leftBottom: {x: 73.45169014635671, y: 3.853726078199864}, |
| 16 | + right: 134.9754744676044, |
| 17 | + rightTop: {x: 134.9754744676044, y: 66.826881183998}, |
| 18 | + top: 66.826881183998 |
| 19 | + }, |
| 20 | + resolutions: [0.15211472144423888, 0.07605736072211941, 0.03802868036105977], |
| 21 | + scaleDenominators: [64000000, 32000000, 16000000], |
| 22 | + } |
| 23 | + }, { |
| 24 | + desc: "V2", |
| 25 | + name: "38c8028a-8f13-43a2-9119-15acdc99f34f", |
| 26 | + parent: "63477488-e91e-41a1-b029-c1c7b476a64d", |
| 27 | + timestamp: 1503472306420, |
| 28 | + update: { |
| 29 | + bounds: { |
| 30 | + bottom: 3.853726078199864, |
| 31 | + left: 73.45169014635671, |
| 32 | + leftBottom: {x: 73.45169014635671, y: 3.853726078199864}, |
| 33 | + right: 134.9754744676044, |
| 34 | + rightTop: {x: 134.9754744676044, y: 66.826881183998}, |
| 35 | + top: 66.826881183998, |
| 36 | + }, |
| 37 | + resolutions: [0.15211472144423888, 0.07605736072211941, 0.03802868036105977], |
| 38 | + scaleDenominators: [64000000, 32000000, 16000000] |
| 39 | + } |
| 40 | + |
| 41 | + }]; |
| 42 | + beforeAll(function () { |
| 43 | + testDiv = window.document.createElement("div"); |
| 44 | + testDiv.setAttribute("id", "map"); |
| 45 | + testDiv.style.styleFloat = "left"; |
| 46 | + testDiv.style.marginLeft = "8px"; |
| 47 | + testDiv.style.marginTop = "50px"; |
| 48 | + testDiv.style.width = "500px"; |
| 49 | + testDiv.style.height = "500px"; |
| 50 | + window.document.body.appendChild(testDiv); |
| 51 | + |
| 52 | + var url = GlobeParameter.China4326URL; |
| 53 | + map = new ol.Map({ |
| 54 | + target: 'map', |
| 55 | + controls: ol.control.defaults({attributionOptions: {collapsed: false}}) |
| 56 | + .extend([new ol.supermap.control.Logo()]), |
| 57 | + view: new ol.View({ |
| 58 | + center: [104.79, 33.03], |
| 59 | + zoom: 4, |
| 60 | + projection: 'EPSG:4326' |
| 61 | + }) |
| 62 | + }); |
| 63 | + |
| 64 | + baseLayer = new ol.source.TileSuperMapRest({ |
| 65 | + origin: [-180, 90], |
| 66 | + url: url, |
| 67 | + wrapX: true |
| 68 | + }); |
| 69 | + |
| 70 | + map.addLayer(new ol.layer.Tile({ |
| 71 | + source: baseLayer, |
| 72 | + projection: 'EPSG:4326' |
| 73 | + })); |
| 74 | + }); |
| 75 | + |
| 76 | + it("constructor", function () { |
| 77 | + var options = { |
| 78 | + layer: baseLayer, |
| 79 | + orientation: "horizontal" |
| 80 | + }; |
| 81 | + var result = new ol.supermap.control.ChangeTileVersion(options); |
| 82 | + expect(result).not.toBeNull(); |
| 83 | + expect(result.firstLoad).toBeTruthy(); |
| 84 | + expect(result.options.collapsed).toBeTruthy(); |
| 85 | + expect(result.options.switch).toBeTruthy(); |
| 86 | + expect(result.options.orientation).toBe("horizontal"); |
| 87 | + expect(result.options.title).toBe("切换缓存版本"); |
| 88 | + expect(result.options.tooltip).toBe("top"); |
| 89 | + }); |
| 90 | + |
| 91 | + it("setLayer", function () { |
| 92 | + var options = { |
| 93 | + orientation: "horizontal" |
| 94 | + }; |
| 95 | + var changetileversion = new ol.supermap.control.ChangeTileVersion(options); |
| 96 | + var result = changetileversion.setLayer(baseLayer); |
| 97 | + expect(result).not.toBeNull(); |
| 98 | + expect(result.firstLoad).toBeTruthy(); |
| 99 | + expect(result.options.collapsed).toBeTruthy(); |
| 100 | + expect(result.options.switch).toBeTruthy(); |
| 101 | + expect(result.options.orientation).toBe("horizontal"); |
| 102 | + expect(result.options.title).toBe("切换缓存版本"); |
| 103 | + expect(result.options.tooltip).toBe("top"); |
| 104 | + }); |
| 105 | + |
| 106 | + it("removeLayer", function () { |
| 107 | + var options = { |
| 108 | + orientation: "horizontal" |
| 109 | + }; |
| 110 | + var changetileversion = new ol.supermap.control.ChangeTileVersion(options); |
| 111 | + var result = changetileversion.removeLayer(); |
| 112 | + expect(result.options.layer).toBeNull(); |
| 113 | + }); |
| 114 | + |
| 115 | + it("tilesVersion", function () { |
| 116 | + var options = { |
| 117 | + layer: baseLayer, |
| 118 | + orientation: "horizontal" |
| 119 | + }; |
| 120 | + var changetileversion = new ol.supermap.control.ChangeTileVersion(options); |
| 121 | + var version = '63477488-e91e-41a1-b029-c1c7b476a64d'; |
| 122 | + changetileversion.update(tileVersions); |
| 123 | + changetileversion.tilesVersion(version); |
| 124 | + expect(tileVersions[0].name).toBe(version); |
| 125 | + }); |
| 126 | + |
| 127 | + it("getValue", function () { |
| 128 | + var options = { |
| 129 | + layer: baseLayer, |
| 130 | + orientation: "horizontal" |
| 131 | + }; |
| 132 | + var changetileversion = new ol.supermap.control.ChangeTileVersion(options); |
| 133 | + changetileversion.update(tileVersions); |
| 134 | + var result = changetileversion.getValue(); |
| 135 | + expect(result).not.toBeNull(); |
| 136 | + expect(result).toBe('0'); |
| 137 | + |
| 138 | + }); |
| 139 | + |
| 140 | + it("nextTilesVersion", function () { |
| 141 | + var options = { |
| 142 | + layer: baseLayer, |
| 143 | + orientation: "horizontal" |
| 144 | + }; |
| 145 | + var changetileversion = new ol.supermap.control.ChangeTileVersion(options); |
| 146 | + changetileversion.update(tileVersions); |
| 147 | + changetileversion.nextTilesVersion(); |
| 148 | + expect(changetileversion).not.toBeNull(); |
| 149 | + expect(changetileversion.firstLoad).toBeFalsy(); |
| 150 | + expect(changetileversion.getValue()).toBe('0'); |
| 151 | + }); |
| 152 | + |
| 153 | + it("lastTilesVersion", function () { |
| 154 | + var options = { |
| 155 | + layer: baseLayer, |
| 156 | + orientation: "horizontal" |
| 157 | + }; |
| 158 | + var changetileversion = new ol.supermap.control.ChangeTileVersion(options); |
| 159 | + changetileversion.update(tileVersions); |
| 160 | + changetileversion.lastTilesVersion(); |
| 161 | + expect(changetileversion).not.toBeNull(); |
| 162 | + expect(changetileversion.getValue()).toBe('0'); |
| 163 | + |
| 164 | + }); |
| 165 | + |
| 166 | + it("setContent", function () { |
| 167 | + var options = { |
| 168 | + layer: baseLayer, |
| 169 | + orientation: "horizontal" |
| 170 | + }; |
| 171 | + var changetileversion = new ol.supermap.control.ChangeTileVersion(options); |
| 172 | + var version = tileVersions[0]; |
| 173 | + changetileversion.setContent(version); |
| 174 | + expect(changetileversion.tooltip.innerHTML).toBe("V1"); |
| 175 | + }); |
| 176 | + |
| 177 | + it("getVersion", function () { |
| 178 | + var options = { |
| 179 | + layer: baseLayer, |
| 180 | + orientation: "horizontal" |
| 181 | + }; |
| 182 | + var changetileversion = new ol.supermap.control.ChangeTileVersion(options); |
| 183 | + changetileversion.update(tileVersions); |
| 184 | + var result = changetileversion.getVersion(); |
| 185 | + expect(result).toBe('63477488-e91e-41a1-b029-c1c7b476a64d'); |
| 186 | + |
| 187 | + }); |
| 188 | +}); |
| 189 | + |
0 commit comments