mirror of
https://github.com/symfony/ux-leaflet-map.git
synced 2026-03-24 00:52:09 +01:00
63 lines
3.4 KiB
TypeScript
63 lines
3.4 KiB
TypeScript
/*
|
|
* This file is part of the Symfony package.
|
|
*
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
import { Application, Controller } from '@hotwired/stimulus';
|
|
import { getByTestId, waitFor } from '@testing-library/dom';
|
|
import { clearDOM, mountDOM } from '@symfony/stimulus-testing';
|
|
import LeafletController from '../src/map_controller';
|
|
|
|
// Controller used to check the actual controller was properly booted
|
|
class CheckController extends Controller {
|
|
connect() {
|
|
this.element.addEventListener('ux:map:pre-connect', (event) => {
|
|
this.element.classList.add('pre-connected');
|
|
});
|
|
|
|
this.element.addEventListener('ux:map:connect', (event) => {
|
|
this.element.classList.add('connected');
|
|
});
|
|
}
|
|
}
|
|
|
|
const startStimulus = () => {
|
|
const application = Application.start();
|
|
application.register('check', CheckController);
|
|
application.register('leaflet', LeafletController);
|
|
};
|
|
|
|
describe('LeafletController', () => {
|
|
let container: HTMLElement;
|
|
|
|
beforeEach(() => {
|
|
container = mountDOM(`
|
|
<div
|
|
data-testid="map"
|
|
data-controller="check leaflet"
|
|
style="height: 700px; margin: 10px"
|
|
data-leaflet-provider-options-value="{}"
|
|
data-leaflet-view-value="{"center":{"lat":48.8566,"lng":2.3522},"zoom":4,"fitBoundsToMarkers":true,"options":{"tileLayer":{"url":"https:\/\/tile.openstreetmap.org\/{z}\/{x}\/{y}.png","attribution":"\u00a9 <a href=\"https:\/\/www.openstreetmap.org\/copyright\">OpenStreetMap<\/a>","options":{}}},"markers":[{"position":{"lat":48.8566,"lng":2.3522},"title":"Paris","infoWindow":null},{"position":{"lat":45.764,"lng":4.8357},"title":"Lyon","infoWindow":{"headerContent":"<b>Lyon<\/b>","content":"The French town in the historic Rh\u00f4ne-Alpes region, located at the junction of the Rh\u00f4ne and Sa\u00f4ne rivers.","position":null,"opened":false,"autoClose":true}}]}"
|
|
></div>
|
|
`);
|
|
});
|
|
|
|
afterEach(() => {
|
|
clearDOM();
|
|
});
|
|
|
|
it('connect', async () => {
|
|
const div = getByTestId(container, 'map');
|
|
expect(div).not.toHaveClass('pre-connected');
|
|
expect(div).not.toHaveClass('connected');
|
|
|
|
startStimulus();
|
|
await waitFor(() => expect(div).toHaveClass('pre-connected'));
|
|
await waitFor(() => expect(div).toHaveClass('connected'));
|
|
});
|
|
});
|