Skip to content

Commit

Permalink
[fix]UT
Browse files Browse the repository at this point in the history
  • Loading branch information
luoxiao-supermap committed Oct 17, 2024
1 parent edc101f commit 278af1e
Showing 1 changed file with 55 additions and 16 deletions.
71 changes: 55 additions & 16 deletions test/mapboxgl/overlay/GraticuleLayerSpec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GraticuleLayer } from '../../../src/mapboxgl/overlay/GraticuleLayer';
import mapboxgl from 'mapbox-gl';
// import { Feature } from '@supermap/iclient-common';
// import { Feature } from '@supermapgis/iclient-common';
var url = GlobeParameter.ChinaURL + '/zxyTileImage.png?z={z}&x={x}&y={y}';

describe('mapboxgl_GraticuleLayer', () => {
Expand Down Expand Up @@ -45,7 +45,7 @@ describe('mapboxgl_GraticuleLayer', () => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
if (!map.getLayer('graticuleLayer_1')) {
graticuleLayer = new GraticuleLayer({ layerID: 'graticuleLayer_1' });
graticuleLayer.onAdd(map);
map.addLayer(graticuleLayer);
}
});

Expand All @@ -72,14 +72,13 @@ describe('mapboxgl_GraticuleLayer', () => {
done();
}, 0);
});

it('_initialize visible', (done) => {
setTimeout(() => {
expect(graticuleLayer).not.toBeNull();
const graticuleLayer = new GraticuleLayer({ layerID: 'graticuleLayer_test', visible: false });
graticuleLayer.onAdd(map);
var visible = map.getLayoutProperty('graticuleLayer_1_line', 'visibility');
expect(visible).toBe('false');
var visible = map.getLayoutProperty('graticuleLayer_test_line', 'visibility');
expect(visible).toBe('none');
done();
}, 0);
});
Expand All @@ -93,6 +92,20 @@ describe('mapboxgl_GraticuleLayer', () => {
expect(visible).toBe('visible');
});

it('setLayoutProperty', () => {
let visible = map.getLayoutProperty('graticuleLayer_1_line', 'visibility');
expect(visible).toBe('visible');
expect(graticuleLayer.visible).toBeTruthy();
map.setLayoutProperty(graticuleLayer.id, 'visibility', 'none');
visible = map.getLayoutProperty('graticuleLayer_1_line', 'visibility');
expect(visible).toBe('none');
expect(graticuleLayer.visible).toBeFalsy();
map.setLayoutProperty(graticuleLayer.id, 'visibility', 'visible');
visible = map.getLayoutProperty('graticuleLayer_1_line', 'visibility');
expect(visible).toBe('visible');
expect(graticuleLayer.visible).toBeTruthy();
});

it('setMinZoom', () => {
graticuleLayer.setMinZoom(0);
expect(graticuleLayer.options.minZoom).toEqual(0);
Expand All @@ -109,12 +122,12 @@ describe('mapboxgl_GraticuleLayer', () => {
});

it('setExtent', () => {
graticuleLayer.setExtent([
[0, 0],
[50, 50]
]);
expect(graticuleLayer.options.extent[0]).toEqual(0);
expect(graticuleLayer.options.extent[3]).toEqual(50);
graticuleLayer.setExtent([
[0, 0],
[50, 50]
]);
expect(graticuleLayer.options.extent[0]).toEqual(0);
expect(graticuleLayer.options.extent[3]).toEqual(50);
});

it('setStrokeStyle', () => {
Expand All @@ -133,8 +146,34 @@ describe('mapboxgl_GraticuleLayer', () => {
});

it('setIntervals', () => {
graticuleLayer.setIntervals(5);
expect(graticuleLayer.renderer.options.interval).toEqual(5);
graticuleLayer.setIntervals(5);
expect(graticuleLayer.renderer.options.interval).toEqual(5);
});

it('getDefaultExtent must return degree', () => {
map.getCRS = () => {
return {
extent: [
-20037508.3427892,
-20037508.3427892,
20037508.3427892,
20037508.3427892
],
lngLatExtent: [
-179.99999999999963,
-85.05112877980658,
179.99999999999963,
85.05112877980656
]
};
};
var extent = graticuleLayer.getDefaultExtent();
expect(extent).toEqual([
-179.99999999999963,
-85.05112877980658,
179.99999999999963,
85.05112877980656
]);
});

it('_calcInterval', () => {
Expand Down Expand Up @@ -164,8 +203,8 @@ describe('mapboxgl_GraticuleLayer', () => {
expect(points[0][1]).toEqual(80);
});

it('onRemove', () => {
xit('onRemove', () => {
graticuleLayer.onRemove();
expect(graticuleLayer.renderer.canvas).toBeNull();
});
});
});

0 comments on commit 278af1e

Please sign in to comment.