Skip to content

Commit

Permalink
Merge pull request #538 from vincent-lecrubier-skydio/patch-2
Browse files Browse the repository at this point in the history
Take options into account in the Map component
  • Loading branch information
tschaub authored Jun 12, 2024
2 parents 69de85a + 95449fc commit 53fadb1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
48 changes: 45 additions & 3 deletions tests/lib/Map.test.jsx
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -23,13 +24,54 @@ describe('<Map>', () => {
});

it('accepts a ref for accessing the map', () => {
let mapRef;
let map;
render(
<div style={style}>
<Map ref={r => (mapRef = r)} />
<Map ref={r => (map = r)} />
</div>,
);

expect(mapRef).toBeInstanceOf(OLMap);
expect(map).toBeInstanceOf(OLMap);
});

it('creates a map with the default controls', () => {
let map;
render(
<div style={style}>
<Map ref={r => (map = r)} />
</div>,
);

expect(map).toBeInstanceOf(OLMap);
const controls = map.getControls();
expect(controls.getLength()).toBe(3);
});

it('allows custom controls to be passed', () => {
let map;
render(
<div style={style}>
<Map ref={r => (map = r)} controls={[]}>
<Zoom options={{className: 'custom'}} />
</Map>
</div>,
);

expect(map).toBeInstanceOf(OLMap);
const controls = map.getControls();
expect(controls.getLength()).toBe(1);
});

it('allows options to be passed', () => {
let map;
render(
<div style={style}>
<Map ref={r => (map = r)} options={{controls: []}} />
</div>,
);

expect(map).toBeInstanceOf(OLMap);
const controls = map.getControls();
expect(controls.getLength()).toBe(0);
});
});

0 comments on commit 53fadb1

Please sign in to comment.