-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure OpenLayers instance is initialized before adding map to D…
…OM (#3388) * fix: ensure OpenLayers instance is initialized before adding map to DOM * fix inconsistent property naming * improve test readability
- Loading branch information
1 parent
7661fa0
commit 8a89320
Showing
2 changed files
with
55 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { expect } from '@esm-bundle/chai'; | ||
import '../enable.js'; | ||
import '../vaadin-map.js'; | ||
import TileLayer from 'ol/layer/Tile'; | ||
import Map from 'ol/Map'; | ||
import OSM from 'ol/source/OSM'; | ||
import View from 'ol/View'; | ||
|
||
async function nextMapRender(map) { | ||
return new Promise((resolve) => { | ||
map.configuration.on('rendercomplete', resolve); | ||
}); | ||
} | ||
|
||
describe('configuration in detached state', () => { | ||
let mapElement; | ||
|
||
beforeEach(() => { | ||
mapElement = document.createElement('vaadin-map'); | ||
mapElement.style.width = '100px'; | ||
mapElement.style.height = '100px'; | ||
}); | ||
|
||
afterEach(() => { | ||
mapElement.remove(); | ||
}); | ||
|
||
it('should be configurable when detached', async () => { | ||
// OL instance should be initialized | ||
expect(mapElement.configuration).to.be.instanceOf(Map); | ||
// Configure map | ||
mapElement.configuration.addLayer(new TileLayer({ source: new OSM() })); | ||
mapElement.configuration.setView(new View({ center: [0, 0], zoom: 3 })); | ||
// Attach and wait for layer to be rendered | ||
document.body.appendChild(mapElement); | ||
await nextMapRender(mapElement); | ||
// Verify layer is set up | ||
const layers = mapElement.shadowRoot.querySelectorAll('.ol-layer'); | ||
expect(layers.length).to.equal(1); | ||
}); | ||
}); |