|
| 1 | +import { ScaleLine } from '../../../src/openlayers/control/ScaleLine'; |
| 2 | +import { TileSuperMapRest } from '../../../src/openlayers/mapping/TileSuperMapRest'; |
| 3 | + |
| 4 | +import Map from 'ol/Map'; |
| 5 | +import View from 'ol/View'; |
| 6 | +import TileLayer from 'ol/layer/Tile'; |
| 7 | + |
| 8 | +describe('openlayers_ScaleLine', () => { |
| 9 | + var map, baseLayer, testDiv; |
| 10 | + beforeAll(() => { |
| 11 | + testDiv = window.document.createElement('div'); |
| 12 | + testDiv.setAttribute('id', 'map'); |
| 13 | + testDiv.style.styleFloat = 'left'; |
| 14 | + testDiv.style.marginLeft = '8px'; |
| 15 | + testDiv.style.marginTop = '50px'; |
| 16 | + testDiv.style.width = '500px'; |
| 17 | + testDiv.style.height = '500px'; |
| 18 | + window.document.body.appendChild(testDiv); |
| 19 | + var url = GlobeParameter.China4326URL; |
| 20 | + map = new Map({ |
| 21 | + target: 'map', |
| 22 | + view: new View({ |
| 23 | + center: [104.79, 33.03], |
| 24 | + zoom: 4, |
| 25 | + projection: 'EPSG:4326' |
| 26 | + }) |
| 27 | + }); |
| 28 | + baseLayer = new TileSuperMapRest({ |
| 29 | + origin: [-180, 90], |
| 30 | + url: url, |
| 31 | + wrapX: true |
| 32 | + }); |
| 33 | + map.addLayer( |
| 34 | + new TileLayer({ |
| 35 | + source: baseLayer, |
| 36 | + projection: 'EPSG:4326' |
| 37 | + }) |
| 38 | + ); |
| 39 | + }); |
| 40 | + afterAll(() => { |
| 41 | + document.body.removeChild(testDiv); |
| 42 | + }); |
| 43 | + |
| 44 | + it('initialize default', (done) => { |
| 45 | + var scaleControl = new ScaleLine(); |
| 46 | + expect(scaleControl).not.toBeNull(); |
| 47 | + expect(scaleControl.render).not.toBeUndefined(); |
| 48 | + expect(scaleControl.minWidth_).toBe(64); |
| 49 | + expect(scaleControl.getUnits()).toBe('metric'); |
| 50 | + expect(scaleControl.innerElement_.className).toBe('ol-scale-line-inner'); |
| 51 | + done(); |
| 52 | + }); |
| 53 | + |
| 54 | + it('initialize options', (done) => { |
| 55 | + const options = { |
| 56 | + className: 'ol-scale-test', |
| 57 | + minWidth: 80, |
| 58 | + units: 'imperial' |
| 59 | + }; |
| 60 | + var scaleControl = new ScaleLine(options); |
| 61 | + expect(scaleControl).not.toBeNull(); |
| 62 | + expect(scaleControl.minWidth_).toBe(80); |
| 63 | + expect(scaleControl.getUnits()).toBe('imperial'); |
| 64 | + expect(scaleControl.innerElement_.className).toBe('ol-scale-test-inner'); |
| 65 | + done(); |
| 66 | + }); |
| 67 | + |
| 68 | + it('initialize and addTo map', (done) => { |
| 69 | + var scaleControl = new ScaleLine(); |
| 70 | + expect(scaleControl).not.toBeNull(); |
| 71 | + expect(scaleControl.render).not.toBeUndefined(); |
| 72 | + map.addControl(scaleControl); |
| 73 | + map.once('postrender', () => { |
| 74 | + expect(scaleControl.viewState_).not.toBeNull(); |
| 75 | + expect(scaleControl.renderedHTML_).not.toBeNull(); |
| 76 | + expect(scaleControl.renderedVisible_).toBeTruthy(); |
| 77 | + done(); |
| 78 | + }); |
| 79 | + }); |
| 80 | + |
| 81 | + it('test updateElementRepair', (done) => { |
| 82 | + var scaleControl = new ScaleLine(); |
| 83 | + scaleControl.yn = true; |
| 84 | + scaleControl.c = { style: { display: 'block' } }; |
| 85 | + scaleControl.updateElementRepair(); |
| 86 | + expect(scaleControl.viewState_).toBeNull(); |
| 87 | + expect(scaleControl.renderedVisible_).toBeFalsy(); |
| 88 | + expect(scaleControl.element.style.display).toBe('none'); |
| 89 | + done(); |
| 90 | + }); |
| 91 | +}); |
0 commit comments