Skip to content

Commit

Permalink
【ut】fix ut 不稳定; review by songym
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongjiaojiao committed Dec 6, 2024
1 parent df55cdf commit d0bcc51
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 79 deletions.
9 changes: 5 additions & 4 deletions test/mapboxgl/mapping/WebMapSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ describe('mapboxgl_WebMap', () => {
var mapJson = datavizWebMap_RestMap;
return Promise.resolve(new Response(mapJson));
}
return Promise.resolve();
return Promise.resolve(new Response(JSON.stringify({})));
});

var datavizWebmap = new WebMap(id, options);
Expand Down Expand Up @@ -1317,20 +1317,21 @@ describe('mapboxgl_WebMap', () => {
target: 'map',
withCredentials: false
};
var datavizWebmap1 = new WebMap('', { ...commonOption }, mapOptionsList[0]);
datavizWebmap = new WebMap('', { ...commonOption }, mapOptionsList[0]);

const callback = function () {
var datavizWebmap2 = new WebMap(id, {
server: server
});
datavizWebmap2.once('mapcreatesucceeded', function () {
const type1 = datavizWebmap1.getWebMapType();
const type1 = datavizWebmap.getWebMapType();
const type2 = datavizWebmap2.getWebMapType();
expect(type1).toBe('MapStyle');
expect(type2).toBe('WebMap2');
datavizWebmap2.cleanLayers();
done();
});
};
datavizWebmap1.once('mapcreatesucceeded', callback);
datavizWebmap.once('mapcreatesucceeded', callback);
});
});
76 changes: 42 additions & 34 deletions test/mapboxgl/mapping/WebMapV2Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,7 @@ describe('mapboxgl_WebMapV2', () => {
if (url.indexOf('map.json') > -1) {
return Promise.resolve(new Response(raster4490));
}
if (url.indexOf('jubu4490.json') > -1) {
return Promise.resolve(new Response(JSON.stringify({})));
}
return Promise.resolve();
return Promise.resolve(new Response(RET_MAP_INFO_4490));
});
datavizWebmap = new WebMap(
id,
Expand Down Expand Up @@ -526,7 +523,7 @@ describe('mapboxgl_WebMapV2', () => {
if (url.indexOf('web/datas/1920557079/content.json') > -1) {
return Promise.resolve(new Response(layerData_CSV));
}
return Promise.resolve();
return Promise.resolve(new Response(JSON.stringify({})));
});
const id = heatLayer;
datavizWebmap = new WebMap(id, { ...commonOption });
Expand All @@ -545,7 +542,7 @@ describe('mapboxgl_WebMapV2', () => {
if (url.indexOf('China_Dark.json') > -1) {
return Promise.resolve(new Response(JSON.stringify({})));
}
return Promise.resolve();
return Promise.resolve(new Response(JSON.stringify({})));
});
const id = rangeLayer;
const callback = function (data) {
Expand Down Expand Up @@ -598,8 +595,6 @@ describe('mapboxgl_WebMapV2', () => {
return Promise.resolve(new Response(raster4490));
} else if (url.indexOf('jubu4490.json') > -1) {
return Promise.resolve(new Response(JSON.stringify({})));
} else if (url.indexOf('jubu4490.json') > -1) {
return Promise.resolve(new Response(JSON.stringify({})));
}
return Promise.resolve();
});
Expand Down Expand Up @@ -679,7 +674,7 @@ describe('mapboxgl_WebMapV2', () => {

it('request wkt info and visibleExtend without EPSFG Prefix ', (done) => {
const epsgeCode =
'PROJCS["Google Maps Global Mercator",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]],PROJECTION["Mercator_2SP"],PARAMETER["standard_parallel_1",0],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",0],PARAMETER["false_easting",0],PARAMETER["false_northing",0],AXIS["Northing", "NORTH"],AXIS["Easting", "EAST"],UNIT["Meter",1],EXTENSION["PROJ4","+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs"],AUTHORITY["EPSG","900913"]]';
'PROJCS["unnamed",GEOGCS["GRS 1980(IUGG, 1980)",DATUM["unknown",SPHEROID["GRS80",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic_1SP"],PARAMETER["latitude_of_origin",43.0695160375],PARAMETER["central_meridian",-89.42222222222223],PARAMETER["scale_factor",1.0000384786],PARAMETER["false_easting",811000],PARAMETER["false_northing",480943.886],AXIS["Northing", "NORTH"],AXIS["Easting", "EAST"],UNIT["Foot_US",0.3048006096012192],AUTHORITY["epsg","7599"]]';
spyOn(FetchRequest, 'get').and.callFake((url) => {
if (url.indexOf('web/datas/676516522/content.json') > -1) {
return Promise.resolve(new Response(layerData_CSV));
Expand Down Expand Up @@ -788,7 +783,7 @@ describe('mapboxgl_WebMapV2', () => {
if (url.indexOf('web/datas/1171594968/content.json') > -1) {
return Promise.resolve(new Response(layerData_CSV));
}
return Promise.resolve();
return Promise.resolve(new Response(JSON.stringify({})));
});
const id = rangeLayer;
datavizWebmap = new WebMap(id, { ...commonOption });
Expand Down Expand Up @@ -1102,7 +1097,7 @@ describe('mapboxgl_WebMapV2', () => {
if (url.indexOf('web/datas/123456/content.json') > -1) {
return Promise.resolve(new Response(JSON.stringify(layerData_geojson['MARKER_GEOJSON'])));
}
return Promise.resolve();
return Promise.resolve(new Response(JSON.stringify({})));
});
const id = markerLayer;
datavizWebmap = new WebMap(id, { ...commonOption });
Expand All @@ -1118,7 +1113,7 @@ describe('mapboxgl_WebMapV2', () => {
if (url.indexOf('web/datas/123456/content.json') > -1) {
return Promise.resolve(new Response(JSON.stringify(layerData_geojson['MARKER_GEOJSON'])));
}
return Promise.resolve();
return Promise.resolve(new Response(JSON.stringify({})));
});
const id = markerLayer;
datavizWebmap = new WebMap(id, { ...commonOption, map: commonMap }, { ...commonMapOptions });
Expand Down Expand Up @@ -1146,7 +1141,7 @@ describe('mapboxgl_WebMapV2', () => {
)
);
}
return Promise.resolve();
return Promise.resolve(new Response(JSON.stringify({})));
});
const id = markerLayer;
datavizWebmap = new WebMap(id, { ...commonOption });
Expand All @@ -1164,12 +1159,11 @@ describe('mapboxgl_WebMapV2', () => {
...layerData_geojson['MARKER_GEOJSON'],
content
};
const contentData = JSON.parse(content);
spyOn(FetchRequest, 'get').and.callFake((url) => {
if (url.indexOf('web/datas/1795361105/content.json') > -1) {
return Promise.resolve(new Response(JSON.stringify(newLayerData_geojson)));
}
return Promise.resolve();
return Promise.resolve(new Response(JSON.stringify({})));
});
const layers = [
{
Expand Down Expand Up @@ -1229,7 +1223,7 @@ describe('mapboxgl_WebMapV2', () => {
if (url.indexOf('web/datas/676516522/content.json') > -1) {
return Promise.resolve(new Response(layerData_CSV));
}
return Promise.resolve();
return Promise.resolve(new Response(JSON.stringify({})));
});
const id = ranksymbolLayer;
datavizWebmap = new WebMap(id, { ...commonOption });
Expand All @@ -1256,7 +1250,7 @@ describe('mapboxgl_WebMapV2', () => {
} else if (url.indexOf('iserver/services/dataflowTest/dataflow/subscribe') > -1) {
return Promise.resolve(new Response(JSON.stringify(dataflowLayerData.subscribe)));
}
return Promise.resolve();
return Promise.resolve(new Response(JSON.stringify({})));
});
datavizWebmap = new WebMap(dataflowLayer, { ...commonOption, map: commonMap }, undefined);
const callback = function (data) {
Expand Down Expand Up @@ -1286,6 +1280,7 @@ describe('mapboxgl_WebMapV2', () => {
} else if (url.indexOf('datas/144371940/content.json')) {
return Promise.resolve(new Response(JSON.stringify(layerData_geojson['LINE_GEOJSON'])));
}
return Promise.resolve(new Response(JSON.stringify({})));
});
datavizWebmap = new WebMap(id, { ...commonOption, map: commonMap }, { ...commonMapOptions });
datavizWebmap.on('mapcreatesucceeded', (data) => {
Expand Down Expand Up @@ -1477,7 +1472,7 @@ describe('mapboxgl_WebMapV2', () => {
} else if (url.indexOf('web/datas/13136933/content.json') > -1) {
return Promise.resolve(new Response(JSON.stringify(layerData_geojson['POINT_GEOJSON'])));
}
return Promise.resolve();
return Promise.resolve(new Response(JSON.stringify({})));
});
const id = vectorLayer_point;
datavizWebmap = new WebMap(id, { ...commonOption, map: commonMap }, undefined);
Expand Down Expand Up @@ -1534,7 +1529,7 @@ describe('mapboxgl_WebMapV2', () => {
} else if (url.indexOf('/map.json') > -1) {
return Promise.resolve(new Response(datavizWebmap_ZXYTILE));
}
return Promise.resolve();
return Promise.resolve(new Response(JSON.stringify({})));
});
datavizWebmap = new WebMap(
'test',
Expand Down Expand Up @@ -1564,7 +1559,7 @@ describe('mapboxgl_WebMapV2', () => {
} else if (url.indexOf('web/maps/test/map.json') > -1) {
return Promise.resolve(new Response(raster4490));
}
return Promise.resolve();
return Promise.resolve(new Response(JSON.stringify({})));
});
datavizWebmap = new WebMap(
'test',
Expand Down Expand Up @@ -1755,7 +1750,7 @@ describe('mapboxgl_WebMapV2', () => {
if (url.indexOf('map-world/wms130') > -1) {
return Promise.resolve(new Response(wmsCapabilitiesText));
}
return Promise.resolve();
return Promise.resolve(new Response(JSON.stringify({})));
});
const mapData = {
...wmsLayer,
Expand All @@ -1780,7 +1775,7 @@ describe('mapboxgl_WebMapV2', () => {
if (url.indexOf('map-world/wms130') > -1) {
return Promise.resolve(new Response(wmsCapabilitiesTextWith130));
}
return Promise.resolve();
return Promise.resolve(new Response(JSON.stringify({})));
});
const callback = function (data) {
expect(data).not.toBeUndefined();
Expand All @@ -1807,7 +1802,7 @@ describe('mapboxgl_WebMapV2', () => {
if (url.indexOf('map-china400/wmts100') > -1) {
return Promise.resolve(new Response(wmtsCapabilitiesText));
}
return Promise.resolve();
return Promise.resolve(new Response(JSON.stringify({})));
});
datavizWebmap = new WebMap(baseLayers['WMTS'], { ...commonOption });
const callback = function (data) {
Expand Down Expand Up @@ -1853,6 +1848,9 @@ describe('mapboxgl_WebMapV2', () => {
});

it('tile layer', (done) => {
spyOn(FetchRequest, 'get').and.callFake(() => {
return Promise.resolve(new Response(JSON.stringify({})));
});
datavizWebmap = new WebMap(
restmapLayer,
{ ...commonOption, ignoreBaseProjection: true, map: commonMap },
Expand All @@ -1869,7 +1867,7 @@ describe('mapboxgl_WebMapV2', () => {
if (url.indexOf('web/datas/1920557079/content.json') > -1) {
return Promise.resolve(new Response(layerData_CSV));
}
return Promise.resolve();
return Promise.resolve(new Response(JSON.stringify({})));
});
datavizWebmap = new WebMap(heatLayer, { ...commonOption, map: commonMap }, { ...commonMapOptions });
const callback = function () {
Expand All @@ -1880,6 +1878,9 @@ describe('mapboxgl_WebMapV2', () => {
});

it('different projection', (done) => {
spyOn(FetchRequest, 'get').and.callFake((url) => {
return Promise.resolve(new Response(JSON.stringify({})));
});
const callback = function (data) {
expect(data).not.toBeUndefined();
done();
Expand All @@ -1898,6 +1899,9 @@ describe('mapboxgl_WebMapV2', () => {
});

it('add online map', (done) => {
spyOn(FetchRequest, 'get').and.callFake((url) => {
return Promise.resolve(new Response(JSON.stringify({})));
});
datavizWebmap = new WebMap(baseLayers['TILE'], {
isSuperMapOnline: true,
serverUrl: 'https://www.supermapol.com'
Expand Down Expand Up @@ -2052,7 +2056,7 @@ describe('mapboxgl_WebMapV2', () => {
if (url.indexOf('web/datas/1920557079/content.json') > -1) {
return Promise.resolve(new Response(layerData_CSV));
}
return Promise.resolve();
return Promise.resolve(new Response(JSON.stringify({})));
});
datavizWebmap = new WebMap(
vectorLayer_line,
Expand All @@ -2079,7 +2083,7 @@ describe('mapboxgl_WebMapV2', () => {
if (url.indexOf('web/datas/13136933/content.json') > -1) {
return Promise.resolve(new Response(JSON.stringify(layerData_geojson['POINT_GEOJSON'])));
}
return Promise.resolve();
return Promise.resolve(new Response(JSON.stringify({})));
});
const id = {
...uniqueLayer_multi_points,
Expand Down Expand Up @@ -2115,6 +2119,7 @@ describe('mapboxgl_WebMapV2', () => {
} else if (url.indexOf('China.json') > -1) {
return Promise.resolve(new Response(JSON.stringify({})));
}
return Promise.resolve(new Response(JSON.stringify({})));
});
datavizWebmap = new WebMap(id, { ...commonOption });
const callback = function (data) {
Expand Down Expand Up @@ -2178,6 +2183,7 @@ describe('mapboxgl_WebMapV2', () => {
} else if (url.indexOf('China.json') > -1) {
return Promise.resolve(new Response(JSON.stringify({})));
}
return Promise.resolve(new Response(JSON.stringify({})));
});
const map = {
...commonMap,
Expand Down Expand Up @@ -2423,7 +2429,7 @@ describe('mapboxgl_WebMapV2', () => {
} else if (url.indexOf('portal.json') > -1) {
return Promise.resolve(new Response(JSON.stringify(iportal_serviceProxy)));
}
return Promise.resolve();
return Promise.resolve(new Response(JSON.stringify({})));
});
datavizWebmap = new WebMap(id, {
server: server
Expand All @@ -2443,7 +2449,7 @@ describe('mapboxgl_WebMapV2', () => {
} else if (url.indexOf('portal.json') > -1) {
return Promise.resolve(new Response(JSON.stringify(iportal_serviceProxy)));
}
return Promise.resolve();
return Promise.resolve(new Response(JSON.stringify({})));
});
datavizWebmap = new WebMap(123456, {
server: server
Expand Down Expand Up @@ -2471,7 +2477,7 @@ describe('mapboxgl_WebMapV2', () => {
} else if (url.indexOf('portal.json') > -1) {
return Promise.resolve(new Response(JSON.stringify(iportal_serviceProxy)));
}
return Promise.resolve();
return Promise.resolve(new Response(JSON.stringify({})));
});
datavizWebmap = new WebMap(id, {
server: server
Expand All @@ -2498,7 +2504,7 @@ describe('mapboxgl_WebMapV2', () => {
} else if (url.indexOf('portal.json') > -1) {
return Promise.resolve(new Response(JSON.stringify(iportal_serviceProxy)));
}
return Promise.resolve();
return Promise.resolve(new Response(JSON.stringify({})));
});
datavizWebmap = new WebMap(id, {
server: server
Expand All @@ -2523,7 +2529,7 @@ describe('mapboxgl_WebMapV2', () => {
} else if (url.indexOf('portal.json') > -1) {
return Promise.resolve(new Response(JSON.stringify(iportal_serviceProxy)));
}
return Promise.resolve();
return Promise.resolve(new Response(JSON.stringify({})));
});
datavizWebmap = new WebMap(id, {
server: server
Expand All @@ -2550,7 +2556,7 @@ describe('mapboxgl_WebMapV2', () => {
} else if (url.indexOf('portal.json') > -1) {
return Promise.resolve(new Response(JSON.stringify(iportal_serviceProxy)));
}
return Promise.resolve();
return Promise.resolve(new Response(JSON.stringify({})));
});
spyOn(ArrayStatistic, 'getArraySegments').and.callFake(function (array, type, segNum) {
return [
Expand Down Expand Up @@ -2584,7 +2590,7 @@ describe('mapboxgl_WebMapV2', () => {
} else if (url.indexOf('portal.json') > -1) {
return Promise.resolve(new Response(JSON.stringify(iportal_serviceProxy)));
}
return Promise.resolve();
return Promise.resolve(new Response(JSON.stringify({})));
});
datavizWebmap = new WebMap(id, {
server: server
Expand Down Expand Up @@ -2613,7 +2619,7 @@ describe('mapboxgl_WebMapV2', () => {
} else if (url.indexOf('portal.json') > -1) {
return Promise.resolve(new Response(JSON.stringify(iportal_serviceProxy)));
}
return Promise.resolve();
return Promise.resolve(new Response(JSON.stringify({})));
});
datavizWebmap = new WebMap(id, {
server: server
Expand Down Expand Up @@ -2825,6 +2831,7 @@ describe('mapboxgl_WebMapV2', () => {
if (url.indexOf('T202007210600.json') > -1 || url.indexOf('T202007210700.json') > -1) {
return Promise.resolve(new Response(JSON.stringify({})));
}
return Promise.resolve(new Response(JSON.stringify({})));
});
datavizWebmap = new WebMap(
'',
Expand Down Expand Up @@ -2910,6 +2917,7 @@ describe('mapboxgl_WebMapV2', () => {
if (url.indexOf('/content.json') > -1) {
return Promise.resolve(new Response(JSON.stringify(projection_4548_content)));
}
return Promise.resolve(new Response(JSON.stringify({})));
});
spyOn(FetchRequest, 'post').and.callFake((url) => {
if (url.indexOf('/featureResults') > -1) {
Expand Down
Loading

0 comments on commit d0bcc51

Please sign in to comment.