diff --git a/lib/Map.js b/lib/Map.js index 23bb7e8a..8f8265f5 100644 --- a/lib/Map.js +++ b/lib/Map.js @@ -29,8 +29,8 @@ class Map extends Component { this.targetRef = createRef(); - const {id, style, className, innerRef, ...mapProps} = props; - this.map = new OLMap({}); + const {id, style, className, innerRef, options, ...mapProps} = props; + this.map = new OLMap({...options}); if (innerRef) { if (typeof innerRef === 'function') { innerRef(this.map); diff --git a/tests/lib/Map.test.jsx b/tests/lib/Map.test.jsx index 756458e8..b0fb5be3 100644 --- a/tests/lib/Map.test.jsx +++ b/tests/lib/Map.test.jsx @@ -1,6 +1,7 @@ import Map from '../../lib/Map.js'; import OLMap from 'ol/Map.js'; import React from 'react'; +import Zoom from '../../lib/control/Zoom.js'; import {afterEach, describe, expect, it} from 'vitest'; import {cleanup, render, screen} from '@testing-library/react'; @@ -23,13 +24,54 @@ describe('', () => { }); it('accepts a ref for accessing the map', () => { - let mapRef; + let map; render(
- (mapRef = r)} /> + (map = r)} />
, ); - expect(mapRef).toBeInstanceOf(OLMap); + expect(map).toBeInstanceOf(OLMap); + }); + + it('creates a map with the default controls', () => { + let map; + render( +
+ (map = r)} /> +
, + ); + + expect(map).toBeInstanceOf(OLMap); + const controls = map.getControls(); + expect(controls.getLength()).toBe(3); + }); + + it('allows custom controls to be passed', () => { + let map; + render( +
+ (map = r)} controls={[]}> + + +
, + ); + + expect(map).toBeInstanceOf(OLMap); + const controls = map.getControls(); + expect(controls.getLength()).toBe(1); + }); + + it('allows options to be passed', () => { + let map; + render( +
+ (map = r)} options={{controls: []}} /> +
, + ); + + expect(map).toBeInstanceOf(OLMap); + const controls = map.getControls(); + expect(controls.getLength()).toBe(0); }); });